How to Clean up an Orphan Process in HP-UX?

Posted on 1997-06-03
Last Modified: 2013-12-06
Suppose we have a process, and it forks a child process, in HP-UX 10.0.  If the parent terminates (in an unexpected way), we may want to let that orphan child process exit.  How can this be implemented?  Or in other words, how can the child process know its parent has terminated?  (It seems signal SIGHUP doesn't work, and the system doesn't clean up it in a short time.)
Question by:cheng060397
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
  • 3

Expert Comment

ID: 2006352
Where are you trying to handle the SIGHUP in parent- or child-process? Normally the signal-handling in HP-UX is very clean an works fine...

Author Comment

ID: 2006353
Thanks, Beckers!  What I understand is that SIGHUP is generated when parent process terminates.  So I let child handle it, but it turned out that the child couldn't receive that signal.  (If the child called kill(getpid(), SIGTSTP) to suspend itself, it would receive it. (See Stevens' book, pages 256-258.)  But no one wants to suspend the child.)  My code looks like:
void main()
    childpid = fork();    
    if (childpid == -1) {
      perror("fork error\n");
    else if(childpid == 0) {                   /* child */      
        signal(SIGHUP, sig_func);
        /* some child code here */
    else {                                 /* parent */
        /* some parent code here */

void sig_func()                             /* signal handler */
    printf("SIGHUP received.\n");


Accepted Solution

beckers012097 earned 100 total points
ID: 2006354
Try using a signal-handler in parent-process (for all fatal signals like SIGKILL, SIGSEV etc.). In this signal handler shut down the child-process (you know the pid from fork) by sending a "soft"-kill. Then after recieving the childs exit-status terminate the parent-process.

But I don't understand the reason for not getting SIGHUP...
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 2006355
Thanks, beckers, but I am not sure those fatal signals can cover all unexpected terminations.

Expert Comment

ID: 2006356
They should, there are no other reasons for terminating a program than the signals you can catch. Or I understood it wrong for 10 years... Catch all signals?!?

Author Comment

ID: 2006357
Thanks, beckers!


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. Please see for the updated article. It is avail…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

735 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