Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Kill/ Trap command not working
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
yagamiram
n00b
n00b


Joined: 17 Feb 2015
Posts: 13

PostPosted: Fri Mar 06, 2015 9:59 pm    Post subject: Kill/ Trap command not working Reply with quote

I have bash script where it calls kill command

kill pid

now the script that is mapped to this pid will capture the signal SIGTERM sent by the kill command and performs stop all its sub-processes before exiting.

Now the 1st script that called the kill command , will go in a while loop for a waiting time of some XXX seconds to check if the pid is killed or not. This is done by calling kill -0 pid. If it is killed, it breaks from the loop and exit otherwise throw and error and exit.

The problem I'm facing is: The 2nd script captures the SIGTERM signal only after the first 1st script ends. It means, the 1st script goes in while loop and once the waiting time is crossed it throws an error exits first. Then the second script captures the SIGTERM signal and performs the action and exits.

When I gave high priority for pid of second script using renice thinking It will make the CPU to execute 1st script as soon as the signal is trapped, but it failed to do so.

How can I make the script that gets the signal to complete its action before the parent script ??

Template of my first script:
Code:

kill pid

variables timeout, interval and waiting time are set to some initial values

sleep for few seconds

while waiting_time < timout:
 check if kill -0 pid
   if it gets 0 go for sleep and increasing waiting time value
   else break

if waiting_time > timeout and still kill -0 pid returned 0 value:
  print error


2nd script:

Code:
trap function_name SIGTERM

function_name does the following this:

kill whatever the pids that are started by it

and exit 0


Now if I give
Code:
kill process_id_of_second_script
, the signal is not captured by the script

only
Code:
kill -9 process_id_of_second_script
kills the process but it is not killing the processes that are created by it.

And if I kill any of the processes created by the second script, it is created again in different process id.

How to make the script to accept the signal immediately when the kill command is called ?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum