The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to store values into variable in perl chittiprasad15 Linux 3 05-07-2008 09:21 PM
How to Store command O/P to a variable... smartbuddy UNIX for Dummies Questions & Answers 7 08-24-2007 04:49 AM
To store the output in a variable Sudhakar333 Shell Programming and Scripting 2 07-10-2007 05:45 AM
store awk results in a variable forever_49ers Shell Programming and Scripting 1 09-19-2006 07:51 PM
When can a script deny to store any value in a variable mitte_dino Shell Programming and Scripting 1 10-04-2005 03:57 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-11-2007
Registered User
 

Join Date: Jun 2007
Posts: 4
Need to get pid of a process and have to store the pid in a variable

Hi,

I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this.

Thanks in advance,
Amudha
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-11-2007
Registered User
 

Join Date: May 2007
Posts: 211
This is to find the pid for the single process

Code:
ps -ef | grep 'your procees' | grep -v grep | awk '{print $2}' | read pid
Reply With Quote
  #3 (permalink)  
Old 06-11-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
Quote:
Originally Posted by lorcan
This is to find the pid for the single process

Code:
ps -ef | grep 'your procees' | grep -v grep | awk '{print $2}' | read pid
You can do yhe work without using the grep command :
Code:
pid=`ps -ef | awk '/your process/{ print $2 }'`
Jean-Pierre.
Reply With Quote
  #4 (permalink)  
Old 06-11-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,573
Code:
var1=`ps -ef | awk '/process_name/ { print $2 }'`
I believe this had been answered many times/

Try searching the forums
Reply With Quote
  #5 (permalink)  
Old 06-11-2007
Registered User
 

Join Date: Jun 2007
Posts: 4
Hi,

Thanks for your help. your command is working fine. i can able to store the pid of process in a variable. Thank you once again
Reply With Quote
  #6 (permalink)  
Old 06-11-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,542
Code:
set -- $(ps -eo pid,args|grep [y]our_process); p="$1"
Reply With Quote
  #7 (permalink)  
Old 08-05-2008
Registered User
 

Join Date: Aug 2008
Posts: 1
how to store pid in a variable?

Hi ,

How to store pid of process in a variable and check its value?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0