Sponsored Content
Full Discussion: Trapping program return code
Top Forums Shell Programming and Scripting Trapping program return code Post 302491513 by pavlosgr on Thursday 27th of January 2011 04:25:11 PM
Old 01-27-2011
Trapping program return code

Hello

I have a program (prog) that accepts a parameter in order to execute some internal loop grabbing memory in each iteration. I'm using top to monitor the memory usage and to produce an output.
Thus I need the program's pid as a parameter to top.
I capture pid using myPID=$!.
I'm also checking if the program returns an error code in order to stop the script's execution.

Now using & myPID always equals to 0 even if the program returns an error. Removing & error capture works fine but I have no pid.
Is there any work around in order to have error trapping and pid at the same time?

Code:
#!/bin/sh 
./prog $1 &

myPID=$!
if [ $? -ne 0 ]
then
  echo "error captured"
  exit 1
fi

echo $myPID
top -p $myPID -b -d 1 -n $1 | sed -n '8~10p' | awk '{print $5}' > res.txt

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sql error code trapping

Hello #!bin/ksh sqlplus -s system/manager < |grep '^ORA' |uniq select * from kk; set echo on show spool on end; / EOF save test.sh sh test.sh results ORA-00942: table or view does not exist (3 Replies)
Discussion started by: xiamin
3 Replies

2. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies

3. Shell Programming and Scripting

How to get return value from C program and logs to file

Hi, I have written scritp which prints output from the executable to standard output as well as in a file. Here "add" is an c executable which returns some value based on inputs. But if tee is not used "$?" returns the return value from add exe. If tee is used it is simply retuning 0. echo... (5 Replies)
Discussion started by: yhacks
5 Replies

4. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

5. Shell Programming and Scripting

How to capture C program return values in Kshell

I have a K shell script (ksh) that needs to return an email address. A C program was written (prog1) to now access the email address off of an oracle table. The call to the program in the ksh is prog1 -p parm1 Based on Parm1 the program will read an oracle table and retrieve the email... (2 Replies)
Discussion started by: jclanc8
2 Replies

6. Programming

Parallel Processing Detection and Program Return Value Detection

Hey, for the purpose of a research project I need to know if a specific type of parallel processing is being utilized by any user-run programs. Is there a way to detect whether a program either returns a value to another program at the end of execution, or just utilizes any form of parallel... (4 Replies)
Discussion started by: azar.zorn
4 Replies

7. Shell Programming and Scripting

Trapping SIGINT after restarting program.

Tried to add a function to my control_c interrupt here. It works but has one little bug. If the user selects to run the function instead of exiting, the program restarts itself without forking as it should. However, after that control_c no longer works again. I wanted to allow the user to run... (1 Reply)
Discussion started by: Azrael
1 Replies

8. Shell Programming and Scripting

How to end the program with a successful return code?

i have the follow shell script that try to find any file in the specified path and upload to oracle. if no file will output in the concurrent log and the program return as error , how do i change the program so that if no file found will give out normal sucessful result. i tried change the exit... (3 Replies)
Discussion started by: feilhk
3 Replies

9. Programming

Segment fault for C++ program when return vector

I am trying to reverse complement DNA sequence (string) with a short c++ code using boost library. Code was compiled without any warning/error, but ran into Segmentation fault. My guess is the function to return a vector, but not sure. #include <iostream> #include <fstream> #include <string>... (14 Replies)
Discussion started by: yifangt
14 Replies

10. Shell Programming and Scripting

Trapping the return status from FIND command

I have the following code in a script: find . \( ! -name . -prune \) -name "cg*" -exec cp -p {} "${temp_dir}" \; ret_stat=$? I think the return status is only captured for the 'find' command and not for the 'cp' command. Is there a way to get the return status for the 'cp' command... (7 Replies)
Discussion started by: vskr72
7 Replies
Gearman::Server(3pm)					User Contributed Perl Documentation				      Gearman::Server(3pm)

NAME
Gearman::Server - function call "router" and load balancer DESCRIPTION
You run a Gearman server (or more likely, many of them for both high-availability and load balancing), then have workers (using Gearman::Worker from the Gearman module, or libraries for other languages) register their ability to do certain functions to all of them, and then clients (using Gearman::Client, Gearman::Client::Async, etc) request work to be done from one of the Gearman servers. The servers connect them, routing function call requests to the appropriate workers, multiplexing responses to duplicate requests as requested, etc. More than likely, you want to use the provided gearmand wrapper script, and not use Gearman::Server directly. METHODS
new $server_object = Gearman::Server->new( %options ) Creates and returns a new Gearman::Server object, which attaches itself to the Danga::Socket event loop. The server will begin operating when the Danga::Socket runloop is started. This means you need to start up the runloop before anything will happen. Options: port Specify a port which you would like the Gearman::Server to listen on for TCP connections (not necessary, but useful) create_listening_sock $server_object->create_listening_sock( $portnum ) Add a TCP port listener for incoming Gearman worker and client connections. start_worker $pid = $server_object->start_worker( $prog ) ($pid, $client) = $server_object->start_worker( $prog ) Fork and start a worker process named by $prog and returns the pid (or pid and client object). SEE ALSO
gearmand perl v5.10.1 2010-01-18 Gearman::Server(3pm)
All times are GMT -4. The time now is 05:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy