LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-14-2004, 11:33 AM   #1
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Rep: Reputation: 15
obtaining PID of shell script


hello,

How can i obtain the PID of a just started shell script.

Regards
SaN
 
Old 07-14-2004, 11:38 AM   #2
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
You can do ps -ef and look for the name of the program that's running. The PID will be shown in the second column, if memory serves.

See also:
http://www.linuxbase.org/spec/refspe...LSB/pidof.html
 
Old 07-14-2004, 11:41 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
You can also have the script itself report the value. The shell variable $$ contains the pid. If you need to share that information with external programs/scripts, just output it to a file. Something like:
Code:
echo $$ > /tmp/script_name.pid
 
1 members found this post helpful.
Old 07-14-2004, 11:43 AM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
From inside the script you can use $$ to obtain the PID (e.g. echo $$)

EDIT: AHH! DH beat me to it

Last edited by itsme86; 07-14-2004 at 11:44 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
What is script PID information? Stepaj47 Linux - Newbie 7 11-15-2005 03:50 PM
How do I get PID info about a specific script? Stepaj47 Linux - Newbie 2 11-14-2005 05:31 PM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 07:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration