- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: korn shell issues
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
10-21-2003 11:16 AM
10-21-2003 11:16 AM
I have found that Korn shell sets a variable $! equal to the PID of the last background process run, I am doing a process that comes back after it is entered and runs for several hours, but it will not set the PID with $!, can anybody help?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2003 11:34 AM
10-21-2003 11:34 AM
Re: korn shell issues
# echo $$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2003 11:51 AM
10-21-2003 11:51 AM
Re: korn shell issues
try doing this
#!/usr/bin/ksh
print "1this shells pid is $$"
( print "this shells pid is $$;sleep 5) &
print "the background process pid is $!"
sleep 6
print "the background process pid is $!"
print "2this shells pid is $$"
maybe this will help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2003 12:48 PM
10-21-2003 12:48 PM
Re: korn shell issues
tfile=/tmp/process$$.dat
# process stores data in the file Does work.
rm $tfile
exit 0;
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
10-21-2003 07:17 PM
10-21-2003 07:17 PM
Solution# sleep 60 &
[1] 255
# echo $!
255
Maybe there's some confusion. The $! variable is set when you have run a background command with "command &".
When you say your process "comes back after it is entered", maybe it is a daemon process, which behaves differently, by spawning a child process and terminating the original. This will not set $!.
I think you were running the Progress DB, and if this is anything like Oracle then its processes do run as daemons.
From another window, if you can find the pid of your "child" process, and run "ps -fpPID", then look in the PPID (parent) column. If PPID matches your shell then it is a true child; if PPID = 1 then it is a daemon.
I can explain further but it gets a bit technical. In a nutshell, if you run a child process with "command &", you will see $!. If you don't, you won't. In the former case you can also use the "wait" command to wait for all children to finish, in the latter you can't, because the daemon is not a true child.
Hope this helps.
--Grahan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2003 05:04 AM
10-22-2003 05:04 AM
Re: korn shell issues
You can get the current PID with $$. I always use this variable to define uniqueness files.
Ex:
#! /bin/ksh
#
#
ls -la > file.$$
rm file.$$
where:
$$ -> PID of the Korn Shell that is interpreting the script.
Tania
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2003 05:50 AM
10-22-2003 05:50 AM
Re: korn shell issues
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2003 07:11 PM
10-22-2003 07:11 PM
Re: korn shell issues
The "wait" command won't help here, this doesn't work for daemons.
I think the traditional way is to loop, running ps -fpPID, until the process exits, as I think you are already doing.
If anyone knows a better way I'd be interested to hear it.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2003 08:02 PM
10-22-2003 08:02 PM
Re: korn shell issues
based on something I once saw mr. A. Clay Stephenson do....
First, make a script that simulates something running for a period of time, e.g. ./runback.sh
#!/usr/bin/sh
sleep 20
Then use the following as the controlling script:
#!/usr/bin/sh
BACK_JOB=./runback.sh
BACK_PID=""
RC=0
# start background job
$BACK_JOB &
BACK_PID=${!}
while [[ $RC = 0 ]]
do
kill -s 0 ${BACK_PID} 2>/dev/null
RC=$?
sleep 5
echo $BACK_PID is running
done
echo $BACK_PID has stopped
The controlling script tests for the existence of the background pid by issuing the kill -s 0 command; the moment it does not return zero it is considered stopped.
Perhaps an idea?
regards,
John K.