Michael C. Toren on 5 Jan 2004 17:11:01 -0000


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

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


On Mon, Jan 05, 2004 at 07:26:52AM -0500, Jeff Abrahamson 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
> > 
> > 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?
> 
>     | tr '\0' ' '

Ah, yes, that will work; I had tried cut, which failed, but not tr.

> alternatively
> 
>     awk -F'\0' '{print $1}' /proc/$PPID/cmdline

I gave that a try initially, too, but it also fails horribly with mawk
version 1.3.3-8:

	[mct@ellesmere ~]$ tr '\0' ' ' < /proc/$PPID/cmdline | awk '{print $1}'
	SCREEN

	[mct@ellesmere ~]$ awk -F'\0' '{print $1}' /proc/$PPID/cmdline
	S

It would appear that tr is the best method.

-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