[ale] shell script to find a script's ancestors

David Corbin dcorbin at machturtle.com
Fri Aug 4 19:24:16 EDT 2006


On Wednesday 02 August 2006 19:58, Bj?rn Gustafsson wrote:
> On 8/2/06, David Corbin <dcorbin at machturtle.com> wrote:
> > Since I cannot find out who is installing iptables when my ppp interface
> > starts, I thought I might replace it with a shell script to log who it's
> > parent is.
> >
> > Anyone care to suggest the best way to show the current process's
> > ancestors from a shell script?
>
> You can get a single-level parent from a bash script in one line:
>
> #!/bin/bash
> echo $PPID

I should have been more verbose.  I'm looking for the parent application/cmd 
line, not it's ID.
>
> To get the whole ancestral tree, a simple perl script works for me:
>
> #!/usr/bin/perl
> my $proc = $$;
> while ($proc > 1) {
>         my $procinfo = `ps -fp $proc`;
>         print $procinfo;
>         my @proctext = split(/\s+/,$procinfo);
>         $proc = $proctext[10]; # your `ps' may vary.
> }

I'll give that a try.

Thanks.



More information about the Ale mailing list