Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Finding return code for completed process ?? Post 302754731 by hergp on Friday 11th of January 2013 03:31:59 AM
Old 01-11-2013
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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

background process return code

Hi I have the following piece of code that is calling another child process archive.ksh in the background while read file; do file_name=`ls $file`; ksh archive.ksh $file_name &; done < $indirect_file The problem is, indirect_file may contain anwhere from 2 to 20 different... (5 Replies)
Discussion started by: Vikas Sood
5 Replies

2. UNIX for Advanced & Expert Users

return code of a process

two programs A and B writting in c++ I am using A to B and I want to know the return code of B. in B ------------------------ int main() { return 11; } ------------------------ in A ------------------------ int main() { system(A); } ------------------------ Is it the right way... (1 Reply)
Discussion started by: filedeliver
1 Replies

3. Programming

return code of a process

two programs A and B writting in c++ I am using A to B and I want to know the return code of B. in B ------------------------ int main() { return 11; } ------------------------ in A ------------------------ int main() { system(A); } ------------------------ Is it the right way... (1 Reply)
Discussion started by: filedeliver
1 Replies

4. Programming

getting the return code of forked child process (ftp)

Hi, From within my C++ program, I fork a child process and execl an ftp session (solaris), like this : std::string szStartCmd = "ftp -i -n -v 192.168.149.31"; int nExecRes = execl("/bin/sh", "sh", "-c", szStartCmd.c_str(), (char *)0); I use 2 pipes to communicate between my... (7 Replies)
Discussion started by: KittyJ
7 Replies

5. Shell Programming and Scripting

Return code of background process

Hi, I have a process that I run in the background that looks like this ${BASEDIR}/ksh/sqler.ksh ${compnames003} & and I would like to get the return code of the sqler.ksh script. so my code is like this ${BASEDIR}/ksh/sqler.ksh ${compnames003} & retcode=$? (3 Replies)
Discussion started by: c19h28O2
3 Replies

6. AIX

aix 4.2: finding out the return code of a savevg/mksysb ?

Am I right to assume that to check the return code of a savevg/mksysb on an AIX 4.2 is with the "$?" ? (1 Reply)
Discussion started by: Browser_ice
1 Replies

7. Shell Programming and Scripting

return code of multiple java process

Hi, I have a unix shell script which is launching multiple java processes by calling a java class in a loop, but each time with a different set of parameters. Now I have to use the return code from each process in the script later. but how do i obtain the return code from each process... (1 Reply)
Discussion started by: rama354
1 Replies

8. Shell Programming and Scripting

Background process, return code and pid.

Hey all, Okay, this one is tricky and I'm not sure there is a niec way to do it, or indeed anyway to do it. The main issue revolves around timing out a hung ssh. I am doing this by creating a wrapper script for the ssh with the following requirements. My requirements are: Defineable... (5 Replies)
Discussion started by: RECrerar
5 Replies

9. Shell Programming and Scripting

Process only files which have completed in transaction

Hi , I have a situation where I have to Process files ( move , edit or rename ) in a folder ..... This folder is a FTP folder and Files keep coming in when they are available ... So I should perform my actions on those which which completed transaction .. . Is there a way to identify a... (3 Replies)
Discussion started by: chillblue
3 Replies

10. Shell Programming and Scripting

Capturing the return code from background process

Hi All, I was out not working on unix from quite sometime and came back recently. I would really appreciate a help on one of the issue I am facing.... I am trying to kick off the CodeNameProcess.sh in PARALLEL for all the available codes. The script runs fine in parallel. Let say there are... (1 Reply)
Discussion started by: rkumar28
1 Replies
Tcl_DetachPids(3)					      Tcl Library Procedures						 Tcl_DetachPids(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_DetachPids, Tcl_ReapDetachedProcs, Tcl_WaitPid - manage child processes in background SYNOPSIS
#include <tcl.h> Tcl_DetachPids(numPids, pidPtr) Tcl_ReapDetachedProcs() Tcl_Pid Tcl_WaitPid(pid, statusPtr, options) ARGUMENTS
int numPids (in) Number of process ids contained in the array pointed to by pidPtr. int *pidPtr (in) Address of array containing numPids process ids. Tcl_Pid pid (in) The id of the process (pipe) to wait for. int *statusPtr (out) The result of waiting on a process (pipe). Either 0 or ECHILD. int options (in) The options controlling the wait. WNOHANG specifies not to wait when checking the process. _________________________________________________________________ DESCRIPTION
Tcl_DetachPids and Tcl_ReapDetachedProcs provide a mechanism for managing subprocesses that are running in background. These procedures are needed because the parent of a process must eventually invoke the waitpid kernel call (or one of a few other similar kernel calls) to wait for the child to exit. Until the parent waits for the child, the child's state cannot be completely reclaimed by the system. If a parent continually creates children and doesn't wait on them, the system's process table will eventually overflow, even if all the children have exited. Tcl_DetachPids may be called to ask Tcl to take responsibility for one or more processes whose process ids are contained in the pidPtr array passed as argument. The caller presumably has started these processes running in background and does not want to have to deal with them again. Tcl_ReapDetachedProcs invokes the waitpid kernel call on each of the background processes so that its state can be cleaned up if it has exited. If the process has not exited yet, Tcl_ReapDetachedProcs does not wait for it to exit; it will check again the next time it is invoked. Tcl automatically calls Tcl_ReapDetachedProcs each time the exec command is executed, so in most cases it is not necessary for any code outside of Tcl to invoke Tcl_ReapDetachedProcs. However, if you call Tcl_DetachPids in situations where the exec command may never get executed, you may wish to call Tcl_ReapDetachedProcs from time to time so that background processes can be cleaned up. Tcl_WaitPid is a thin wrapper around the facilities provided by the operating system to wait on the end of a spawned process and to check a whether spawned process is still running. It is used by Tcl_ReapDetachedProcs and the channel system to portably access the operating sys- tem. KEYWORDS
background, child, detach, process, wait Tcl Tcl_DetachPids(3)
All times are GMT -4. The time now is 09:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy