Messages in this thread |  | | Date | Mon, 3 Feb 1997 11:16:42 -0500 (EST) | From | "Richard B. Johnson" <> | Subject | Signals |
| |
I don't know what POSIX says about this, but the included code snippet clearly shows that a signal handler using a negative number is allowed in the existing system. However, kill() with is negative number is NOT allowed. In other words, we can't ever use the signal handler that we've set up!!!
If negative signals were allowed for user signals. We've got as many as we would ever need!
----------------------------
#include <stdio.h> #include <unistd.h> #include <signal.h> #include <sys/wait.h>
void handler(int sig) { fprintf(stdout, "Signal %d received.\n", sig); fflush(stdout); signal(sig, handler); }
int main(void); int main() { int i; pid_t pid;
for(i=-1; i > -10; i--) { fprintf(stdout, "Setting signal %d\n", i); if((signal(i, handler)) < 0) /* Allowed okay */ perror("signal()"); } switch(fork()) { case 0: /* Child process */ pid = getppid(); for(i=-1; i > -10; i--) { fprintf(stdout, "Sending signal %d to PID %d\n", i, pid); fflush(stdout); if((kill(pid, i)) < 0) /* Returns an error */ perror("kill()"); } exit(1); break; case -1: fprintf(stderr, "fork() failed\n"); break; default: /* Parent process */ (void)wait(&i); break; } return 0; } -----------------------------------------
Cheers, Dick Johnson -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Richard B. Johnson Project Engineer Analogic Corporation Voice : (508) 977-3000 ext. 3754 Fax : (508) 532-6097 Modem : (508) 977-6870 Ftp : ftp@boneserver.analogic.com Email : rjohnson@analogic.com, johnson@analogic.com Penguin : Linux version 2.1.23 on an i586 machine (66.15 BogoMips). Warning : It's hard to remain at the trailing edge of technology. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|  |