Sponsored Content
Full Discussion: Trapping program return code
Top Forums Shell Programming and Scripting Trapping program return code Post 302491562 by pavlosgr on Thursday 27th of January 2011 06:18:48 PM
Old 01-27-2011
I'm running Ubuntu 10.10, 2.6.35-24-generic kernel.

My code now looks like :

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

sleep 1
kill -0 $myPID

if [ $? -ne  0 ] ; then
  echo 'process terminated'
  exit 
fi

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

It runs smoothly Smilie.
Just a slight drawback as prog should iterate $1 times grabbing some memory each time. Between each iteration it sleeps 1 sec. As my script sleeps for 1 sec I monitor $1-1 iterations than $1.
 

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
CC(1)							      General Commands Manual							     CC(1)

NAME
cc - C compiler SYNOPSIS
cc [-STOUfcimos] [-w[aos]] [-v[n]] [-Dname]* [-Idir]* [-Ldir]* file+ [-lname]* OPTIONS
-D The flag -Dx[=y] defines a macro x with (optional) value y -I -Idir searches dir for include files -L -Ldir searches dir for -lname libraries -O Optimize the code -S Produce an assembly code file, then stop -T The flag -Tdir tells cc and as to use dir for temporary files -U Undefine a macro -E Preprocess to standard output -c Compile only. Do not link -f Link with floating point emulation library -i Use separate I & D space (64K + 64K) ( only) -l The flag -lname causes the library libname.a to be linked -m Remove unnecessary prototypes after preprocessing ( only) -o Put output on file named by next arg -s Strip the symbol-table from executable file -v Verbose; print pass names -vn Verbose; print pass names but do not run them -w Suppress warning messages -ws Suppress strict messages -wa Suppress all warning and strict messages -wo Suppress messages about old-style -.o Do not link the default run-time start-off EXAMPLES
cc -c file.c # Compile file.c cc -DFOO file.c # Treat the symbol FOO as defined cc -wo -o out file.c # Compile old-style code; output to out DESCRIPTION
This is the C compiler. It has eight passes, as follows: Program Input Output Operation performed lib/ncpp prog.c prog.i C preprocessor: #include, #define, #ifdef lib/irrel prog.i prog.i Removal of unnecessary prototypes lib/ncem prog.i prog.k Parsing and semantic analysis lib/nopt prog.k prog.m Optimization of the intermediate code lib/ncg prog.m prog.s Code generation bin/as prog.s prog.o Assembly lib/ld prog.o prog.out Linking lib/cv prog.out a.outConversion to MINIX a.out format In the 68000 versions of MINIX , the preprocessor is not called since the front-end contains the preprocessor. This increases compilation speed. The main program, cc , forks appropriately to call the passes, transmitting flags and arguments. The -v flag causes the passes to be listed as they are called, and the -vn flag causes the passes to be listed but not called. The libraries should be made with aal (which is the same as ar on the 68000 versions), and consist of .o files. The internal order of files inside the library is unimportant, but the order in which the libraries are specified is. When -T is used, the intermediate files end up in the directory specified. Otherwise, /tmp is used. When available memory is very limited (e.g., a 512K machine), it may be necessary to run chmem to reduce the sizes of the compiler passes that do not fit, typically ncem . On the other hand, if the compiler (or, in fact, almost any program) begins acting strange, it is almost always due to its running out of space, either stack space or scratch file space. The relevant pass can be given more stack space using chmem . More space for scratch files can be obtained by removing other files on the device. If the compiler runs out of memory, it may be necessary to use the -m flag. This causes irrel to be run, which removes unnecessary proto- types and thus frees up extra table space within the compiler. Beware, however, that running this pass may cause strictly conforming pro- grams to become non-conforming and vice versa, so you should only run this pass as a last resort. The compiler is derived from the ACK system (Tanenbaum et al., Communications of the ACM, Sept. 1983), not from the AT&T portable C com- piler. It has been shoehorned onto the PC with some loss of performance. SEE ALSO
make(1). CC(1)
All times are GMT -4. The time now is 01:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy