Solved

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

Posted on 1997-06-03
6
645 Views
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.)
0
Comment
Question by:cheng060397
  • 3
  • 3
6 Comments
 

Expert Comment

by:beckers012097
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...
0
 

Author Comment

by:cheng060397
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");
      exit(0);
    }
    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");
    exit(1);
}

0
 

Accepted Solution

by:
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...
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

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

Expert Comment

by:beckers012097
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?!?
0
 

Author Comment

by:cheng060397
ID: 2006357
Thanks, beckers!

0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
nodeip 9 80
Vmware Vswitch  VS  Redhat  Bridge 1 107
Shell script errors 10 135
remove one line from a file in solaris 8 29
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

803 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