supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* What is the process group hack
@ 2012-04-26 15:15 harish badrinath
  2012-04-26 15:52 ` Mike Buland
  2012-04-26 18:27 ` Wayne Marshall
  0 siblings, 2 replies; 5+ messages in thread
From: harish badrinath @ 2012-04-26 15:15 UTC (permalink / raw)
  To: supervision

Hello,

I Could not figure out what "process group hack" is supposed to be
utilized for ??
Is it used to supervise daemons that stubbornly fork into the background.
Could anyone please explain with an example, i would be really helpful.
I have to the best of my abilities RTFM'ed and searched the internet.

Thank you,
Harish


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is the process group hack
  2012-04-26 15:15 What is the process group hack harish badrinath
@ 2012-04-26 15:52 ` Mike Buland
  2012-04-26 18:27 ` Wayne Marshall
  1 sibling, 0 replies; 5+ messages in thread
From: Mike Buland @ 2012-04-26 15:52 UTC (permalink / raw)
  To: supervision

Hello,

At least one good example is getty processes.  There are a number of
systems (including newer linux kernels, but this may be optional) that
will not allow a process that is not the parent of it's own process
group to take an unclaimed terminal device as it's controlling
terminal.  getty programs don't generally make their own process
groups, and neither does runit for it's services, so the program group
hack is necessary to run a getty program on many systems.

Although I believe that you're right, it was intended in daemontools
as a way to try to supervise a process that wanted to daemonize, I've
never had experience using it in that capacity myself.

--Mike Buland

On Thu, Apr 26, 2012 at 9:15 AM, harish badrinath
<harishbadrinath@gmail.com> wrote:
> Hello,
>
> I Could not figure out what "process group hack" is supposed to be
> utilized for ??
> Is it used to supervise daemons that stubbornly fork into the background.
> Could anyone please explain with an example, i would be really helpful.
> I have to the best of my abilities RTFM'ed and searched the internet.
>
> Thank you,
> Harish


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is the process group hack
  2012-04-26 15:15 What is the process group hack harish badrinath
  2012-04-26 15:52 ` Mike Buland
@ 2012-04-26 18:27 ` Wayne Marshall
  2012-04-26 19:02   ` Charlie Brady
  2012-04-27  1:20   ` Laurent Bercot
  1 sibling, 2 replies; 5+ messages in thread
From: Wayne Marshall @ 2012-04-26 18:27 UTC (permalink / raw)
  To: harish badrinath; +Cc: supervision

On Thu, 26 Apr 2012 20:45:28 +0530
harish badrinath <harishbadrinath@gmail.com> wrote:

> Hello,
> 
> I Could not figure out what "process group hack" is supposed
> to be utilized for ??
> Is it used to supervise daemons that stubbornly fork into the
> background. Could anyone please explain with an example, i
> would be really helpful. I have to the best of my abilities
> RTFM'ed and searched the internet.
> 
> Thank you,
> Harish
> 

This question refers to specific utilities in the daemontools
suite by Daniel Bernstein.

pgrphack is simply a wrapper around the setsid(2) system call.
It runs a process in a new session and process group.  See the
man page for setsid(2) for more information.  See also the
source file pgrphack.c in the daemontools distribution.

fghack is djb's "anti-backgrounding" utility.  It invokes
strangeness and mysteries to inhibit a process from forking into
the background.  Dunno about examples.  Normally it is not used
because: 1) nowadays most programs that daemonize will be
decently written and offer an option to run in the foreground;
or -- if such option is not provided -- 2) it is usually a
simple matter to delete a few lines of the offensive source code
to cut out the daemonizing behavior.

It should be mentioned that daemontools itself should be
considered deprecated by several alternatives currently
available and under active maintenance.  For example, runit,
daemontools-encore, and perp.  I believe most of these tools now
run each service in its own session and process group as a
matter of course, something that daemontools does not do, unless
you yourself explicitly run each service under the pgrphack
utility.

Why does this matter?  If the entire supervision tree runs under
a single process group, that entire process tree can be crashed
under certain conditions in some cases on some platforms.  Which
is a bad thing.

Internally segregating each service into its own process group is
more reliable, and generally eliminates any need for something
like pgrphack within the service definitions themselves.

Wayne
http://b0llix.net/perp/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is the process group hack
  2012-04-26 18:27 ` Wayne Marshall
@ 2012-04-26 19:02   ` Charlie Brady
  2012-04-27  1:20   ` Laurent Bercot
  1 sibling, 0 replies; 5+ messages in thread
From: Charlie Brady @ 2012-04-26 19:02 UTC (permalink / raw)
  To: Wayne Marshall; +Cc: harish badrinath, supervision


On Thu, 26 Apr 2012, Wayne Marshall wrote:

> fghack is djb's "anti-backgrounding" utility.  It invokes
> strangeness and mysteries to inhibit a process from forking into
> the background.

No, it doesn't change anything about the way the process operates. It just 
starts the process in a child process, and attempts to stay around until 
that process exits. 

See the description here:

http://cr.yp.to/daemontools/faq/create.html

fghack creates a pipe from the daemon and reads data until the pipe is 
closed. Normally all the daemon's descendants will inherit the open pipe 
from the daemon, so the pipe will not be closed until they all exit.

However, fghack will exit early if the daemon goes out of its way to close 
extra descriptors. A few of these daemons leave descriptor 0 open, even 
though they do not use descriptor 0; so

     #!/bin/sh
     exec fghack baddaemon <&-

might work. 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is the process group hack
  2012-04-26 18:27 ` Wayne Marshall
  2012-04-26 19:02   ` Charlie Brady
@ 2012-04-27  1:20   ` Laurent Bercot
  1 sibling, 0 replies; 5+ messages in thread
From: Laurent Bercot @ 2012-04-27  1:20 UTC (permalink / raw)
  To: supervision

 Just to clarify:

 There are two different tools that should not be confused.

 * The "process group hack" tool, prgphack. It's not a real hack,
it's just a call to setsid(2).

 * The "foreground hack", fghack. This one is a real unadulterated
100% ugly hack. It's used to allow self-backgrounding processes to
be still managed by a supervisor.

 Documentation - sparse, but accurate - about those tools can be found
on the daemontools web site:
 http://cr.yp.to/daemontools/fghack.html
 http://cr.yp.to/daemontools/pgrphack.html


> It should be mentioned that daemontools itself should be
> considered deprecated by several alternatives currently
> available and under active maintenance.  For example, runit,
> daemontools-encore, and perp.

 And s6. Please. :P

-- 
 Laurent


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-04-27  1:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-26 15:15 What is the process group hack harish badrinath
2012-04-26 15:52 ` Mike Buland
2012-04-26 18:27 ` Wayne Marshall
2012-04-26 19:02   ` Charlie Brady
2012-04-27  1:20   ` Laurent Bercot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).