- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script for capturing pid of particular process
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2002 04:00 AM
тАО07-29-2002 04:00 AM
I want to capture ONLY the process id of a particular process and store it in a variable.
Example, if the process id of the process "aaa" is 5643, the variable should store 5643.
How would you do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2002 04:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2002 04:08 AM
тАО07-29-2002 04:08 AM
Re: Script for capturing pid of particular process
PID=`ps -ef | grep $PROCNAME | grep -v grep | awk '{print $2}'`
echo $PID
Greetings,
Ceesjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2002 04:18 AM
тАО07-29-2002 04:18 AM
Re: Script for capturing pid of particular process
PID=$(ps -ef|grep thingtogrepfor | grep -v grep|cut -c10-14
So many ways to skin that cat (as we say in the UK).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2002 04:32 AM
тАО07-29-2002 04:32 AM
Re: Script for capturing pid of particular process
try this.
pid=`ps -ef|grep "process name"|awk '{print $2}'`
regds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2002 05:03 AM
тАО07-29-2002 05:03 AM
Re: Script for capturing pid of particular process
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2002 06:52 AM
тАО07-29-2002 06:52 AM
Re: Script for capturing pid of particular process
ps -ef | grep -v grep | grep sh
(to look for all the sh programs (but it finds ksh and csh and bash and users with the name cash and shenn, etc
Use this instead:
PIDVAR=$(UNIX95= ps -C MyProcessName | tail -1 | grep -v PID | awk '{print $1}')
where MyProcessName is the name of your selected process. This script will return the last match (in case there are two or more processes) and PIDVAR will be null if the process is not running. By using the XPG4 option -C, you are asking ps to do the searching for you and it will always match the basename of the process you are looking for.
In the above example, here is what you need:
UNIX95= ps -fC sh
and now you see only the sh (and the login shells -sh).
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2002 01:21 PM
тАО07-29-2002 01:21 PM
Re: Script for capturing pid of particular process
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2002 11:51 PM
тАО07-30-2002 11:51 PM
Re: Script for capturing pid of particular process
Var=`ps -ef | grep "aaa" | grep -v grep | awk '{print $2}'`
echo $var
Hope this will helps you.
Regards
Anand Hotchandani