Terminating child script with terminating the parent script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Terminating child script with terminating the parent script
# 1  
Old 05-02-2007
Terminating child script without terminating the parent script

Hi
I was working on a shell script with randomly shows a page of text from a randomly selected topic .As soon as the page is displayed it callers a timer script which keeps on running indefinitely until the timer script is killed by the user.

This is where I have the problem,if I press Cntrl-C then even the parent script gets terminated.This is what my code looks like

cat ${file_nm} |head -$line_count | tail -100

timer.ksh

I tried modifying it to try the get the PID of the timer script and kill it like this below if the user enters 0 ,but even that doesn't seem to work

cat ${file_nm} |head -$line_count | tail -100

bg timer.ksh


PID=$$
echo $PID

read kill_proc
if [[ $kill_proc -eq 0 ]]
then

kill $PID
fi

I tried something like this but even this doesn't seem to work ,can you give me suggestions to just kill the timer script interactively which terminating the parent script as well

The timer script is just a simple infinite while loop

while true
do

sleep 1
done

Thanks for any help

Mervin Johnsingh

Last edited by mervin2006; 05-02-2007 at 03:01 AM..
# 2  
Old 05-02-2007
Use a trap on SIGINT and use a cleanup function to kill the child.
# 3  
Old 05-02-2007
Question Duplicate?

Isnt this a duplicate post?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to capture exit code of child script and send it to parent script?

#!/usr/local/bin/bash set -vx /prod/HotelierLinks/palaceLink/bin/PalacefilesWait /prod/HotelierLinks/palaceLink/bin/prodEnvSetup 03212013 & if then echo "fatal error: Palace/HardRock failed!!!!" 1>&2 echo "Palace Failed" | mail -s "Link Failed at Palace/HardRock" -c... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

2. UNIX for Dummies Questions & Answers

tcsh: how to prevent a foreach from terminating a script when the result is null?

Sorry if this has been answered. I did search both Google and this site and did find this post: unix.com/unix-dummies-questions-answers/152992-how-ignore-errors-script.html However, it wasn't answered. I have the same question - how do you prevent a tcsh script from terminating when the... (4 Replies)
Discussion started by: deepstructure
4 Replies

3. Shell Programming and Scripting

Stop child script by stoping parent script

Hi everyone, I have this problem with a script I'm writting. I want to execute a code running in the background several times through a script. I am writting it like that parent_script for a in 1 2 3 4 5 do exec test -n $a done What I want to do is when parent_script is killed,... (0 Replies)
Discussion started by: geovas
0 Replies

4. UNIX for Advanced & Expert Users

why the script is not terminating with proper results

Hi everyone, I am new to the linux.I wrote a small script and assigning two values to fname and lname and I want if the fname or lname are not given proper name like Toys or Gun the script should terminate and if they are given proper name it should execute.please help thanks:wall: #!/bin/bash... (4 Replies)
Discussion started by: starter2011
4 Replies

5. Shell Programming and Scripting

Parent Script exiting with child script

PARENT SCRIPT #!/bin/ksh # . $HOME/.profile . /etl/estdm2/DEV/scripts/DM_ENV_VARS.ksh DEV DB echo "CALLING CHILD SCRIPT" . /${SCRIPT_DIR}/DM_CHild.ksh -x HRDATA.dat -e $sEnv -d Wait_Time *****THE PARENT SCRIPT EXITS HERE ******** *****whether the file is found or not******* ... (2 Replies)
Discussion started by: sumeet
2 Replies

6. Shell Programming and Scripting

How can i terminating expect script without terminating SSH connection.

Hi all , i know i ask a lot of question but these are really hard to solve and important question. I send two scripts: expect.sh: #!/usr/local/bin/expect spawn ssh root@172.30.64.163 expect "login:" send "root\n" expect "password:" send "root\n^M" interact and son.sh: ... (2 Replies)
Discussion started by: fozay
2 Replies

7. Shell Programming and Scripting

how to terminate ssh connection without terminating script

Hi all, I connect with SSH connection to remote machine in the script and ı want to logout at half of the script then continue to script. If ı write exit in the script it terminates script not SSH connection. How can i do that please help me (1 Reply)
Discussion started by: fozay
1 Replies

8. Shell Programming and Scripting

script unexpectedly terminating

I now that this isnt the greatest code around. Im a network guy by trade not a programer .. but needed something to compare config files ... Anyway ... intermittently, the program terminates. Ive been looking at the code for a week trying to figure it out and Im stumped. Can anyone provide... (0 Replies)
Discussion started by: popeye
0 Replies

9. Shell Programming and Scripting

terminating script with CTRL+D

Hi, I'm trying to make a script that reads the console input and terminates with CTRL+D. It's absolutely basic but I don't know how to "read" the CTRL+D. I've tried a bunch of things like EOT=^D while //with & without quotations do read input echo $input done while while ] ... (12 Replies)
Discussion started by: sanchopansa
12 Replies

10. Shell Programming and Scripting

return valuse from child script to parent script

Hi, I am trying to return a value from child script to a parent script just as a function does. The child script will look for a file and if exists will return 1 else 0. I need to capture the status 1 from child script in the parent script and proceed further. if 0, i need not do... (1 Reply)
Discussion started by: borncrazy
1 Replies
Login or Register to Ask a Question