Mark Dominus on 6 Jan 2004 16:56:02 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] How to find parent in the shell?


Michael C. Toren:
> I don't see how testing to see if your parent process is init will give
> you any insight into weather or not your script is being executed at boot
> time or not, unfortunately.  What if a user types "exec
> /etc/init.d/whatever" from a console login shell?

Moreover, when the parent process of process P exits, process P is
adopted by init.  So

        sh -c '  perl -le "sleep 2; print getppid()"  &  '

prints '1', because this command runs a shell, which runs Perl in the
background and exits; two seconds later Perl uses getppid() to find
its parent process ID, and discovers that its parent is init.

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug