Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site utcsrgv.UUCP
Path: utzoo!utcsrgv!dave
From: dave@utcsrgv.UUCP (Dave Sherman)
Newsgroups: net.lang.c
Subject: Re: crontab (UNIX system V)
Message-ID: <48@utcsrgv.UUCP>
Date: Sun, 30-Sep-84 14:30:47 EDT
Article-I.D.: utcsrgv.48
Posted: Sun Sep 30 14:30:47 1984
Date-Received: Sun, 30-Sep-84 14:41:38 EDT
References: <784@eisx.UUCP>
Organization: The Law Society of Upper Canada, Toronto
Lines: 24

In article <784@eisx.UUCP> jlk@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