[lkml]   [2001]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectOff-Topic: how do I trace a PID over double-forks?
This is more a Unix API question than a Linux question.

I hope the issue is interesting enough to be of interest to some of you.

Basically, I am writing an init which features process watching
capabilities. My init has a management channel with which you can tell
it "the PID of the ssh process is really 123 instead of 12".

When init forks a getty and that getty exits, it is restarted. So far
so good. But I want my init to be able to restart uncooperative
processes like sendmail that fork in the background. sendmail may be a
bad example because the sources are available, but please imagine you
didn't have the sources to sendmail or didn't want to touch them.

Now, the back channel for my init has a function that allows to set the
PID of a process. The idea is that the init does not start sendmail but
a wrapper. The wrapper forks, runs sendmail, does some magic trickery
to find the real PID of the daemonized sendmail and tells init this PID
so init will know it has to restart sendmail when it exits and won't
restart the wrapper when that exits.

Follow me this far? Great! The real problem at hand is: what kind of
trickery can I employ in that wrapper. I was hoping for something that
is not Linux specific, but I haven't found anything yet. I was also
hoping that I could find a method that does not rely on /proc being
there or on any filesystem being mounted read-write (yes, my back
channel works if the filesystem is mounted read-only). So, using
/proc and relying on something like /var/run/ are out.

Someone suggested using fcntl to create a lock and then use fcntl again
to see who holds the lock. That sounded good at first, but fork() does
not seem to inherit locks. Does anyone have another idea?

In case I made you wonder:

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:28    [W:0.499 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site