Messages in this thread |  | | From | PARMELAN Edouard <> | Subject | RE: Signals | Date | Tue, 04 Feb 97 10:34:00 PST |
| |
signal(2): DIAGNOSTICS On success, signal returns the signal's previous disposition. On failure, it returns SIG_ERR and sets errno to indicate the error.
change: if((signal(i, handler)) < 0) /* Allowed okay */ by: if((signal(i, handler)) == SIG_ERR) /* Allowed okay */ you will see :signal(): Invalid argument
Edouard. ---------- De : owner-linux-kernel-outgoing[SMTP:owner-linux-kernel-outgoing@vger.rutgers .edu] Date d'envoi : lundi 3 fevrier 1997 11:16 A : Linux kernel Objet : Signals
part1 (TEXT/PLAIN) ------------------------------
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. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -=-=- -
|  |