[ale] shell script to find a script's ancestors
Björn Gustafsson
bg-ale at bjorng.net
Wed Aug 2 19:58:27 EDT 2006
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
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.
}
More information about the Ale
mailing list