crontab (UNIX system V)

Dave Sherman dave at utcsrgv.UUCP
Mon Oct 1 04:30:47 AEST 1984


In article <784 at eisx.UUCP> jlk at eisx.UUCP (Joe Klein) writes:
~| 
~| 	Can anyone tell me how I can determine from within a C program
~| whether that program is being executed via the 'cron' or not ?

Sure. On many systems, cron does a setuid(1). If you're lucky, UID 1
is never actually used as a login ID (it might be called sys, bin,
daemon or a number of other things). A getuid() will therefore help
you out, for practical purposes.

Another route is to do a getppid() [get parent's process ID], if
that system call is supported. However, this requires predicting the
PID which cron will have based on the sequence of calls in /etc/rc,
and makes your code unportable and likely to break as soon as someone
changes /etc/rc.

The best solution is to put in a flag (call it -c), to be used when
the program is called from /etc/rc. Normal people type "foo", and
/etc/rc will contain "foo -c". Voila.

Dave Sherman
Toronto
-- 
 { allegra cornell decvax ihnp4 linus utzoo }!utcsrgv!dave



More information about the Comp.lang.c mailing list