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.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-