Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can't catch SIGCHLD

Posted on 2000-03-05
5
Medium Priority
?
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

609 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