[Techtalk] Re: check if script parent process is "init"
Rudi
dominik.schramm at gmxpro.net
Wed Apr 14 21:08:42 EST 2004
Hi,
Wolfgang Petzold <petzold at villa-chaos.de> writes:
> 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.
Hmm, of course, why didn't I think of it?
This would be then:
if echo $0 | grep -q "/etc.*/?rc.\.d/"
then
echo thanks for calling me, init!
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.
That's true. And I must say, I like this idea better as a starting point
because it's distro-independent, whereas the exact rc?.d locations are
different in Debian, Red Hat and SuSE, though there may be a
In the end, I did it like this, based on Kathryn Hogg's suggestion:
# [^0-9] could actually be "\t", I think,
# but I didn't want to rely on that
if grep -q -v "^Ppid:[^0-9]1$" /proc/$$/status
then
echo not run by init
fi
> Hope that helps,
Yes, it did.
Thanks a lot,
dominik
PS: I cc'ed you, Wolfgang, because this really belongs in techtalk.
Hope that's okay.
More information about the Techtalk
mailing list