|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Finding return code for completed process ??
I have Process Id for one background process and currently it is running state. I want to see the return code after the above running process is done.
for the forground process normally I use "echo $?". But how to get the return code for my background process on UNIX/Linux?? Thanks in advance! Sriram |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
$ cat k.sh #!/bin/sh echo "TEST" grep test a.txt & wait $! echo $? $ sh k.sh TEST grep: can't open a.txt 2 $ echo test > a.txt $ sh k.sh TEST test 0 |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi,
Thanks for your input. But my requirement is little bit different. My running process is not child process of my current process. So it is triggered by some other user and I would like to monitor that process and see the return code. Wait command will work only for child process. Pls help me... |
|
#4
|
|||
|
|||
|
Within the script which runs the process, record the exit status to a file. Then monitor the file from your monitoring script.
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Ok, is there any other way I can capture using command?
|
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
If you are on Solaris, you could use dtrace for this. Create a file
exit.d as Code:
#!/usr/sbin/dtrace -s
syscall::rexit:
/execname == "ls"/
{
printf ("ls exited with exitcode %d\n", arg0);
}This example catches the exit code of the ls command. When you run the script, you get some output like: Code:
dtrace: script './exit.d' matched 2 probes CPU ID FUNCTION:NAME 7 105722 rexit:entry ls exited with exitcode 0 3 105722 rexit:entry ls exited with exitcode 2 1 105722 rexit:entry ls exited with exitcode 0 The script will run, until you stop it with Ctrl-C. |
| Sponsored Links | ||
|
![]() |
| Tags |
| background processes, process id, return code |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| aix 4.2: finding out the return code of a savevg/mksysb ? | Browser_ice | AIX | 1 | 05-14-2009 10:46 AM |
| Return code of background process | c19h28O2 | Shell Programming and Scripting | 3 | 04-06-2008 11:46 AM |
| return code of a process | filedeliver | Programming | 1 | 04-19-2007 01:42 AM |
| return code of a process | filedeliver | UNIX for Advanced & Expert Users | 1 | 04-18-2007 03:27 PM |
| background process return code | Vikas Sood | Shell Programming and Scripting | 5 | 06-10-2006 09:25 AM |
|
|