Strange SIGINT propagation between Parent/Child sh scripts
Good day,
I am trying to add signal handling capabilities to some of my scripts. Unfortunately, I am having some difficulty with the manner in which signals are propagated between parent/child processes. Consider the following example:
I have the following "parent" script:
which calls the following "child" script (as a background process):
When I execute the "parent" process with a ">./parent",
I observe that the expected behavior. I then send a
SIGINT to the "parent" via a ">kill -s SIGINT <ppid>" and
get the following screen output:
Quote:
SIGINT caught in Parent
Parent sending: kill -n 2 20944
Wait Status recorded when parent continues: 130
Parent Still Running after the child exits!
When I look at the processes that are still active, I see
that the child (and its sleep) has not been killed at all -
all that happened was that the sleep-process of the parent
was activated.
I would appreciate it if anybody has some idea what is happening
here.
'When I execute the "parent" process with a ">./parent",' This does not work for me but . parent does run it. Similarly I changed './child &' to '. child &' and got the following output: -
^Cchild got signal 2
Wait Status recorded when parent continues: 0
Parent Still Running after the child exits!
"child got signal 2" is the message from the child's signal handler, not the parent; at this point a ps shows that the child is gone.
A further CTRL C gives: -
^CSIGINT caught in Parent
Parent sending: kill -n 2 7191
kill: 7191: no such process
SIGINT caught in Parent
Parent sending: kill -n 2 7191
kill: 7191: no such process
Note that the handler is called twice.
When I run your code with the line './child &' in it I get the output: -
TX5XN:/home/brad/wip/signals>. parent
parent running ksh: .: line 19: ./child: not found
[1] 7398
child_id = 7398
Wait Status recorded when parent continues: 127
Parent Still Running after the child exits!
^CSIGINT caught in Parent
Parent sending: kill -n 2 7398
kill: 7398: no such process
SIGINT caught in Parent
Parent sending: kill -n 2 7398
kill: 7398: no such process
Are you sure you actually ran the child process or am I missing something? I don't have much experience of signal handlers?
Thanks for your quick reply! I think the "./" works when you make the scripts executable. What I did, was to make each file "parent" and "child" executable with chmod, i.e.
> chmod "+x" parent
and then the same for the child. Then the "./parent" and "./child &" commands should work.
Also, you are using the korn shell. I am using the bash, or sh. (I am not sure which one of the 2 - I am fairly new to Unix).
I have reformulated my original question in the form of 3 new small sh scripts to illustrate exactly what I am struggling with, w.r.t parent/child process behavior:
Consider a "parent" process:
I made the script executable with ">chmod "+x" parent" and executed it in a bash environment, via ">./parent".
I then do a "ps -alf | grep dludick" to see my list of running processes, I observe the following output:
Does anybody know why the sleep processes are not being killed when each of the children receives a "SIGINT" signal? How can I modify the above scripts to ensure this?
That's because the sleep procs didn't get a kill signal. The parent got it. It then killed the kids. But the sleeps (which are kids of the children of parent) did not get a kill. So they continue to sleep. Note that the parent of the sleeps have changed from the original parents to proc id 1 (aka init). The parents died, but the sleeps are still sleeping...
Thank you for you quick reply, your advice worked.
I understand what you mean about the children of the children (i.e. the sleep processes) not getting the signal. I tried the following:
Changed "child1" to:
and then "child2" to:
so that the INT signals gets propagated to the spawned "sleep" children of each. When I now send a SIGINT to the original parent script, I see that the sleep processes are killed active. I think this solves the problem.
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)
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)
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)
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:
... (5 Replies)
Greets all. I'm using Slackware 12.0 with the bash shell. Calling my scripts with /bin/sh...
I'm building gnome-2.18.3 and I have all my build scripts ready and working but I'm calling them from a parent script which executes each child/build script in a certain order (for loop).
I have "set... (6 Replies)
Hello.
I have a global function name func1() that I am sourcing in from script A. I call the function from script B. Is there a way to find out which script called func1() dynamically so that the func1() can report it in the event there are errors?
Thanks (2 Replies)
Hello all,
I have gone through the search and looked at posting about idle users and killing processes. Here is my question I would like to kill an idle user ( which I can do) but how can I asure that all of his process is also killed whit out tracing his inital start PID. I have tried this on a... (4 Replies)
:(
Since I'm fairly new to the scene and don't have much experience in shell programming, I decided to check out the net for a useful script or two.
What I'm looking for is a script that would let me enter a PID and then show the process tree associated with it.
So it would display the (grand-)... (2 Replies)
I don't follow what these are...
this is what my text says...
"When a process is started, a duplicate of that process is created. This new process is called the child and the process that created it is called the parent. The child process then replaces the copy for the code the parent... (1 Reply)