Tobias DiPasquale on 5 Jan 2004 12:42:02 -0000


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

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


On Mon, 2004-01-05 at 01:38, Michael C. Toren wrote:
> 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

Use this instead for argv[0] of the parent:

shell% awk '{print}' /proc/$PPID/cmdline | tr '\0' '\n' | head -1

That will yield the correct results. Of course, it will also only work
on Linux. HTH :)

-- 
Tobias DiPasquale, www.cbcg.net
202A 04C4 2CE6 B985 8520  88D6 CD25 1A6C B9B5 1595

Attachment: signature.asc
Description: This is a digitally signed message part