10-20-2005
C programs start with special start-up code that invokes main(). You come back to this stub when you return from main. The stub then invokes exit(). Within exit(), any atexit() routines get invoked. After all of that the system call _exit() is called. The process will never return from this system call...no more user code will run. _exit() will close any open files.
There is a lot of stuff left to be done to shut down the process and different os's do it in different order. One of the things is to send SIGCHLD to the parent. When the parent gets the SIGCHLD signal, the kernel may still be working to finish the _exit() call. If process accounting or C2 security auditing is active this may involve writing records to disk files. But the process is being killed as fast as the kernel can manage it.
One thing though.... System V had a SIGCLD while BSD had a SIGCHLD and they worked differently. Posix boldly decided that the spelling should be SIGCHLD but did not specify which behavior to use. So the parent may be able to set a flag called SA_NOCLDWAIT which will inhibit SIGCHLD from being set at all.
9 More Discussions You Might Find Interesting
1. Programming
Hello everybody, this is my first post on this forum. I have a program that has a child process that sleeps for 5 second and exit. I'm suppose to modify this program so that when the child exits, the parent reports the exit status of the child, so I also have to deal with SIGINT and SIGQUIT. Can... (1 Reply)
Discussion started by: Unlimited Sky
1 Replies
2. Programming
Hi,
I have an c++ application which uses the function fork and execvp().
The parent does not wait until the child ends. The parents just creates children and let them do their stuff.
You can see the parent program as a batch-manager.
I have added a SIGCHLD handler to the program:
void... (3 Replies)
Discussion started by: jens
3 Replies
3. UNIX for Dummies Questions & Answers
When the SIGCHLD is sent?
SIGCHLD is sent either a child exits spontaneously (e.g. exit(0)) or it is killed ?
thank you in advance (3 Replies)
Discussion started by: Puntino
3 Replies
4. Shell Programming and Scripting
i have installed vmware on a text base linux node
now i have to vmware-configure.pl to do the initial configuration
now 1st step it askes for agreeing for a " License Agreement"
for that i have to say "q" and "yes" to Accept it
i want to run a script with does these 3 steps... (6 Replies)
Discussion started by: pbsrinivas
6 Replies
5. UNIX for Dummies Questions & Answers
I want to know whicj process send the signal SIGCHLD to the parent's child.
Thank you in advance, (1 Reply)
Discussion started by: Puntino
1 Replies
6. Programming
Hello,
I'd like to know whether it is possible to let the parent know who kills its child process. The case is likely as below:
if there are four processes, we call them A, B, C and D. B is the child of A, and can be killed by both C and D. if B is killed, then A will receive SIGCHLD from B.... (7 Replies)
Discussion started by: aaronwong
7 Replies
7. Shell Programming and Scripting
Hi,
The following test case populate an array named: array3.
Since array1 and array2 are equal in length and values array3 will remain empty.
#!/usr/bin/ksh
test() {
set -A array1 "A"
set -A array2 "A"
NUM_1=`echo ${#array1}`
print "num elenemt in NUM_1 is ${NUM_1}"
i=1
for ELE2 in... (1 Reply)
Discussion started by: yoavbe
1 Replies
8. Programming
Hi. I have a program whose job it is to manage 15 child processes. Sometimes these children die (sometimes deliberately other times with a SEGV). This causes a SIGCHLD to be sent to my program which uses waitpid() in the signal handler to gather information and, in most cases, restart the child.... (3 Replies)
Discussion started by: jrichemont
3 Replies
9. UNIX for Dummies Questions & Answers
I'm testing out how to use SIGCHLD and I had a question about intercepting the signal and executing an action in the signal handler.
signal(SIGCHLD,countdown);
What I'm trying to achieve is be able to printf(Hello) every second that child is set to sleep.
I'm setting sleep = 3;
so... (1 Reply)
Discussion started by: l flipboi l
1 Replies
LEARN ABOUT HPUX
pthread_exit
pthread_exit(3T) pthread_exit(3T)
NAME
pthread_exit() - cause the calling thread to terminate
SYNOPSIS
PARAMETERS
value_ptr The calling thread's exit status.
DESCRIPTION
terminates the calling thread. The calling thread returns an exit status in value_ptr. This value is returned to a joining thread calling
on the terminating thread. Only threads created with the detachstate attribute value can return an exit status to The exit status of a
detached thread is lost when the thread terminates.
When a thread terminates, process-shared resources are not released. Examples of process-shared resources include mutexes, condition vari-
ables, semaphores, message queue descriptors, and file descriptors. The routines are not called when a thread terminates as this is a
process termination action.
An implicit call to is made when a thread returns from its start routine. The function's return value serves as the thread's exit status
(see pthread_create(3T)). If the main thread returns from without calling the process will exit using the return value from as the exit
status. If the main thread calls the process will continue executing until the last thread terminates or a thread calls After the last
thread in the process terminates, the process will exit with an exit status of zero.
Any installed cancellation cleanup handlers will be popped and executed in the reverse order that they were installed. After the cancella-
tion cleanup handlers have been executed, if the thread has any non-NULL thread-specific data values with associated destructor functions,
the destructor functions are called. The order in which these destructor functions are called is unspecified.
Calling from a cancellation cleanup handler or destructor function that was invoked because of thread termination results in undefined
behavior.
After a thread has terminated, the result of access to local (auto) variables of the thread is undefined. The terminating thread should
not use local variables for the value_ptr parameter value.
RETURN VALUE
None.
ERRORS
None, this function does not return.
AUTHOR
was derived from the IEEE POSIX P1003.1c standard.
SEE ALSO
pthread_create(3T), pthread_join(3T), exit(2), wait(2).
STANDARDS CONFORMANCE
Pthread Library pthread_exit(3T)