Child Killing Parent


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Child Killing Parent
# 1  
Old 03-06-2009
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 figure out a way to call these child scripts, and for them to NEVER touch the parent. I have no idea why it is doing this, but hoping theres a simple way to stop it.

Here is what happens in my main parent script that simply calls other scripts.

Call Script 1
Call Script 2
Call Script 3
EXITS HERE
Script 4 never runs
Script 5 never runs
# 2  
Old 03-06-2009
Whats in script3?
If you have a exec <something else e.g. menu...>
with a badly placed exit (or one too much..)
you can end up having parent script exit also, and so 4 and following are to never run...
# 3  
Old 03-06-2009
Quote:
Originally Posted by vbe
Whats in script3?
If you have a exec <something else e.g. menu...>
with a badly placed exit (or one too much..)
you can end up having parent script exit also, and so 4 and following are to never run...

I don't follow that. If my script, say pid 1223, invokes script B, a child process is created for script B, let's say it is pid 1337. Now script B can what it wants to pid 1337, but pid 1223 should stay intact.

One thing that script B might do is to obtain the pid of its parent and then explicitly kill that pid. To protect against that, we could do:
( scriptB )
The parentheses create a subshell and the subshell is now the parent of scriptB. We hope that scriptB will ignore its grandparent.

In the worst case,
echo /path/to/scriptB | at now
would totally disconnect scriptB, but now it's hard to wait for scriptB to finish.
# 4  
Old 03-09-2009
Thanks for the replies.

The problem is, these scripts are not under my control at all. I can only think from the point of view of the parent, I need to run these scripts, and they should never be allowed kill the parent. Is this possible do you think from the parents point of view?
# 5  
Old 03-09-2009
Thanks Perderabo for noting my nonsense, I was disturbed friday by phonecalls and people in my office when trying to post and got mixed up...the exec I was thinking about was on calling script 3, not inside...(silly because in present case there is no mention of exits...)
Anyway you are right here it looks more the script found its parent and explicitly killed it like a bugged ps -ef to get all process I launched to kill and in the lot there is my unfortunate parent...
Quote:
I need to run these scripts, and they should never be allowed kill the parent. Is this possible do you think from the parents point of view?
Difficult because same UID...
But Perderabo gave you the workaround (a new subshell who becomes now the parent...).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Programming

Killing a Child Thread

What is the best way for a parent to kill a child thread that has blocked on a command it cannot finish and will never read another line of its code? Will pthread_cancel() work with a thread that will never stop processing its current line of code? Thanks. (4 Replies)
Discussion started by: Brandon9000
4 Replies

3. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

4. Homework & Coursework Questions

Need help with deleting childīs parent and child subprocess

1. The problem statement, all variables and given/known data: I need to make an program that in a loop creates one parent and five children with fork(). The problem i'm trying to solve is how to delete the parent and child of the childīs process. 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: WhiteFace
0 Replies

5. 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

6. UNIX for Advanced & Expert Users

killing all child processes

Hi, Is there a way I can kill all the child processes of a process, given its process id. Many thanks in advance. J. (1 Reply)
Discussion started by: superuser84
1 Replies

7. Shell Programming and Scripting

Killing child process in ksh

I have a script that (ideally) starts tcpdump, sleeps a given number of seconds, then kills it. When I do this for 10 seconds or and hour, it works fine. When I try it for 10 hours (the length I actually want) it just doesn't die, and will actually stick around for days. Relevant part of my... (1 Reply)
Discussion started by: upnix
1 Replies

8. Shell Programming and Scripting

killing a child process

I am calling another script from my main script and making it run in the background,based upon the value of the input provided by the user I want to kill the child process ,I have written this code timer.ksh & PID=$$ print "\n Do you wish to continue .. (Y/N) : \c " read kill_proc if ]... (4 Replies)
Discussion started by: mervin2006
4 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. Shell Programming and Scripting

killing a child process within a shell

Hi All, I have a written a script in korn shell for importing data into a oracle database. The shell invokes the import within the script. I want to kill this import (child process) . I tries using trap, but this does not kill the import even if i press cnt c. i have to login into other terminal... (2 Replies)
Discussion started by: yerics
2 Replies
Login or Register to Ask a Question