Killing parent shells from subshells (KSH)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Killing parent shells from subshells (KSH)
# 1  
Old 06-27-2007
Killing parent shells from subshells (KSH)

Hi all,

I have a shell script which calls other shell scripts, depending on the input.

Within a.sh, I have a command which calls b.sh (ie. ksh b.sh)

Normally, we use the exit function to terminate a shell. However, if I choose to call exit from b.sh, I will return to the parent shell who activated the shell (ie. a.sh), rather than to close the application completely.

Is there a command that I can use to close all parent shells from b.sh?

Thanks in advance.
# 2  
Old 06-27-2007
Use 'exec b.sh' instead of 'ksh b.sh'
# 3  
Old 06-27-2007
Quote:
Originally Posted by aigles
Use 'exec b.sh' instead of 'ksh b.sh'
Thanks a lot!
# 4  
Old 06-28-2007
Suppose that I want to allow the user to have a choice between:

1. Terminating the shell completely
2. Or closing the subshell and going back to the previous shell script that called it.

How can this be implemented? Is it through the use of using ksh b.sh instead of exec b.sh and then:

1. have a case statement which calls exit from the subshell to go back to previous page.

2. use some signal to kill the whole shell

Am I correct to say this? If so, what is the command to be used to implement the signals?

Thanks in advance.
# 5  
Old 06-28-2007
If the parent shell script used "exec" to call your script then the parent script has gone when you shell runs.

This is because exec replaces the current program with a new one. The old program is no longer running.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

--killing backround Procs spawned from the parent script with Ctrl+C trap

Hello: Am trying to understand why the method #2 works but method #1 does not. For both methods, sending CTRL+C should kill both the Parent script & all of the spanwd background procs. Method #1: ========================== #!/bin/sh ctrl_c() { echo "** Trapped CTRL-C" ... (3 Replies)
Discussion started by: gilgamesh
3 Replies

2. Solaris

Child killing parent process and how to set up SMF

Hello, A little background on what we are doing first. We are running several applications from a CLI, and not all of them are fully functional. They do on occasion core dump, not a problem. We are running a service that takes a screen scrape of those apps and displays them in a more user... (5 Replies)
Discussion started by: Bryan.Eidson
5 Replies

3. Shell Programming and Scripting

Question regarding shells and subshells when a script is run

I have the following script running with nohup on one of my servers: #!/bin/bash #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #set log number #i=1 #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #Check if log exits, if so incrememnt log number up so we don't clobber #while... (8 Replies)
Discussion started by: DeCoTwc
8 Replies

4. Red Hat

Killing child daemon started by parent process

Hi All, Hope this is right area to ask this question. I have a shell script (bash) "wrapper.sh", which contains few simple shell command which executes a "server.sh" (conatins code to execute a java server) as a daemon. Now what I want to kill this "server.sh" so that the server should... (2 Replies)
Discussion started by: jw_amp
2 Replies

5. UNIX for Advanced & Expert Users

Child Killing Parent

Hi all, I am writing a script which calls other third party scripts that perform numerous actions. I have no control over these scripts. My problem is, one of these scripts seems to execute and do what it is meant to do, but my calling / parent script always exits at that point. I need to... (4 Replies)
Discussion started by: mark007
4 Replies

6. UNIX for Advanced & Expert Users

how to make a parent wait on a child shells running in background?

Hi I have a shell script A which calls another 10 shell scripts which run in background. How do i make the parent script wait for the child scripts complete, or in other words, i must be able to do a grep of parent script to find out if the child scripts are still running. My Code: ... (1 Reply)
Discussion started by: albertashish
1 Replies

7. UNIX for Dummies Questions & Answers

Killing all active shells without rebooting

Hi All, This may seem to be a very strange request but here is what I am trying to do 1. run a clean up script for my product which will basically remove the directories, entries in the /etc/profile After that I need to know who all are logged on to the Unix server and log them all off.... (3 Replies)
Discussion started by: Kesava81
3 Replies

8. UNIX for Dummies Questions & Answers

Passing environment variables to parent shells

Hi, I am using bash and need to run a set of tcsh scripts that set environment variables. Is there a way to do this? Any help greatly appreciated. (3 Replies)
Discussion started by: konndanley
3 Replies

9. UNIX for Dummies Questions & Answers

forking and killing parent processes

Hi everybody, I'm having some problems wiriting a program in UNIX using the "fork" and "kill" system calls. I have to create a C program P0, which creates 9 other processes P1, P2, ..., P9, where P0 is the father of P1, P1 the father of P2, and so on. All the processes contain an infinite... (0 Replies)
Discussion started by: davewilliams20
0 Replies

10. Answers to Frequently Asked Questions

Difference between ksh,bash and different shells.

Hello Everyone, Can someone please tell me the key difference between the different shells availabe i.e. ksh,bash,(i don't know the others ones. :confused: (5 Replies)
Discussion started by: a25khan
5 Replies
Login or Register to Ask a Question