- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Killing parent pid
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
09-15-2009 05:46 AM
09-15-2009 05:46 AM
user1 3870 1667 1 Sep 9 ? 4:52 b
user1 3871 1667 0 Sep 9 ? 4:50 c
user1 3878 1667 0 Sep 9 ? 4:49 d
user1 1667 1 0 Sep 9 ? 12:33 a
user1 3868 1667 0 Sep 9 ? 4:44 e
a is the parent process and b,c,d,e are the child processes.
Thanks,
Srini
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2009 05:53 AM
09-15-2009 05:53 AM
SolutionIt all depends on the software and there is no definite answer as I know of.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2009 06:19 AM
09-15-2009 06:19 AM
Re: Killing parent pid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2009 06:33 AM
09-15-2009 06:33 AM
Re: Killing parent pid
PPID=whatever
ps -ef | awk {'print $3'} | grep $PPID
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2009 06:37 AM
09-15-2009 06:37 AM
Re: Killing parent pid
PPID=whatever
ps -ef | grep $PPID
this output will also include a line for the parent process as well as all the child processes
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2009 07:14 PM
09-15-2009 07:14 PM
Re: Killing parent pid
The ps command can show the entire hierarchy:
UNIX95=1 ps -eH
or
UNIX95=1 ps -efH
Be sure to copy/paste the entire line. UNIX95=1 sets a special option for ps.
But the best tool is pstree. Here's a link to it: http://en.wikipedia.org/wiki/Pstree
pstree -p #####
where ##### is any process in the tree. pstree will show the entire branch up and down.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2009 10:56 PM
09-15-2009 10:56 PM
Re: Killing parent pid
In HP-UX 11.31 ptree exists and do the same as pstree.
Regards,
Roland
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2009 03:21 AM
09-16-2009 03:21 AM
Re: Killing parent pid
A safer command would be:
PPID=whatever
UNIX_95=EXTENDED_PS ps -ef -opid= -ocomm= -oppid= | grep " $PPID$"
This makes sure you can search for PPID=1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2009 11:02 PM
09-16-2009 11:02 PM
Re: Killing parent pid
Script starts here:
ppid=`ps -ef|grep 'TWM -u'|grep -v grep|awk '{print $2}'`
if [ -z "$ppid" ]
then
echo "no parent TM process running"
else
echo " Child processes are "
for child in `ps -ef|grep -w $ppid|grep -v grep|awk '{if($3!=1) {print $2}}'`
do
echo $child
#replace echo with kill
done
echo "Parent TM is " $ppid
fi
Thanks,
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2009 11:41 AM
09-17-2009 11:41 AM
Re: Killing parent pid
Always use ps to find processes by name, never grep. In your script, grep "TWM -u" may be unique but you can't depend on that. If you want to find all the TWM processes, use ps like this:
UNIX95=1 ps -C TWM -o pid= -o args=
This method ensures that grep will not find something else (like grep). Now if several copies of TWM are running and you want to select only the one with -u, then you can add grep to the result like this:
UNIX95=1 ps -C TWM -o pid= -o args= | grep -- -u
Be sure to use two dashes (grep --) to terminate the option processing and treat "-u" as a simple string.
But most important, do NOT grep for pid or ppid!!! This will find critical processes that happen to have matching numbers in the run string. ALWAYS use ps -p for exact PID matches.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2009 01:04 PM
09-17-2009 01:04 PM
Re: Killing parent pid
> ...replace echo with kill
And while we are on the subject of killing processes, don't use 'kill -9' without first attempting a simple 'kill' first.
A 'kill -9' cannot be caught and thus a process has no (programatic) chance to cleanup temporary files and/or shared memory segments.
Instead, escalate your annihilation:
kill -TERM ${mypid} > /dev/null 2>&1
sleep 2
kill -HUP ${mypid} > /dev/null 2>&1
sleep 2
kill -9 ${mypid} > /dev/null 2>&1
If the first 'kill' works ${mypid} will no longer be valid and the second (and third) 'kill's will be no-ops. If the 'kill -9' fails to terminate the process then it is waiting on an I/O to complete or in some other kernel state for which it can't be interrupted.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2009 01:08 PM
09-17-2009 01:08 PM
Re: Killing parent pid
>Is there any script to find all the child processes if we give the input as the parent pid?
Which version of OS you are using.
If you are on 11.31 use , ptree , it is a very nice program. It prints the complete process tree hierarchy.
http://docs.hp.com/en/B2355-60130/ptree.1.html
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2009 01:08 AM
09-18-2009 01:08 AM
Re: Killing parent pid
Using "--" is overkill and not as flexible as just "-e -u". After -e, you can add more options.
>do NOT grep for pid or ppid!!! This will find critical processes that happen to have matching numbers in the run string.
My grep pattern anchored it to the PPID.