HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: korn shell scripting - how to check return cod...
Operating System - HP-UX
1827293
Members
2359
Online
109717
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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-19-2001 05:14 AM
09-19-2001 05:14 AM
I'm running a script that executes three processes (not necessarily shell script) in the background and then waits for them to complete. If any one of those processes exits with a non-zero return code I want to detect this and exit the script; otherwise I want to continue executing the script.
How can I do this? (i.e. check the return code of the completed background processes)
I've written the following test code, but I'm not able to detect any non-zero return codes.
#! /bin/ksh
# main script
backgroundprocess1 & #hardcoded to exit with 2
backgroundprocess2 & #hardcoded to exit with 0
backgroundprocess2 & #hardcoded to exit with 0
wait
echo $? # always displays 0
###################
#backgroundprocess1
sleep 5
exit 2
###################
#backgroundprocess2
sleep 5
exit 0
###################
#backgroundprocess3
sleep 5
exit 0
How can I do this? (i.e. check the return code of the completed background processes)
I've written the following test code, but I'm not able to detect any non-zero return codes.
#! /bin/ksh
# main script
backgroundprocess1 & #hardcoded to exit with 2
backgroundprocess2 & #hardcoded to exit with 0
backgroundprocess2 & #hardcoded to exit with 0
wait
echo $? # always displays 0
###################
#backgroundprocess1
sleep 5
exit 2
###################
#backgroundprocess2
sleep 5
exit 0
###################
#backgroundprocess3
sleep 5
exit 0
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2001 05:32 AM
09-19-2001 05:32 AM
Solution
Hi Paul:
See this thread:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x5bb76af52b04d5118fef0090279cd0f9,00.html
...JRF...
See this thread:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x5bb76af52b04d5118fef0090279cd0f9,00.html
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2001 06:13 AM
09-19-2001 06:13 AM
Re: korn shell scripting - how to check return codes of background processes?
Hi Paul,
A small word of caution - the wait in a korn-shell can give erratic results (see the last comment in James' link). If at all possible, use a bourne-shell, this gives 'sensible' results.
Rgds, Robin.
A small word of caution - the wait in a korn-shell can give erratic results (see the last comment in James' link). If at all possible, use a bourne-shell, this gives 'sensible' results.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2001 04:34 PM
09-19-2001 04:34 PM
Re: korn shell scripting - how to check return codes of background processes?
Consider writing a subroutine to execute a command
and record its status in a status file. Something like:
sub stat_command {
statfile=$1
shift
$($*; echo \$? > $statfile) &
}
You can then check the contents of the
statfiles when the tasks complete.
and record its status in a status file. Something like:
sub stat_command {
statfile=$1
shift
$($*; echo \$? > $statfile) &
}
You can then check the contents of the
statfiles when the tasks complete.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP