Re: BEGIN, INIT etc...



Ben Morrow <ben@xxxxxxxxxxxx> writes:

Quoth Joost Diepenmaat <joost@xxxxxxxxx>:
if (! fork()) { # assumin fork() doesn't fail here.
exec $whatever;
exit;

You need POSIX::_exit here, or the END blocks get run twice (once for
each process).

Sorry, that's my mistake: exec() never returns, unless it fails, and I
tried to disregard every complication to make the point.

}
exit;

You probably want to wait here before exitting, as otherwise the execed
process is orphaned, and your parent gets SIGCHLD early. You probably
also want to set up signal handlers to pass signals along, etc... see
the source for the shell of your choice :). Or you could just use
system, which does all that for you.

Sure, this is just the extremely simplified version :-)


--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
.



Relevant Pages

  • Re: _Exit() and signal handlers
    ... The _Exit function causes normal ... Why is there a mention of signal handlers? ... the program can be set to catch SIGABRT. ...
    (comp.lang.c)
  • Re: Set REXX variables before REXX start
    ... Exec initialization exit ... This exit is called by the IRXEXEC routine or a compiler runtime ... exec, but before the first clause in the exec is processed. ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Re: Multithreaded qsort(3)
    ... of system is to exec() a shell and run an external command. ... Btw - the Solaris 10 system manpage only mentions signal interactions ... "The systemfunction manipulates the signal handlers for SIGINT, ...
    (freebsd-arch)
  • FC5: Users successfully boot to X (Gnome), but root does not.
    ... graphical mode, but root cannot - shortly after root login, X begins to ... exec $0 "$@" ...
    (Fedora)
  • Re: FC5 doesnt start up right.
    ... edit /etc/X11/prefdm so that it starts gdm instead of what its trying to ... exec $0 "$@" ... If your problem is only booting into runlevel 5 instead of runlevel 3 ...
    (Fedora)