- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to get PID of father 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
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
тАО06-08-2009 04:18 AM
тАО06-08-2009 04:18 AM
any chance for some help?
I tried the command:
ps -ef | grep -i vdsd | grep -v root
to find PIDs of processes:
vds2 23246 1 0 12:39:32 ? 0:03 vdsd -g
vds2 29284 23246 3 14:12:37 ? 0:00 vdsd -g
The father process forks child processes and sometimes the father needs a restart (will then get new PID). How can I get the PID of the father process┬┤if there are probably 10 child processes?
Any help would be much appreciated.
Thanks in advance,
Juergen
Solved! Go to Solution.
- Tags:
- PS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 04:24 AM
тАО06-08-2009 04:24 AM
Re: how to get PID of father process
PPID=Parent Process ID (I am assuming this is what you meant by father process"
PID=`ps -ef | grep process_name_string | awk {'print $2'}
PPID=`ps -ef | grep process_name_string | awk {'print $3'}
Hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 04:36 AM
тАО06-08-2009 04:36 AM
Re: how to get PID of father process
Given a child's pid (for example 2342):
# UNIX95= ps -p 2342 -o ppid=
1
...which indicates that 'init' is the parent process.
Or, if you know the basename of the child process:
# UNIX95= ps -C getty -o ppid=
1
In both cases, set the XPG4 (UNIX95) behavior of 'ps' only for the duration of the commandline by writing 'UNIX95= ps'. Note that no semicolon occurs. If you prefer you could do: 'UNIX95=1 ps' but do _not_ assume that 'uNIX95=0' disarams it.
The UNIX95 behavior for 'ps' allows you to select the fields you want to see with '-o'. The "=" after the field name suppresses the header for the field.
Regards!
...JRF...
- Tags:
- UNIX95
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 04:46 AM
тАО06-08-2009 04:46 AM
Re: how to get PID of father process
Thanks, it helps and it does not, I created a script like that:
# !/bin.sh
PPID=`ps -ef|grep vdsd|grep -v root|grep -v vds2s|awk {'print $3'}`
PID=`ps -ef|grep vdsd|grep -v root|grep -v vds2s|awk {'print $2'}`
if [ $PPID -eq 1 ]
then
echo $PID
fi
Sometimes the script displays a PID and sometimes a syntax error. Hmmmh I'm not sure why it happens sometime!
As I mentioned the parent process ID is the one I'm looking for! And not 2 or more child processes!
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 04:50 AM
тАО06-08-2009 04:50 AM
Re: how to get PID of father process
UNIX95=1
ps -efH
This will show an indented display showing father processes at the left.
Modify this script to see the PPID field.
http://www.hpux.ws/?p=8
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 04:51 AM
тАО06-08-2009 04:51 AM
Re: how to get PID of father process
Using 'grep' to filter and select the output of 'ps' is a poor way to be sure that you find what (and only what you want).
The UNIX95 behavior allows the '-C' option as I showed which allows you to match _exactly_ the basename of a process. With the UNIX95 mode you can also select only the 'ps' fields you want to return (with the '-o' option) and optionally suppress the header line. THis makes life easy and exacting.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 05:26 AM
тАО06-08-2009 05:26 AM
Re: how to get PID of father process
I tried this below:
UNIX95= ps -C vdsd -o pid -o ppid
and got the output:
PID PPID
14514 1
14511 1
16364 1
The last PID would be the right one!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 05:37 AM
тАО06-08-2009 05:37 AM
Re: how to get PID of father process
UNIX95 is the XPG4 standard.
http://en.wikipedia.org/wiki/XPG4#Output
Setting the variable lends different behavior to various commands, perhaps the most notable and useful being 'ps'.
For 'ps' simply see the manpages for more information.
Be extremely careful _not_ to set the behavior in your profile or at some global level in a script. Many commands will have their standard behavior altered in subtle ways.
For this reason, confine the use of this behavior to a command-by-command basis by setting it only on the command line for the duration of the command line as I showed in my original post.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 05:42 AM
тАО06-08-2009 05:42 AM
Re: how to get PID of father process
Actually another good reference to the XPG4/UNIX95 environment is this:
http://docs.hp.com/en/B2355-60130/standards.5.html
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 05:52 AM
тАО06-08-2009 05:52 AM
Re: how to get PID of father process
from e.g. ps(1) "EXTERNAL INFLUENCES":
EXTERNAL INFLUENCES
Environment Variables
UNIX95 specifies to use the XPG4 behavior for this command. The changes for XPG4 include support for the entire option set specified above and include (the following) behavioral changes.
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 06:30 AM
тАО06-08-2009 06:30 AM
Solution> Hi and thanks...
When you are satisfied with the information that has been offered, please don't forget to evaulate it by providing feedback:
http://forums13.itrc.hp.com/service/forums/helptips.do?#28
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 09:57 PM
тАО06-08-2009 09:57 PM
Re: how to get PID of father process
Regards
Juergen