Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get PID of the current process in Shell-script

Status
Not open for further replies.

sambit

Programmer
Mar 13, 2002
6
0
0
US
Hi,

Can anyone help in getting the PID of the current process in Shell. Well I am working on HP-UX 11.00.

Regards,
Sambit.
 
The environment variable $ contains the process id of the current shell, while PPID contains its parent process id.
Example:
Code:
echo $$ $PPID

Is it what you are looking for ?
 
TIP It may be good pratice to use the PID number with any temp files created with your shell scripts.
Example1:
tempfile="/tmp/scriptname.tmp.$$"

rm $tempfile

Example2:
tempfile1=="/tmp/scriptname.tmp1.$$"
tempfile2=="/tmp/scriptname.tmp2.$$"

rm /tmp/*.$$
 
TIP It may be good pratice to use the PID number with any temp files created with your shell scripts.
Example1:
tempfile="/tmp/scriptname.tmp.$$"

rm $tempfile

Example2:
tempfile1="/tmp/scriptname.tmp1.$$"
tempfile2="/tmp/scriptname.tmp2.$$"

rm /tmp/*.$$
 
Thanks all of you.

Thanks Required(MIS),
your suggestion was the I was searching for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top