parents, children and signals - second try

Joel Coltoff coltoff at burdvax.UUCP
Wed Jun 5 04:59:42 AEST 1985


<< DANGER - MEN AT REST >>

Some of you may have seen some of this article already. I made two mistakes
and need to post it again. The first mistake was posting to net.unix.wizards
instead of net.unix-wizards. The second mistake was cancelling the article
all together. Since I posted it I ran into yet another problem with my
primative understanding of signals.

I am developing an application on 4.2bsd that is a single parent family
with two children. Each of the children already has a catcher for ^C
and it is important that this be maintained. What I need the parent to
do is sense the ^C and then send it to the appropriate child. What I am
doing now is telling the children to ignore SIGQUIT and use that as a
psuedo SIGINT to the parent. When I release this program to the users
I would like them to be able to use SIGINT. The reason being they are
used to doing this when they run either of the children as a single process.
Is there anyway I can get the parent to see the interrupt first and then
have it decide which child sees it?

Also, the parent has a trap set up for SIGCHLD. Is there a clever way to
tell which child caused this to happen? I really don't want to include
the code for ps in my program. For this application it is sufficient
to know only which child's status has changed not what the new status is.


*****NEW STUFF******

The application uses curses and I have my own handler for SIGTSTP which
then calls the one curses provides. On restarting the parent I want
to make sure that the program wasn't put in the background. I am using
SIGTTOU to detect this. A code frgament is shown below along with my
comments as to what I think is happening.


	signal( SIGTSTP, suspend );
	signal( SIGTTOU, ttou );
	parent_pid = getpid();
suspend()
{
	extern int tstp();

	signal(SIGCHLD, SIG_IGN);
	signal(SIGTSTP, tstp );
	kill( proca_pid, SIGSTOP );
	kill( procb_pid, SIGSTOP );
	kill( parent_pid, SIGTSTP );
/* Program is suspended */

/*
 * Program is restarted. If it is started in the background we should
 * get a SIGTTOU when curses redraws the screen
*/
	kill( proca_pid, SIGCONT );
	kill( procb_pid, SIGCONT );
	signal(SIGCHLD, chld );
	signal(SIGTSTP, suspend );
}
ttou
{

	signal( SIGCHLD, SIG_IGN );
	signal( SIGTTOU, SIG_DFL );
	kill( parent_pid, SIGTTOU );
/* We should stop at this point */


	signal( SIGCHLD, chld );
	signal( SIGTTOU, ttou );
}

What ends up happening is that I can start the program in the
background. I don't stop when I send myself the SIGTTOU but do with a
stand alone program that contains only that statement. I get no
indication on my terminal that there is tty output. If I do a 'ps' my
two children are sleeping and the parent is running.

Does anyone have a good explanation for the behavior I am seeing or
suggestions for how to do it correctly?

	Thanks in advance,
	  - Joel {psuvax1,sdcrdcf}burdvax!coltoff



More information about the Comp.lang.c mailing list