- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: return value of background 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
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
12-27-2000 05:51 AM
12-27-2000 05:51 AM
return value of background process
I have a C program which return a non zero value. When I run a.out in a shell program in the background and do echo $? I get 0 and not the return value.
./a.out &
echo $?
my question is how can I get the return value. Is it possible to get the return value if I have the PID of the process.
Thanks in advance
Praveen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2000 06:38 AM
12-27-2000 06:38 AM
Re: return value of background process
write a a.sh
---
a.out
echo $? > /tmp/$$.return
---
a.sh &
read STATUS < /tmp/$$.return
rm /tmp/$$.return
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2000 06:43 AM
12-27-2000 06:43 AM
Re: return value of background process
If you are running the c program in the background, $? will not contain the exit status of the program. You can get the pid of the last background job from the $! variable but I don't know of a way to get the exit status of that process.
Do you have access to the c source code? If so, you can save the exit status in a file or something similar. Just make sure that the process has terminated before the script tries to access the exit status if you have saved it in a file.
--Bruce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2000 06:57 AM
12-27-2000 06:57 AM
Re: return value of background process
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2000 07:01 AM
12-27-2000 07:01 AM
Re: return value of background process
You won't be able to get that value unless you
call your c program from within a shell script, check the $? variable within the same shell script and run the whole stuff in the background.
like this:
#!/usr/bin/sh
a.out # your c program
echo $? > /tmp/myreturn$$
# the return value of the a.out prog
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2000 07:18 AM
12-27-2000 07:18 AM
Re: return value of background process
write a a.sh
---
a.out
echo $? > /tmp/$$.return
---
a.sh &
LASTPID=$!
while [ ! -f $LASTPID.return]
do
#...
sleep 5
done
read STATUS < /tmp/$LASTPID.return
rm /tmp/$LASTPID.return
Sorry.