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
  #8  
Old 08-05-2008
Registered User
 

Join Date: Mar 2006
Posts: 141
Quote:
Originally Posted by milangautami View Post
Hi ,

How to store pid of process in a variable and check its value?
Probably also already asked and answered a million times.

Here the million and first way (it really depends on your version of ps or Unix)
On Linux and Solaris we have pgrep
Code:
pid=$(pgrep name_of_cmd)
on HP-UX we would have to make ps behave in a different way by e.g.
Code:
pid=$(UNIX95= ps -C name_of_cmd -o pid=)
etc., etc.
Testing if pid holds valid content is also heavily dependent on the used shell.
In a posix shell we could do (if we were process owner or root, or omit the kill)
Code:
[[ -n $pid ]] && kill -0 $pid && echo "is alive"
Reply With Quote
Google The UNIX and Linux Forums
Forum Sponsor
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:43 PM.


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 Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0