lkml.org 
[lkml]   [1997]   [Feb]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectSignals
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.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


\
 
 \ /
  Last update: 2005-03-22 13:38    [W:0.031 / U:1.452 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site