473,396 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unis signal handling in parent child scenario.

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.
Nov 14 '05 #1
2 2835
In article <5d**************************@posting.google.com >,
gn*****@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
Nov 14 '05 #2
Thanks Jonathan,

It works!
And thanks for suggesting the com.unix.programming.

Regards,
Vinay Gadekar.
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: steffen staehle | last post by:
Hi, I'm writing a server process which spawns child processes via fork This server process should keep track of the number of children stil running, do the necessary cleanup to avoid zombies,...
2
by: Rookie | last post by:
Hi, I have a program that fork()'s + execlp()'s two children. Later in the program I want to send a signal to the parent(SIGINT) . The parent's signal handler should then send signals to these...
0
by: Chris Waldmann via .NET 247 | last post by:
Here's the deal. I have a Typed Dataset. For simplicity, we'll say it has 2 tables Parent and Child with a FK in Child, relationname = FK, cascade on update. Kyes are negative autoincrement. I...
3
by: Maheshkumar.R | last post by:
Hi groups, How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT. Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
0
by: Innova | last post by:
Hi, We are working on a gridview inside the gridview (parent-child) scenario. The data of child grid will depend on the data of parent. Objectives: 1.Add new row in parent grid after each row...
3
by: joelq1981 | last post by:
Dear friends, I want to extend the interrupt handler of a program, my code is: ... if ($pid = fork) { local $SIG{INT} = sub { print "Please select:\n"; $choice =...
1
by: 32Alpha | last post by:
Hi, first post here. First off, this IS a homework assignment for an operating systems class, but the question isn't "how do i do the assignment" but "why is my particular implementation not...
5
by: david | last post by:
I'm developing a program that runs using an asyncore loop. Right now I can adequately terminate it using Control-C, but as things get refined I need a better way to stop it. I've developed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.