- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell program query
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
06-01-2002 05:44 AM
06-01-2002 05:44 AM
Shell program query
Can any one tell me how to kill the same shell?. I have written a script, it looks like this
pids=`ps |grep sh | awk '{print $1}'
echo $pids
......
kill -9 $pids
I ran this script in two ways on the prompt:
1. $exam_script (failed to kill itself)
2. $. exam_script (killed itself)
But in the first condition its giving a message like "Killed". My question is why it is not able to kill the parent shell from the child shell?.
Thanks
Vasu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2002 06:46 AM
06-01-2002 06:46 AM
Re: Shell program query
try simply the command:
kill -9 $$
$$ will be replaced by the PID of your shell.
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2002 07:39 AM
06-01-2002 07:39 AM
Re: Shell program query
Instead, use the -C option in ps. NOTE: this an XPG4 option, so temporarily set UNIX95 so it will work. For your example:
pids=$(UNIX95= ps -C sh)
To find all sh shells:
pids=$(UNIX95= ps -efC sh)
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2002 12:24 AM
06-02-2002 12:24 AM
Re: Shell program query
I have tried this also already, but I got the same message like "killed" but failed to parent shell.
Bill,
As you mentioned the option in your reply, it gives all the shell pids, but How do I kill a parent shell from a child shell?
Thanks
Vasu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2002 01:58 AM
06-02-2002 01:58 AM
Re: Shell program query
To kill the parent shell of your script within your script, instead of $$, use $PPID.
kill -9 $PPID
This works because while $$ is the PID of your current shell (i.e. killing this PID kills your script), $PPID is the PID of your parent shell (i.e. killing this PID kills the shell from which your script is launched).
Hope this helps. Regards.
Steven Sim Kok Leong