| Jonathan Adams 2004-09-30, 10:46 am |
| In article <5de1c529.0409292147.5d499a31@posting.google.com>,
gnutuxy@yahoo.co.in wrote:
> 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?
Well, comp.unix.programmer (cross-posted, followup-to: set) would
probably be a better newsgroup, but your error is simple, and somewhat
on-topic:
> void mysig_handler( int signum )
> {
> printf("Received the signal: %d", signum );
> }
stdout is by default line-buffered. You either need to end your printf
format with '\n':
printf("Received the signal: %d\n", signum );
Or add an fflush(stdout); after the printf:
printf("Received the signal: %d", signum );
fflush(stdout);
if you want to get any output. You probably want the former. Back to
c.l.c off-topic-ness:
signal(3C) is a very old, crufty interface. You should look at the
manpage for sigaction(3C), the preferred interface. You might consider
picking up one of:
_Advanced programming in the Unix Environment_
(Stevens, ISBN 0201563177)
_Solaris Systems Programming_
(Rich Teer, ISBN 0201750392)
The latter, despite the title, contains general Unix programming tips,
and is kind of an up-to-date APUE in parts, from what I hear.
Cheers,
- jonathan
|