Jump to content
  • Advertisement
Sign in to follow this  
Iftah

how to know when a process dies (on linux)

This topic is 4253 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, I am writing for linux on a project with many processes, and sometimes one of the processes dies without printing anything, and no core file is generated. How can I catch this? If I could insert a printf just before the process dies it would be great. thanks in advance, Iftah

Share this post


Link to post
Share on other sites
Advertisement
When a child process dies the parent process will receive a SIGCHLD signal. This will interrupt whatever system call you're currently waiting on (select/poll/epoll/etc) with errno = EINTR.

In your SIGCHLD signal handler, you can set a flag to indicate that a child died.

If you check your child-died flag, you know a child died so you can then go and do the appropriate thing: wait() or waitpid() is probably a good idea, otherwise you child will become a zombie. The wait() call will clean up after your dead child (very sad, but if your process is young it can spawn another) and give you an exit status value that will indicate why the child exited.

You cannot control any process other than a child process. Well, unless you're the superuser and use the ptrace() call. Unless you're writing a debugger, use of ptrace indicates very poor design.

You can also intercept almost any signal from withing the child process (man sigaction(2)) and print a wealth of information before exiting on a crash.

--smw

Share this post


Link to post
Share on other sites
Quote:

clean up after your dead child (very sad, but if your process is young it can spawn another)
LOL! [smile]

the processes are run from a shell script so I guess I can't use the parent process
I'll try the signal catching

Thanks!

PS. is this really a for beginners post?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!