Unable to execute a function using trap


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Unable to execute a function using trap
# 1  
Old 05-01-2009
Unable to execute a function using trap

I have a script A which calls script B. I wrote a function in script A to be executed when Kill command is issued for script A and I invoke that function using the trap command.The function identifies all child process running under script A (in this case script B) and kills the child process and performs some operation lets say it updates database tables and log files.

when i execute the "kill -15 script_A_pid" the function that i wrote in script A does not run. I think its because script B (child process) is running.

When i provide kill -15 script_b_pid then child process is terminated and the function that i wrote in script A gets executed.

I would like to know how to execute the function that i wrote in my script Aeven when my script B is running. I want to allways kill script A which should take care of killing script B.
# 2  
Old 05-01-2009
How does your trap procedure look like?

Code:
trap 'function name;exit' 15


cheers,
Devaraj Takhellambam
# 3  
Old 05-01-2009
Something similar but i placed the exit inside the function

trap function_name 15
# 4  
Old 05-01-2009
I wouldn't think that having a child process would suddenly override traps. Could we see what the code for your script actually is?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Help - Infinite Loop: Error in trap function

Hi, I was working on implementing error handling in my bash scripts, and decided to use trap to send myself an email incase of any errors. But it seems that somethings has gone wrong, and I am continuously getting same emails for an old error repeatedly (even though I have stopped/killed all... (1 Reply)
Discussion started by: cool.aquarian
1 Replies

2. Shell Programming and Scripting

Unable to execute glance from cronjob

Hi I am writing a script to get the CPU and memory utilization periodically from glance command. Wrote a script which consists of below two lines Script name : Utilization.sh #!/bin/sh glance -iterations 1 | sed -n '/Util/p/'| awk '!/Disk/'| awk '!/Swap/' >> file.txt I am able to run the... (5 Replies)
Discussion started by: Shravani
5 Replies

3. AIX

Unable to execute snap command

Hi Friends, I am not able to execute snap -a command in AIX 6 system. Could you please let me know how to make work this command and Path to be set. Thanks in Advance Siva. (4 Replies)
Discussion started by: sivakumarl
4 Replies

4. Solaris

Unable to execute any comman on a file

Hello everyone, I'm having a problem with a file. I can run any command on it : cp, mv, chmod,ln,more... Thanks for your help (13 Replies)
Discussion started by: adilyos
13 Replies

5. UNIX for Dummies Questions & Answers

unable to execute while loop

Hi everyone. I wanted to print numbers from 1 to 5 in reverse order. For this I used the following code: #!/bin/bash x=5 while do echo $x x=`expr $x - 1` echo "" done echo "" Well but on compiling the above code, it gives the following error. ... (3 Replies)
Discussion started by: grc
3 Replies

6. AIX

Unable to execute varyonvg during importvg

Hello, On Aix 5.3, during importvg, the varyonvg fails: importvg -y vgtest hdisk20 0516-013 varyonvg: The volume group cannot be varied on because there are no good copies of the descriptor area. When i use manually the command varyonvg -u -b -t vgtest to force, the vg can... (3 Replies)
Discussion started by: dantares
3 Replies

7. Shell Programming and Scripting

Record the Signal Type or Number in Bash Trap function

In my Bash script I have an exit/cleanup function in a trap statement like: trap exitCleanup 1 2 3 6 15 25 Is there anyway to capture which signal # has occurred to record in a log file. Please note I am trying to avoid something like: trap 'mySignal=1; exitCleanup' 1 trap... (1 Reply)
Discussion started by: ckmehta
1 Replies

8. Shell Programming and Scripting

Trap getting lost in 2nd-level function

This is probably a failure in my understanding of trap or of function invocation. I'd really appreciate if someone could explain. This is Solaris 10, but I don't think it matters. #!/usr/bin/ksh trap 'cleanUp $@' exit function cleanUp { print "I got called" } function check { ... (4 Replies)
Discussion started by: plavacek
4 Replies

9. Shell Programming and Scripting

unable to execute background job

I am unable to execute the below command in background. Plz suggest. #> ./test input >out & 913618 + Stopped (SIGTTIN) ./test input >out & Suresh (1 Reply)
Discussion started by: suresh3566
1 Replies

10. UNIX for Advanced & Expert Users

unable to execute a .SH file

this is (11 Replies)
Discussion started by: angelina
11 Replies
Login or Register to Ask a Question