- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to get the process id of a 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
Forums
Discussions
Discussions
Discussions
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
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
05-20-2003 02:21 AM
05-20-2003 02:21 AM
I am trying to get the process id of a process I try to start in the background.
I had come to know about a technique of using $! to get the status of last spawned process.
The above method works for commands like sleep.
When I do $! for my program I get a value, but when I do ps -ef the process id for the process in the listing is greater than the value returned by $! by 1.
For additional information I am setting setsid() in my program. Does it has anything to do with it.
Can anyone help me out.
Thanks in advance.
Shashibhushan GOkhale
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 02:31 AM
05-20-2003 02:31 AM
Re: How to get the process id of a process?
Null points if I am not the first to suggest this pse.
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 02:33 AM
05-20-2003 02:33 AM
SolutionEither you seek the process using ps or you add some code to the program that writes its own PID to some status file, just like syslogd uses /var/run/syslog.pid.
Best regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 02:59 AM
05-20-2003 02:59 AM
Re: How to get the process id of a process?
You are absolutely right.
I am using fork() to daemonize itself.
Thanks,
Shashibhushan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 03:03 AM
05-20-2003 03:03 AM
Re: How to get the process id of a process?
[2] + Running sleep 6000 &
brise:root /# jobs -p %2
21854
brise:root /# ps -ef | grep 21854
root 22308 21624 1 07:07:38 pts/tb 0:00 grep 21854
root 21854 21624 0 07:06:09 pts/tb 0:00 sleep 6000
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 03:11 AM
05-20-2003 03:11 AM
Re: How to get the process id of a process?
after running setsid() the program is the leader of a new process group. So I doubt, that jobs -p is able to find anything (didn't test this myself).
Best regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 03:12 AM
05-20-2003 03:12 AM
Re: How to get the process id of a process?
echo $!
or
echo $?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2003 03:22 AM
05-20-2003 03:22 AM
Re: How to get the process id of a process?
I just read the first line!