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
PERLDTRACE(1)						 Perl Programmers Reference Guide					     PERLDTRACE(1)

NAME
perldtrace - Perl's support for DTrace SYNOPSIS
# dtrace -Zn 'perl::sub-entry, perl::sub-return { trace(copyinstr(arg0)) }' dtrace: description 'perl::sub-entry, perl::sub-return ' matched 10 probes # perl -E 'sub outer { inner(@_) } sub inner { say shift } outer("hello")' hello (dtrace output) CPU ID FUNCTION:NAME 0 75915 Perl_pp_entersub:sub-entry BEGIN 0 75915 Perl_pp_entersub:sub-entry import 0 75922 Perl_pp_leavesub:sub-return import 0 75922 Perl_pp_leavesub:sub-return BEGIN 0 75915 Perl_pp_entersub:sub-entry outer 0 75915 Perl_pp_entersub:sub-entry inner 0 75922 Perl_pp_leavesub:sub-return inner 0 75922 Perl_pp_leavesub:sub-return outer DESCRIPTION
DTrace is a framework for comprehensive system- and application-level tracing. Perl is a DTrace provider, meaning it exposes several probes for instrumentation. You can use these in conjunction with kernel-level probes, as well as probes from other providers such as MySQL, in order to diagnose software defects, or even just your application's bottlenecks. Perl must be compiled with the "-Dusedtrace" option in order to make use of the provided probes. While DTrace aims to have no overhead when its instrumentation is not active, Perl's support itself cannot uphold that guarantee, so it is built without DTrace probes under most systems. One notable exception is that Mac OS X ships a /usr/bin/perl with DTrace support enabled. HISTORY
5.10.1 Perl's initial DTrace support was added, providing "sub-entry" and "sub-return" probes. 5.14.0 The "sub-entry" and "sub-return" probes gain a fourth argument: the package name of the function. 5.16.0 The "phase-change" probe was added. PROBES
sub-entry(SUBNAME, FILE, LINE, PACKAGE) Traces the entry of any subroutine. Note that all of the variables refer to the subroutine that is being invoked; there is currently no way to get ahold of any information about the subroutine's caller from a DTrace action. :*perl*::sub-entry { printf("%s::%s entered at %s line %d ", copyinstr(arg3), copyinstr(arg0), copyinstr(arg1), arg0); } sub-return(SUBNAME, FILE, LINE, PACKAGE) Traces the exit of any subroutine. Note that all of the variables refer to the subroutine that is returning; there is currently no way to get ahold of any information about the subroutine's caller from a DTrace action. :*perl*::sub-return { printf("%s::%s returned at %s line %d ", copyinstr(arg3), copyinstr(arg0), copyinstr(arg1), arg0); } phase-change(NEWPHASE, OLDPHASE) Traces changes to Perl's interpreter state. You can internalize this as tracing changes to Perl's "${^GLOBAL_PHASE}" variable, especially since the values for "NEWPHASE" and "OLDPHASE" are the strings that "${^GLOBAL_PHASE}" reports. :*perl*::phase-change { printf("Phase changed from %s to %s ", copyinstr(arg1), copyinstr(arg0)); } EXAMPLES
Most frequently called functions # dtrace -qZn 'sub-entry { @[strjoin(strjoin(copyinstr(arg3),"::"),copyinstr(arg0))] = count() } END {trunc(@, 10)}' Class::MOP::Attribute::slots 400 Try::Tiny::catch 411 Try::Tiny::try 411 Class::MOP::Instance::inline_slot_access 451 Class::MOP::Class::Immutable::Trait:::around 472 Class::MOP::Mixin::AttributeCore::has_initializer 496 Class::MOP::Method::Wrapped::__ANON__ 544 Class::MOP::Package::_package_stash 737 Class::MOP::Class::initialize 1128 Class::MOP::get_metaclass_by_name 1204 Trace function calls # dtrace -qFZn 'sub-entry, sub-return { trace(copyinstr(arg0)) }' 0 -> Perl_pp_entersub BEGIN 0 <- Perl_pp_leavesub BEGIN 0 -> Perl_pp_entersub BEGIN 0 -> Perl_pp_entersub import 0 <- Perl_pp_leavesub import 0 <- Perl_pp_leavesub BEGIN 0 -> Perl_pp_entersub BEGIN 0 -> Perl_pp_entersub dress 0 <- Perl_pp_leavesub dress 0 -> Perl_pp_entersub dirty 0 <- Perl_pp_leavesub dirty 0 -> Perl_pp_entersub whiten 0 <- Perl_pp_leavesub whiten 0 <- Perl_dounwind BEGIN Function calls during interpreter cleanup # dtrace -Zn 'phase-change /copyinstr(arg0) == "END"/ { self->ending = 1 } sub-entry /self->ending/ { trace(copyinstr(arg0)) }' CPU ID FUNCTION:NAME 1 77214 Perl_pp_entersub:sub-entry END 1 77214 Perl_pp_entersub:sub-entry END 1 77214 Perl_pp_entersub:sub-entry cleanup 1 77214 Perl_pp_entersub:sub-entry _force_writable 1 77214 Perl_pp_entersub:sub-entry _force_writable System calls at compile time # dtrace -qZn 'phase-change /copyinstr(arg0) == "START"/ { self->interesting = 1 } phase-change /copyinstr(arg0) == "RUN"/ { self->interesting = 0 } syscall::: /self->interesting/ { @[probefunc] = count() } END { trunc(@, 3) }' lseek 310 read 374 stat64 1056 REFERENCES
DTrace User Guide http://download.oracle.com/docs/cd/E19082-01/819-3620/index.html <http://download.oracle.com/docs/cd/E19082-01/819-3620/index.html> DTrace: Dynamic Tracing in Oracle Solaris, Mac OS X and FreeBSD http://www.amazon.com/DTrace-Dynamic-Tracing-Solaris-FreeBSD/dp/0132091518/ <http://www.amazon.com/DTrace-Dynamic-Tracing-Solaris- FreeBSD/dp/0132091518/> AUTHORS
Shawn M Moore "sartak@gmail.com" perl v5.16.2 2012-10-25 PERLDTRACE(1)
All times are GMT -4. The time now is 05:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy