In article <2026…@yahoo.com>,
Michael S <alre…@yahoo.com> wrote:
>On Fri, 30 Oct 2026 02:22:43 -0000 (UTC)
>cro…@spitfire.i.gajendra.net (Dan Cross) wrote:
>
>> In article <2026…@yahoo.com>,
>> Michael S <alre…@yahoo.com> wrote:
>> >On Thu, 29 Oct 2026 22:26:40 GMT
>> >sco…@slp53.sl.home (Scott Lurndal) wrote:
>> >
>> >> Michael S <alre…@yahoo.com> writes:
>> >> >On Thu, 29 Oct 2026 16:20:39 -0000 (UTC)
>> >> >[snip]
>> >> >Does it block when your command processor is bash and your command
>> >> >string is "my_subprocess &"?
>> >>
>> >> You might need to do 'nohup my_subprocess &' if my_subprocess
>> >> doesn't intercept SIGHUP.
>> >
>> >
>> >You are likely right. Otherwise OS will kill my_subprocess at about
>> >the same time the caller of system() gets control back.
>> >I would not figure it out myself.
>>
>> Only if you intended to close the TTY the programs were started
>> on. Otherwise, I don't see why it would be necessary:
>
>What happens when caller is GUI-style application?
That depends on a number of factors, but basically, "it does the
same thing". Why would it be any different?
SIGHUP is the "hangup" signal, and _usually_ generated by the
kernel when a process loses its controlling terminal, though it
_can_ be sent from the command line (or a program) using the
`kill` command or one of its many imitators (basically, anything
that invokes `raise()` or the `kill()` system call).
The classic example of its use was a dial-in terminal line that
recognized modem status and reacted to a "carrier detect" signal
dropping; the kernel would clean up by SIGHUP'ing the process
group of anything associated with that terminal; one can see
this readily in early Unix kernel sources. This is a reason why
SIGHUP is one of the few signals a shell will actually honor.
Nowadays, this most often happens when an interactive session
associated with a pseudoterminal is closed; this could be window
in a terminal emulator program, or it could be a network login
via e.g. `ssh` that closes.
For programs that are not associated with a TTY at all, this
won't happen; this is why traditionally Unix daemons often
overloaded SIGHUP to force reloading a config file or similar:
since daemons are not generally associated with user ttys (or
often any TTY at all, including the console), the kernel will
never automatically send them a SIGHUP to terminate, so it's a
"safe" signal to pick for administrative control.
Crucially, using `system()` to invoke a program, even one that
is backgrounded, does not usually allocate a new terminal, nor
does it necessarily close one (though I suppose one could use it
to invoke something like, `kill -9 -1` to zap all of one's
processes; you could even background that if you wanted, but
that seems silly).
GUI programs are no different in this regard. Many of them may
not even be associated with a tty device at all, and may receive
their "session has ended" notification some other way.
So I go back to my original statement, "only if you intended to
close the TTY the programs were started on." IF you intend to
start some long-running program in the background and you won't
stay logged in after doing that, then sure, use `nohup`. But
if you don't care about that, then you don't need to bother.
The OS will not kill your program when the shell started by
`system` exits or anything; nor will the shell itself.
- Dan C.
>> ```
>> term% cat a.c
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <time.h>
>> #include <unistd.h>
>>
>> int
>> main(void)
>> {
>> time_t now = time(NULL);
>> printf("Starting child, time is %s", asctime(gmtime(&now)));
>> sleep(5);
>> now = time(NULL);
>> printf("Bye bye, now is %s", asctime(gmtime(&now)));
>> }
>> term% cat b.c
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <time.h>
>> #include <unistd.h>
>>
>> int
>> main(void)
>> {
>> time_t now = time(NULL);
>> printf("Parent starting, time is %s", asctime(gmtime(&now)));
>> system("./a &");
>> printf("./a started in background\n");
>> sleep(2);
>> now = time(NULL);
>> printf("Ahhh!!! time is %s", asctime(gmtime(&now)));
>> return 0;
>> }
>> term% make a
>> cc -O2 -pipe -o a a.c
>> term% make b
>> cc -O2 -pipe -o b b.c
>> term% ./b
>> Parent starting, time is Fri Oct 30 02:21:06 2026
>> ./a started in background
>> Starting child, time is Fri Oct 30 02:21:06 2026
>> Ahhh!!! time is Fri Oct 30 02:21:08 2026
>> term% Bye bye, now is Fri Oct 30 02:21:11 2026
>> ```