pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


CodeSys defer SIGRT*&co demo for "Rauch"
Posted by Anonymous on Thu 17th Jan 2019 08:44
raw | new post
view followups (newest first): CodeSys defer SIGRT*&co demo for Fa. "Rauch" by Anonymous

  1. #include <pthread.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <signal.h>
  6. #include <errno.h>
  7.  
  8. /* Simple error handling functions */
  9.  
  10. #define handle_error_en(en, msg) \
  11.         do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
  12.  
  13.  
  14. int main(int ac, char *av[])
  15. {
  16.         sigset_t set;
  17.         int i;
  18.         char buff[512];
  19.  
  20.         (void)puts("#start");
  21.  
  22.         sigemptyset(&set);
  23.         sigaddset(&set, SIGRTMIN+2);
  24.         sigaddset(&set, SIGRTMIN+3);
  25.         i = pthread_sigmask(SIG_BLOCK, &set, NULL);
  26.         if (i != 0)
  27.                 handle_error_en(i, "pthread_sigmask() failed");
  28.  
  29.         (void)puts("#mark1");
  30.  
  31.         /*
  32.          * stupid /bin/kill in Linux cannot handle realtime signal
  33.          * *names*, so we pass the signal number instead
  34.          */
  35.         (void)snprintf(buff, sizeof(buff), "kill -s %d %d", SIGRTMIN+2, getpid());
  36.         (void)printf("# executing %s\n", buff);
  37.         (void)system(buff);
  38.  
  39.         (void)puts("#mark2");
  40.        
  41.         (void)sleep(2);
  42.         (void)puts("#mark3");
  43.  
  44.         i = pthread_sigmask(SIG_UNBLOCK, &set, NULL);
  45.         if (i != 0)
  46.                 handle_error_en(i, "pthread_sigmask() failed");
  47.  
  48.         /*
  49.          * unblocking the SIGRTMIN signals will trigger the default handler for
  50.          * the SIGRT signals, which terminates the process, so we will never reach
  51.          * this point in the program
  52.          */
  53.         (void)puts("#notreached");
  54.  
  55.         return EXIT_SUCCESS;
  56. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at