<p><font size=2 color=navy face=Arial>
A simple answer is to check /proc/<pid> for the parent pid and recurse. Eventually it will be 1 and that's the top process. <br><br></font></p>
<p><hr size=2 width="100%" align=center tabindex=-1>
<font face=Tahoma size=2>
<b>From</b>: kwlug-disc-bounces@kwlug.org <kwlug-disc-bounces@kwlug.org> <br><b>To</b>: KWLUG discussion <kwlug-disc@kwlug.org> <br><b>Sent</b>: Tue Jan 25 12:13:33 2011<br><b>Subject</b>: [kwlug-disc] Parent Processes <br></font></p>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
Greetings,<br><br>I've been wrestling to find the parent process of perl scripts that are left running after exiting from the parent shell.  Specifically it is a search script that is started like this:<br><br>nohup <a href="http://search.pl">search.pl</a> -o output.txt -p <pattern> &<br>
<br>Following this, I exit the shell.  From another shell, running pstree, I can see:<br><br><a href="http://search.pl">search.pl</a>, 12345 ....<br>    |--<a href="http://search.pl">search.pl</a>, 12346 ....<br>    |--<a href="http://search.pl">search.pl</a>, 12347<br>
<br>...up to about 20 times, which is how the script runs.<br><br>But if more than one search is running, I of course see this twice, with different pids.<br><br><a href="http://search.pl">search.pl</a>, 12345 ....<br>
    |--<a href="http://search.pl">search.pl</a>, 12346 ....<br>
    |--<a href="http://search.pl">search.pl</a>, 12347....<br><br><a href="http://search.pl">search.pl</a>, 3454 ....<br>
    |--<a href="http://search.pl">search.pl</a>, 3455 ....<br>
    |--<a href="http://search.pl">search.pl</a>, 3456....<br><br><br>What I'd like to find, with a bash script, is the parent process to these.  It's easy to type in pstree, but I'd like the pid as a variable, but I'm having a hard time figuring out a shell command that will help me find these...<br>
<br><br>Any ideas out there?<br>