Sponsored Content
Top Forums Shell Programming and Scripting Strange SIGINT propagation between Parent/Child sh scripts Post 302362132 by danie.ludick on Thursday 15th of October 2009 04:38:19 AM
Old 10-15-2009
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:
Code:
#!/bin/sh

echo starting proc 1, pid=$$
sleep 600 &
pid1=$!
trap "kill $pid1" exit INT
wait

and then "child2" to:
Code:
#!/bin/sh

echo starting proc 2, pid=$$
sleep 600 &
pid1=$!
trap "kill $pid1" exit INT
wait

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.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

what are parent and child processes all about?

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)
Discussion started by: xyyz
1 Replies

2. Filesystems, Disks and Memory

How hard can it be? ps child/parent

:( 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)
Discussion started by: velde046
2 Replies

3. UNIX for Dummies Questions & Answers

kill parent and child

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)
Discussion started by: larry
4 Replies

4. Shell Programming and Scripting

Parent/Child Processes

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)
Discussion started by: yoi2hot4ya
2 Replies

5. Shell Programming and Scripting

Error trapping in parent/child scripts

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)
Discussion started by: madpenguin
6 Replies

6. Shell Programming and Scripting

multiple child scripts running in backgroud, how to use grep on the parent?

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)
Discussion started by: albertashish
5 Replies

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

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

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

10. UNIX for Dummies Questions & Answers

parent and child directory

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
vfork(2)							   System Calls 							  vfork(2)

NAME
vfork - spawn new process in a virtual memory efficient way SYNOPSIS
#include <unistd.h> pid_t vfork(void); DESCRIPTION
The vfork() function creates a new process without fully copying the address space of the old process. This function is useful in instances where the purpose of a fork(2) operation is to create a new system context for an execve() operation (see exec(2)). Unlike with the fork() function, the child process borrows the parent's memory and thread of control until a call to execve() or an exit (either abnormally or by a call to _exit() (see exit(2)). Any modification made during this time to any part of memory in the child process is reflected in the parent process on return from vfork(). The parent process is suspended while the child is using its resources. In a multithreaded application, vfork() borrows only the thread of control that called vfork() in the parent; that is, the child contains only one thread. The use of vfork() in multithreaded applications, however, is unsafe due to race conditons that can cause the child process to become deadlocked and consequently block both the child and parent process from execution indefinitely. The vfork() function can normally be used the same way as fork(). The procedure that called vfork(), however, should not return while run- ning in the child's context, since the eventual return from vfork() in the parent would be to a stack frame that no longer exists. The _exit() function should be used in favor of exit(3C) if unable to perform an execve() operation, since exit() will invoke all functions registered by atexit(3C) and will flush and close standard I/O channels, thereby corrupting the parent process's standard I/O data struc- tures. Care must be taken in the child process not to modify any global or local data that affects the behavior of the parent process on return from vfork(), unless such an effect is intentional. The vfork() function is deprecated. Its sole legitimate use as a prelude to an immediate call to a function from the exec family can be achieved safely by posix_spawn(3C) or posix_spawnp(3C). RETURN VALUES
Upon successful completion, vfork() returns 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, -1 is returned to the parent process, no child process is created, and errno is set to indicate the error. ERRORS
The vfork() function will fail if: EAGAIN The system-imposed limit on the total number of processes under execution (either system-quality or by a single user) would be exceeded. This limit is determined when the system is generated. ENOMEM There is insufficient swap space for the new process. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Obsolete | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
exec(2), exit(2), fork(2), ioctl(2), atexit(3C), exit(3C), posix_spawn(3C), posix_spawnp(3C), signal.h(3HEAD), wait(3C), attributes(5), standards(5) NOTES
To avoid a possible deadlock situation, processes that are children in the middle of a vfork() are never sent SIGTTOU or SIGTTIN signals; rather, output or ioctls are allowed and input attempts result in an EOF indication. To forstall parent memory corruption due to race conditions with signal handling, vfork() treats signal handlers in the child process in the same manner as the exec(2) functions: signals set to be caught by the parent process are set to the default action (SIG_DFL) in the child process (see signal.h(3HEAD)). Any attempt to set a signal handler in the child before execve() to anything other than SIG_DFL or SIG_IGN is disallowed and results in setting the handler to SIG_DFL. On some systems, the implementation of vfork() causes the parent to inherit register values from the child. This can create problems for certain optimizing compilers if <unistd.h> is not included in the source calling vfork(). SunOS 5.10 8 Nov 2004 vfork(2)
All times are GMT -4. The time now is 06:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy