is it possible to create an orphaned process?

Cameron Simpson cs at zip.com.au
Sat Sep 6 06:22:58 UTC 2008


On 05Sep2008 19:40, Konstantin Svist <fry.kun at gmail.com> wrote:
| I have an odd application that has threads which hang around until all
| child processes have finished executing.
| I'd like to create a background process that isn't a child of said
| thread, so that the thread can exit.

Fork twice when you make the children. The immediate child should exit.
The grandchild should exec your "child" process. Since its parent exited
(the imediate child) it becomes inherited by init. Your main process
will be fine.

However, I would dig a bit into why the threads hang around (if you
have the source, or can play with strace and lsof). Why? Because it is
possible for a process to have children unknowingly. Like this:

  sleep 3600 &          # makes "sleep" a child of the current process
  exec your-app ...     # now you app has "sleep" as a child

Provided you started the app itself as a child (no "exec") you're fine.
Just something to keep in mind.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

There's no trick to being a humorist when you have the whole government
working for you.        - Will Rogers




More information about the fedora-list mailing list