473,792 Members | 3,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Receive d 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 2847
In article <5d************ **************@ posting.google. com>,
gn*****@yahoo.c o.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.progr ammer (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("Receive d the signal: %d", signum );
}


stdout is by default line-buffered. You either need to end your printf
format with '\n':

printf("Receive d the signal: %d\n", signum );

Or add an fflush(stdout); after the printf:

printf("Receive d 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.progra mming.

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
3366
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, etc. In the beginning I thought I had to use the POSIX module, using SigSet SigAction, sigprocmask etc. for a rather paranoid approach. Then I've rea
2
1655
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 two children. I am able to catch the signal in the parent - on catching this signal I invoke a function that sends kill(childPid,SIGINT) but the signal handler in the child doesn't seem to be getting invoked. Can someone please tell me why this is...
0
1037
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 bind Parent to dgParent and I bind dgChild to the Parent table, FK datamember. The grids work properly, except in the following scenario. 1. Add a new row to the parent table. (PK = -1) 2. Save. The new Parent key is updated from the return...
3
9707
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 parent menu functions. if i select draw line in MDI parent, the line should be drawn in current active child..any URLS for this or guide me to achieve this communication... -- Mähésh Kumär. R
12
2809
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 when menu items are clicked.Besides these i would like to put a custom status bar. Any error message encountered in any of the webpage will be displayed in the banner. The problem iam encountering is how to access the customer status bar in child...
0
8566
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 and add child grid into that row because the columns in child grid are same as parent grid and we want to align them with the cols of parent grid. 2. If there is data for child grid we show a plus image in the parent row (in the row above the...
3
2283
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 = <STDIN>;
1
4820
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 working". I've searched the forums here, but could not find anything particular to my problem, Googling and the linux manual pages haven't been much help either. What the program is supposed to do is create a very simple shell (that sits atop the...
5
6651
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 another program that executes it as a child process using popen2.Popen4(). I was attempting to use signals to stop it (using os.kill()) but I keep running into a problem where sending the signal causes an infinite loop of printing the message...
0
9670
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10159
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.