|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|
Re: [PLUG] How to find parent in the shell?
|
On Sun, Jan 04, 2004 at 11:11:19PM -0500, Stephen Gran wrote:
> What I'm looking for is something like $PPID, or maybe $$, but that
> gives me a little more information to work with,
To extract argv[0] of the parent, perhaps you could use:
awk '{print}' /proc/$PPID/cmdline
Unfortunately, the above command is somewhat deceptive, at least for
mawk version 1.3.3-8, which is the awk implementation that happens to be
installed on my local system. Based on the output of the following test,
mawk seems to use nul-terminated strings internally, probably the result
of using stdio:
[mct@ellesmere ~]$ echo -e "foo\0bar"| awk '{print}'
foo
The net result is that it's easy to extract the first nul-terminated
string of /proc/$PPID/cmdline using awk, but not the second. I would
normally recommend using perl in a situation like this one, however I
believe the use of perl in Debian init.d scripts is frowned upon?
> and a way to make it be portable across the various implementations.
This is also entirely linux specific. Or by implementations, did you
mean distributions?
-mct
___________________________________________________________________________
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
|
|