Cron questions
guy at sun.UUCP
guy at sun.UUCP
Tue Oct 21 07:16:55 AEST 1986
> > > It is much nicer to do it like so:
> > > 30 * * * * /bin/su person -c "whatever"
> >
> > For efficiency, make that:
> >
> > 30 * * * * exec /bin/su person -c "exec whatever"
> >
>
> Really? Seems to me in the first case there is one exec (from
> cron), and in the second case there are two execs.
You are confused about the significance of the word "exec" in the second
case. It does not cause an *extra* "exec" system call to be performed. It
causes the shell *not* to perform a "fork" before the "exec".
In the first case, "cron" does a "fork" and runs "/bin/sh", passing it the
command line '/bin/su person -c "whatever"'. The shell then forks and runs
"/bin/su", passing it the arguments "person", "-c", and "whatever".
"/bin/su" then becomes the user "person", and forks and runs "/bin/sh",
passing it the arguments "-c" and "whatever". "/bin/sh" now parses the
command line "whatever", and, assuming it only specified one command, forks
and runs that command, passing it whatever arguments "whatever" specified
for it.
In the second case, "cron" does a "fork" and runs "/bin/sh", passing it the
command line 'exec /bin/su person -c "exec whatever"'. The shell then runs
"/bin/su" without forking, passing it the arguments "person", "-c", and
"exec whatever". "/bin/su" then becomes the user "person", and forks and
runs "/bin/sh", passing it the arguments "-c" and "whatever". "/bin/sh" now
parses the command line "exec whatever", and, assuming the "whatever" only
specified one command, runs that command without forking, passing it
whatever arguments "whatever" specified for it.
--
Guy Harris
{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
guy at sun.com (or guy at sun.arpa)
More information about the Comp.unix.wizards
mailing list