Solved

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

Posted on 1997-06-03
6
641 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

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

Expert Comment

by:beckers012097
Comment Utility
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
Comment Utility
Thanks, beckers!

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

771 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

14 Experts available now in Live!

Get 1:1 Help Now