G
gnutuxy
Hi,
I am newbie in the Unix system programming and in learning phase.
I usually read the libc manual and then try to implement small
programs to test/check the learnt thing.
I read the libc manual for signals and tried the program to check
whether child
inherits the signal handler intalled by parent befor fork.
I am totally confused about it because the code won't work as per the
the manual. Manual says child inherits signal action and signal mask.
My situation is as follows:
Question : Why I won't get message "Received the signal: #" on the
terminal, when I signaled child process with SIGINT?
==================glibc manual extract==============
* The set of pending signals (*note Delivery of Signal: for the
child process is cleared. (The child process inherits its mask of
blocked signals and signal actions from the parent process.)
====================================================
My try : I just want to check that the signal handler installed in
Parent is
inherited by child ( this is what I interpreted from the
glibc manual,
the extract of the manual is highlighted above. )
Here is my code.
=================my code============================
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
void mysig_handler( int signum )
{
printf("Received the signal: %d", signum );
}
int main( int argc, char *argv[] )
{
pid_t chld;
signal( SIGINT, mysig_handler );
if( ( chld = fork() ) < 0 )
{
//error
printf("Fork Error!\n");
}
else if( chld == 0 )
{
//child
while(1)
{
}
}
else
{
//parent
while(1)
{
}
}
return(0);
}
====================================================
my softwares are
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
Kernel 2.2.14-12smp
Regards,
Vinay G.
I am newbie in the Unix system programming and in learning phase.
I usually read the libc manual and then try to implement small
programs to test/check the learnt thing.
I read the libc manual for signals and tried the program to check
whether child
inherits the signal handler intalled by parent befor fork.
I am totally confused about it because the code won't work as per the
the manual. Manual says child inherits signal action and signal mask.
My situation is as follows:
Question : Why I won't get message "Received the signal: #" on the
terminal, when I signaled child process with SIGINT?
==================glibc manual extract==============
* The set of pending signals (*note Delivery of Signal: for the
child process is cleared. (The child process inherits its mask of
blocked signals and signal actions from the parent process.)
====================================================
My try : I just want to check that the signal handler installed in
Parent is
inherited by child ( this is what I interpreted from the
glibc manual,
the extract of the manual is highlighted above. )
Here is my code.
=================my code============================
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
void mysig_handler( int signum )
{
printf("Received the signal: %d", signum );
}
int main( int argc, char *argv[] )
{
pid_t chld;
signal( SIGINT, mysig_handler );
if( ( chld = fork() ) < 0 )
{
//error
printf("Fork Error!\n");
}
else if( chld == 0 )
{
//child
while(1)
{
}
}
else
{
//parent
while(1)
{
}
}
return(0);
}
====================================================
my softwares are
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
Kernel 2.2.14-12smp
Regards,
Vinay G.