[prog] check if script parent process is "init"
Wolfgang Petzold
petzold at villa-chaos.de
Wed Apr 14 18:33:14 EST 2004
Hello!
Dominik Schramm wrote:
> I'd like to check in a Bash script if it is being run by init,
> i.e. directly upon system startup, and not interactively
> or from another process -- say, cron.
The init process usually runs scripts in /etc/init.d/ (or a similar
location) by calling symlinks in "runlevel directories", /etc/rc?.d/ in
my (debian) case.
The scripts themselves can then tell by the name they were called with
if they are run automatically or manually. See if you have some
/etc/init.d/skeleton for an example.
Though this might be done in some not so obvious way, the principle is:
if my name is like /etc/init.d/rc?.d/S*
I am to start, called automatically
else if my name is like /etc/init.d/rc?.d/K*
I am to stop, called automatically
else
I am called manually
Check command line for what to do
fi
On the other hand, if I remember correctly what I once read about the
boot process, the init process always has PID 1. So, if another (bash)
process is started by init, bash should set its variable ${PPID} to 1
accordingly.
Hope that helps,
Wolfgang
More information about the Programming
mailing list