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.
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)
:(
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)
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)
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)
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)
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)
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)
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 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)
does anyone know how to check in an 'if' statement if a particular directory is a child directory of a particular directory?
help ~ (2 Replies)
Discussion started by: ymc1g11
2 Replies
LEARN ABOUT HPUX
child
Child(3pm) User Contributed Perl Documentation Child(3pm)NAME
Child - Object oriented simple interface to fork()
DESCRIPTION
Fork is too low level, and difficult to manage. Often people forget to exit at the end, reap their children, and check exit status. The
problem is the low level functions provided to do these things. Throw in pipes for IPC and you just have a pile of things nobody wants to
think about.
Child is an Object Oriented interface to fork. It provides a clean way to start a child process, and manage it afterwords. It provides
methods for running, waiting, killing, checking, and even communicating with a child process.
NOTE: kill() is unpredictable on windows, strawberry perl sends the kill signal to the parent as well as the child.
SYNOPSIS
BASIC
use Child;
my $child = Child->new(sub {
my ( $parent ) = @_;
....
# exit() is called for you at the end.
});
my $proc = $child->start
# Kill the child if it is not done
$proc->complete || $proc->kill(9);
$proc->wait; #blocking
IPC
# Build with IPC
my $child2 = Child->new(sub {
my $self = shift;
$self->say("message1");
$self->say("message2");
my $reply = $self->read(1);
}, pipe => 1 );
my $proc2 = $child2->start;
# Read (blocking)
my $message1 = $proc2->read();
my $message2 = $proc2->read();
$proc2->say("reply");
SHORTCUT
Child can export the child() shortcut function when requested. This function creates and starts the child process in one action.
use Child qw/child/;
my $proc = child {
my $parent = shift;
...
};
You can also request IPC:
use Child qw/child/;
my $child = child {
my $parent = shift;
...
} pipe => 1;
DETAILS
First you define a child, you do this by constructing a Child object. Defining a child does not start a new process, it is just the way to
define what the new process will look like. Once you have defined the child you can start the process by calling $child->start(). One child
object can start as many processes as you like.
When you start a child an Child::Link::Proc object is returned. This object provides multiple useful methods for interacting with your
process. Within the process itself an Child::Link::Parent is created and passed as the only parameter to the function used to define the
child. The parent object is how the child interacts with its parent.
PROCESS MANAGEMENT METHODS
@procs = Child->all_procs()
Get a list of all the processes that have been started. This list is cleared in processes when they are started; that is a child will
not list its siblings.
@pids = Child->all_proc_pids()
Get a list of all the pids of processes that have been started.
Child->wait_all()
Call wait() on all processes.
EXPORTS
$proc = child( sub { ... } )
$proc = child { ... }
$proc = child( sub { ... }, $plugin, @data )
$proc = child { ... } $plugin => @data
Create and start a process in one action.
CONSTRUCTOR
$child = Child->new( sub { ... } )
$child = Child->new( sub { ... }, $plugin, @plugin_data )
Create a new Child object. Does not start the child.
OBJECT METHODS
$proc = $child->start()
Start the child process.
SEE ALSO
Child::Link::Proc
The proc object that is returned by $child->start()
Child::Link::Parent
The parent object that is provided as the argumunt to the function used to define the child.
Child::Link::IPC
The base class for IPC plugin link objects. This provides the IPC methods.
HISTORY
Most of this was part of Parrallel::Runner intended for use in the Fennec project. Fennec is being broken into multiple parts, this is one
such part.
FENNEC PROJECT
This module is part of the Fennec project. See Fennec for more details. Fennec is a project to develop an extendable and powerful testing
framework. Together the tools that make up the Fennec framework provide a potent testing environment.
The tools provided by Fennec are also useful on their own. Sometimes a tool created for Fennec is useful outside the greator framework.
Such tools are turned into their own projects. This is one such project.
Fennec - The core framework
The primary Fennec project that ties them all together.
AUTHORS
Chad Granum exodist7@gmail.com
COPYRIGHT
Copyright (C) 2010 Chad Granum
Child is free software; Standard perl licence.
Child is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
perl v5.10.1 2011-03-07 Child(3pm)