Solved

Can't catch SIGCHLD

Posted on 2000-03-05
5
367 Views
Last Modified: 2013-12-26
I have a process that spawns another process.  In case 1 process A spawns process B by simply calling spawnv() on it's binary.  In case 2 process A calls a script that unzips process B, once process B is uncompressed, process A then calls spawnv() to run process B.

My question is, when I run process A using case 1 I am able to catch SIGCHLD with my signal handler, but when I run process A using case 2 I am no longer able to catch SIGCHLD with my signal handler.  Any ideas on why this is happening.  There is no recoding done to process A to do the 2 cases, I just change the flags to either run the binary or call the decompressing script first.
0
Comment
Question by:MokoWebworks
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:ufolk123
ID: 2586764
Hi MokoWebWorks.

In case 2 , Are you using fork etc to run the unzip script ?
If that is the case then your main process (A) will not get the signal as signal will be sent to forked child of A.
Can you give me some snapshot of your code ?

ufolk123
0
 

Author Comment

by:MokoWebworks
ID: 2589732
Hello ufolk123,

Thank's for responding.  Here is a snapshot of my code:

/*---------------------------------*/int
main()
      {
      .
      .
      signal(SIGCHLD, signalhandler);
      signal(SIGTERM, signalhandler);
      .
      .
      startup_apps();
      .
      .
      while(1)
            {
            }
      return 1;
      }

/*---------------------------------*/void
startup_apps()
      {
      .
      .
      if (running_in_zipmode)
            {
            call_script(name_of_zipfile)
            }
      .
      .
      rval = spawnv(P_NOWAIT, programpath, args_list);
      setprio(rval, 29);
      .
      .
      return;
      }      

/*---------------------------------*/void
call_script(char *name_of_zipfile)
      {
      .
      .
      rval2 = spawnl(P_WAIT,             scriptpath, scriptname, name_of_zipfile, programpath, NULL);
      .
      .
      return;
      }

/*---------------------------------*/void
signalhandler(int signo)
      {
      switch (signo)
            {
            .
            .
            case SIGCHLD:
                  pid = wait(NULL);

                  printf("Process %d terminated!\n", pid);
                  break;
            .
            .
            }
      return;
      }
      
I tried to debug the code and in case 2 it didn't even entered the signal handler as opposed to when the running_in_zipmode flag is unset.

In case you wan't to know what's in the scriptfile, here it is:

/*---------------------------------*/#!/bin/sh

if gzip -t $1
then
      gzip -dc $1 > $2
      chmod 777 $2
else
      echo gzipfile corrupted
      exit 1
fi

exit 0

Hope you could figure out what's wrong with it.  Thanks in advance!
0
 
LVL 3

Accepted Solution

by:
ufolk123 earned 50 total points
ID: 2590400
Hi MokoWebworks ,

I have some doubts regarding your environment.spawnxxx() family of calls are not supported on most of the Unix falimy OS.What exactly is your work environment ?
You code flow seems OK.From this it looks like may be implementation of spawnl() on your system is disabling the signal handling ( as you are using P_WAIT option) .Actually it should not completely change the signal handler and properly restore the SIGCHLD handler before return but from your example seeems that is the root of your problem.

So try to do the following.
Add
signal(SIGCHLD, signalhandler);
signal(SIGTERM, signalhandler);
as
startup_apps()
{
..
..
if (running_in_zipmode)
{
call_script(name_of_zipfile)
}
..
signal(SIGCHLD, signalhandler);
signal(SIGTERM, signalhandler);
..
rval = spawnv(P_NOWAIT, programpath, args_list);
setprio(rval, 29);
..
..
return;
}


Also try to use the system() instead of spawn as a second option.
Try and check if you still get the problem.

ufolk123

0
 

Author Comment

by:MokoWebworks
ID: 2590506
Hello again ufolk123,

Thanks for the advice,I managed to get it working by placing the signal handler right before spawning, though, I do have a few concerns.  The program is to run as a spawning program, meaning it'll call spawn in more than one occasion (in fact, in a lot of occassion),  won't this screw up the system by assigning the same signal to the signal handler more than once?  Otherwise, the program works and I accept your answer.

BTW, my working environment is QNX, an OS specializing for embedded systems, same as UNIX only slightly different architecture.
0
 
LVL 3

Expert Comment

by:ufolk123
ID: 2590646
won't this screw up the system by assigning the same signal to the signal handler more than once?  Otherwise, the program works and I accept your answer.

Do not worry about that.Ideally the signal call should replace the signal handler to the new one.So mulitple signal() calls are never a problem ( As par the standard implementation).


my working environment is QNX, an OS specializing for embedded systems, same as UNIX only slightly different architecture.


Hmmm, Thats why you have some DOS based C library calls supported.As spawn() etc are C library calls orginally in DOS ( & now in windows also).

Anyway thanks for this session.Please feel free if you have anything to share in future.

ufolk123
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 48
Powershell based monitoring system 2 137
How to know only "File created" with EventLog 3 32
Smart Camera scanning and reading information 3 99
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now