[lug] More script questions

Chip Atkinson chip at pupman.com
Thu Apr 27 15:49:17 MDT 2000


Bill,

In the shell, $$ is the variable that refers to the process id of the
script.  In other words, a script like the one below will kill itself.

#!/bin/sh
echo Killing myself
kill -9 $$

In C it's getpid(2), and in perl it's $$ also.

When you invoke a command in the background, such as 

watch ls -l &

$! has the process id.  Strictly speaking, $! is the process id of the
most recently invoked background job.

Hope that helps.

Chip


On Thu, 27 Apr 2000, winrip wrote:

>   Is there a way to force a pid to a program?  Or how would one be able to
> assign a pid to a variable at run time so that the pid is known to the script.
> 
> Example of what I'm doing, my program has two pids, and 
> 
> ps x|awk '/PROGRAM/ {print $1}' 
> 
> adds an extra pid for the awk statement, so I piped "head -2" to the end of the
> statement and get the pids I need.  But, now I need both pids known to the
> script and a test to make sure there are two pids. the conditional test
> shouldn't be any trouble it's just the assigning of pids to variables that
> gets me.  
> 
> 
> Any ideas?
> Thanks 
> Bill
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> 





More information about the LUG mailing list