c - How can I display the output for sigusr1 and sigusr2? -


i beginner in c , system programming. wrote program , should display following: caught sigusr1 caught sigusr2 caught sigint

however, when "./test.c", thing see "caught sigint" when type ctrl-c. how can fix code program displays messages above? sorry if question dumb. appreciated. reading.

edited:

#include <signal.h> #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <unistd.h>  static void sighandler_sigusr1(int sig) {     //sig contains signal number received     printf("caught sigusr1, %d\n", getpid());     //kill(getpid(), sigusr1); }  static void sighandler_sigusr2(int sig) {     //sig contains signal number received     printf("caught sigsr2, %d\n", getpid());     //kill(getpid(), sigusr2); }  static void sighandler_sigint(int sig) {     //sig contains signal number received     printf("caught sigint, existing, %d\n", getpid());     //kill(getpid(), sigint);     exit(exit_success); }  int main(int argc, char *argv[]) {      if (signal(sigusr1, sighandler_sigusr1) == sig_err)         printf("unable create handler sigusr1\n");      if (signal(sigusr2, sighandler_sigusr2) == sig_err)         printf("unable create handler sigusr2\n");      if (signal(sigint, sighandler_sigint) == sig_err)         printf("unable create handler sigint\n");      kill(getpid(), sigusr1);     kill(getpid(), sigusr2);     kill(getpid(), sigint);      while (1)     {         sleep(1);     }      return 0; } 

that looks good.

with sigusr's have explicitly call them in program. can't trigger them ctrl-z or ctrl-c.

you didn't show code try , trigger signals.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -