Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!think!husc6!mit-eddie!genrad!decvax!decwrl!sun!guy From: guy@sun.UUCP Newsgroups: net.unix-wizards Subject: Re: Cron questions Message-ID: <8326@sun.uucp> Date: Mon, 20-Oct-86 17:16:55 EDT Article-I.D.: sun.8326 Posted: Mon Oct 20 17:16:55 1986 Date-Received: Wed, 22-Oct-86 01:26:31 EDT References: <6300012@wvlpdp> <1120001@hpfcla.HP.COM> <1011@whuts.UUCP> Organization: Sun Microsystems, Inc. Lines: 36 > > > 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@sun.com (or guy@sun.arpa)