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
IO::Async::ChildManager(3pm)				User Contributed Perl Documentation			      IO::Async::ChildManager(3pm)

NAME
"IO::Async::ChildManager" - facilitates the execution of child processes SYNOPSIS
This object is used indirectly via an "IO::Async::Loop": use IO::Async::Loop; use POSIX qw( WEXITSTATUS ); my $loop = IO::Async::Loop->new; ... $loop->run_child( command => "/bin/ps", on_finish => sub { my ( $pid, $exitcode, $stdout, $stderr ) = @_; my $status = WEXITSTATUS( $exitcode ); print "ps [PID $pid] exited with status $status "; }, ); $loop->open_child( command => [ "/bin/ping", "-c4", "some.host" ], stdout => { on_read => sub { my ( $stream, $buffref, $eof ) = @_; while( $$buffref =~ s/^(.*) // ) { print "PING wrote: $1 "; } return 0; }, }, on_finish => sub { my ( $pid, $exitcode ) = @_; my $status = WEXITSTATUS( $exitcode ); ... }, ); my ( $pipeRd, $pipeWr ) = IO::Async::OS->pipepair; $loop->spawn_child( command => "/usr/bin/my-command", setup => [ stdin => [ "open", "<", "/dev/null" ], stdout => $pipeWr, stderr => [ "open", ">>", "/var/log/mycmd.log" ], chdir => "/", ] on_exit => sub { my ( $pid, $exitcode ) = @_; my $status = WEXITSTATUS( $exitcode ); print "Command exited with status $status "; }, ); $loop->spawn_child( code => sub { do_something; # executes in a child process return 1; }, on_exit => sub { my ( $pid, $exitcode, $dollarbang, $dollarat ) = @_; my $status = WEXITSTATUS( $exitcode ); print "Child process exited with status $status "; print " OS error was $dollarbang, exception was $dollarat "; }, ); DESCRIPTION
This module extends the functionality of the containing "IO::Async::Loop" to manage the execution of child processes. It acts as a central point to store PID values of currently-running children, and to call the appropriate continuation handler code when the process terminates. It provides useful wrapper methods that set up filehandles and other child process details, and to capture the child process's STDOUT and STDERR streams. METHODS
When active, the following methods are available on the containing "Loop" object. $pid = $loop->spawn_child( %params ) This method creates a new child process to run a given code block or command. The %params hash takes the following keys: command => ARRAY or STRING Either a reference to an array containing the command and its arguments, or a plain string containing the command. This value is passed into perl's "exec" function. code => CODE A block of code to execute in the child process. It will be called in scalar context inside an "eval" block. setup => ARRAY A reference to an array which gives file descriptors to set up in the child process before running the code or command. See below. on_exit => CODE A continuation to be called when the child processes exits. It will be invoked in the following way: $on_exit->( $pid, $exitcode, $dollarbang, $dollarat ) The second argument is passed the plain perl $? value. To use that usefully, see "WEXITSTATUS" and others from "POSIX". Exactly one of the "command" or "code" keys must be specified. If the "command" key is used, the given array or string is executed using the "exec" function. If the "code" key is used, the return value will be used as the exit(2) code from the child if it returns (or 255 if it returned "undef" or thows an exception). Case | WEXITSTATUS($exitcode) | $dollarbang | $dollarat --------------+------------------------+-------------+---------- exec succeeds | exit code from program | 0 | "" exec fails | 255 | $! | "" $code returns | return value | $! | "" $code dies | 255 | $! | $@ It is usually more convenient to use the "open_child" method in simple cases where an external program is being started in order to interact with it via file IO, or even "run_child" when only the final result is required, rather than interaction while it is running. "setup" array This array gives a list of file descriptor operations to perform in the child process after it has been fork(2)ed from the parent, before running the code or command. It consists of name/value pairs which are ordered; the operations are performed in the order given. fdn => ARRAY Gives an operation on file descriptor n. The first element of the array defines the operation to be performed: [ 'close' ] The file descriptor will be closed. [ 'dup', $io ] The file descriptor will be dup2(2)ed from the given IO handle. [ 'open', $mode, $file ] The file descriptor will be opened from the named file in the given mode. The $mode string should be in the form usually given to the "open" function; such as '<' or '>>'. [ 'keep' ] The file descriptor will not be closed; it will be left as-is. A non-reference value may be passed as a shortcut, where it would contain the name of the operation with no arguments (i.e. for the "close" and "keep" operations). IO => ARRAY Shortcut for passing "fdn", where n is the fileno of the IO reference. In this case, the key must be a reference that implements the "fileno" method. This is mostly useful for $handle => 'keep' fdn => IO A shortcut for the "dup" case given above. stdin => ... stdout => ... stderr => ... Shortcuts for "fd0", "fd1" and "fd2" respectively. env => HASH A reference to a hash to set as the child process's environment. nice => INT Change the child process's scheduling priority using "POSIX::nice". chdir => STRING Change the child process's working directory using "chdir". setuid => INT setgid => INT Change the child process's effective UID or GID. setgroups => ARRAY Change the child process's groups list, to those groups whose numbers are given in the ARRAY reference. On most systems, only the privileged superuser change user or group IDs. "IO::Async" will NOT check before detaching the child process whether this is the case. If setting both the primary GID and the supplementary groups list, it is suggested to set the primary GID first. Moreover, some operating systems may require that the supplementary groups list contains the primary GID. If no directions for what to do with "stdin", "stdout" and "stderr" are given, a default of "keep" is implied. All other file descriptors will be closed, unless a "keep" operation is given for them. If "setuid" is used, be sure to place it after any other operations that might require superuser privileges, such as "setgid" or opening special files. AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.14.2 2012-10-24 IO::Async::ChildManager(3pm)
All times are GMT -4. The time now is 10:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy