Re: subprocesses lifecycle



On Aug 30, 1:37 am, "Peter J. Holzer" <hjp-usen...@xxxxxx> wrote:
On 2008-08-29 22:01, C.DeRykus <c...@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:



On Aug 29, 12:53 pm, "Peter J. Holzer" <hjp-usen...@xxxxxx> wrote:
On 2008-08-29 12:19, C.DeRykus <c...@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:

On Aug 28, 10:43 am, Hans Mulder <han...@xxxxxxxxx> wrote:
What you'd really want, is a way to tell C<open> that you don't want
C<close> to wait for this child. As far as I know, there is currently
no simple way to achieve that.

Wouldn't backgrounding the task
accomplish that:

open my $fd, "/some/task & |"
or die...

Man, that's ugly!
But yes, I think that should work (although I haven't actually tried
it).

I'm not sure why a lone "&" tips the ugly balance :)

* Because it invokes a shell (which wouldn't otherwise be necessary)
* Because you have to think about it for a minute to figure out why it
works (if you figure it out at all - see Eric's post).

True, the "&" forces a shell and complexity
increases but, an "ugly" solution which
requires only a single keystroke suddenly
looks better even in a beauty contest..

However, maybe Hans' suggested double fork
is a more palatable solution.



However, child subprocesses would then need to be foregrounded with
SIGCONT if the parent wants to kill them before exiting.

No. SIGCONT doesn't "foreground" a process running in the background.
It continues a process which has been stopped. A running process can be
sent signals whether it is in the foreground or the background.

Yes, I mis-spoke but a SIGCONT actually is sent to the process
group when a backgrounded job is
moved to the foreground via "fg"
to enable a terminal read for example.

"fg" moves a job to the foreground. But that job isn't necessarily in
the background, it can also be stopped. In the latter case of course a
SIGCONT is necessary.


<off topic>
Yes, a SIGCONT can come into play in both cases ---
* when a foreground process is stopped (SIGTSTP)
* a background process attempts to read from the
terminal, gets a SIGTTIN, and then is put
into the foreground with "fg" to enable a
terminal read.
</off topic>


--
Charles DeRykus

.



Relevant Pages

  • Re: subprocesses lifecycle
    ... accomplish that: ... No. SIGCONT doesn't "foreground" a process running in the background. ...
    (comp.lang.perl.misc)
  • Re: subprocesses lifecycle
    ... No. SIGCONT doesn't "foreground" a process running in the background. ... group when a backgrounded job is ...
    (comp.lang.perl.misc)
  • Re: Newbie Post - Limiting processes
    ... > foreground and one background process. ... > I am working on providing some shell accounts to a few clients who have ... to run at any given time, background or foreground alike. ... the login.conf(5) manpage; you can define a custom login class ...
    (FreeBSD-Security)
  • Re: I dont understand how the child gets placed in the background
    ... in the background process group when the parent terminates? ... When you run a program from the shell, it forks a process to execute it. ... This process is in its own process group, ... The terminal's foreground PG is set to this PG while the ...
    (comp.unix.programmer)
  • Re: Problem about bringing last running background job To Foreground
    ... I tried to using systemand execvp() function to acccess ... The fg command will be built into each shell, ... in the foreground will be specific to a particular ...
    (comp.unix.shell)