11-15-2011
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 (if the Application have threads).
4. Now kill the parent, check the status of child process which will be orphan now and check that it will taken by init process.
5. Kill the application
i need lead in this script .. help
10 More Discussions You Might Find Interesting
1. Programming
Hi everybody,
I'm trying to understand how a parent and child processes interact.
This function( below) basically measures the fork time from the perspective of the parent only.
what i would like to know is how to measure the time from the perspective of parent and child (ie: inserting... (0 Replies)
Discussion started by: tosa
0 Replies
2. Shell Programming and Scripting
Hi All,
I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program.
I want 1st script to wait until the 'C' program completes.
I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies
3. UNIX for Dummies Questions & Answers
Hi All,
I facing a problem in handling signals between parent process communication. I am trying to send a signal(SIGINT) from child to parent. I am using kill function to do so and I am trying to read the signal using sigaction(). But the program is ending abruptly and I am not able to figure out... (4 Replies)
Discussion started by: vkn_1985
4 Replies
4. Shell Programming and Scripting
Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know.
More detail.
ScriptA (bash), ScriptB (ksh), ScriptC (bash)
ScriptA, launches ScriptB
ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies
5. Programming
Hi guys, I'm having some problem here, I'm studying pipes, and i want to create a shell in C and at this point a don't want to use semaphores, instead I want to use tricks. Straight to the doubt: I've a parent and a child process, and both of them has some code to execute, and the child process... (5 Replies)
Discussion started by: pharaoh
5 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I have a script that calls other scripts/commands which may or may not spawn other process.
From my understanding, when I do a ps -ef, the highest numbered process ID is supposed to be the parent ID of all the other related child processes, is this correct?
In most or all... (3 Replies)
Discussion started by: newbie_01
3 Replies
7. Programming
Hi, i want that the parent process start before the child, this code doesn't work,
if the child start before the parent it wait for signal, then the father send the signal SIGALRM and the child catch it and call printf;
else the father call printf and send the signal to the child that call its... (1 Reply)
Discussion started by: blob84
1 Replies
8. Emergency UNIX and Linux Support
Hello, everyone.
Here's a program:
pid_t pid = fork();
if (0 == pid) // child process
{
execvp ...;
}
I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process.
However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies
9. Shell Programming and Scripting
Hi all,
I am starting mgen5 for sometime depends on input from a file, in a child process. now I want to make parent to wait in this child process till mgen5 finishes, or timeout happens.
could anyone please tell me how to make parent to wait in child process in shell script?
thanks... (2 Replies)
Discussion started by: girijajoshi
2 Replies
10. Shell Programming and Scripting
HI i would like to know how i can simulate a shell scripts for my requirement.
example
Server name child Process id Parent Process id
Vpesh 16013 15637
Server name child Process id Parent Process id
Vpesh 16014 15637
Server name child... (1 Reply)
Discussion started by: vpesh
1 Replies
LEARN ABOUT OSF1
pthread_atfork
pthread_atfork(3) Library Functions Manual pthread_atfork(3)
NAME
pthread_atfork - Declares fork handler routines to be called when the calling thread's process forks a child process.
LIBRARY
Standard C Library (libc.so, libc.a)
SYNOPSIS
#include <pthread.h>
int pthread_atfork(
void (*prepare)(void),
void (*parent)(void),
void (*child)(void));
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
IEEE Std 1003.1c-1995, POSIX System Application Program Interface
PARAMETERS
Address of a routine that performs the fork preparation handling. This routine is called in the parent process before creating the child
process. Address of a routine that performs the fork parent handling. This routine is called in the parent process after creating the
child process and before returning to the caller of fork(2). Address of a routine that performs the fork child handling. This routine is
called in the child process before returning to the caller of fork(2).
DESCRIPTION
This routine allows a main program or library to control resources during a fork(2) operation by declaring fork handler routines, as fol-
lows: The fork handler routine specified in the prepare argument is called before fork(2) executes. The fork handler routine specified in
the parent argument is called after fork(2) executes within the parent process. The fork handler routine specified in the child argument
is called in the new child process after fork(2) executes. Your program (or library) can use fork handlers to ensure that program context
in the child process is consistent and meaningful. After fork(2) executes, only the calling thread exists in the child process, and the
state of all memory in the parent process is replicated in the child process, including the states of any mutexes, condition variables, and
so on.
For example, in the new child process there might exist locked mutexes that are copies of mutexes that were locked in the parent process by
threads that do not exist in the child process. Therefore, any associated program state might be inconsistent in the child process.
The program can avoid this problem by calling pthread_atfork to provide routines that acquire and release resources that are critical to
the child process. For example, the prepare handler should lock all mutexes that you want to be usable in the child process. The parent
handler just unlocks those mutexes. The child handler will also unlock them all--and might also create threads or reset any program state
for the child process.
If no fork handling is desired, you can set any of this routine's arguments to NULL.
NOTES
It is not legal to call pthread_atfork from within a fork handler routine. Doing so could cause a deadlock.
EXAMPLES
For example, if your library uses a mutex my_mutex, you might provide pthread_atfork handler routines coded as follows:
void my_prepare(void)
{
pthread_mutex_lock(&my_mutex);
}
void my_parent(void)
{
pthread_mutex_unlock(&my_mutex);
}
void my_child(void)
{
pthread_mutex_unlock(&my_mutex);
/* Reinitialize state that doesn't apply...like heap owned */
/* by other threads */
}
{
.
.
.
pthread_atfork(my_prepare, my_parent, my_child);
.
.
fork();
}
RETURN VALUES
If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Successful completion Insufficient table space exists to record the fork handler routines' addresses.
ERRORS
None
RELATED INFORMATION
Functions: pthread_create(3)
Manuals: Guide to DECthreads, Programmer's Guide
delim off
pthread_atfork(3)