03-25-2004
In other words, the children are doing nothing while waiting for the parent's notification. I agree that you will need a semaphore then, because the order in which signals are handled cannot be enforced in a reliable manner without resorting to changing scheduling policies, which is definitely not justified in this case.
I would probably do this:
Have each child install a signal handler for SIGUSR1, without restarting interrupted system calls. Have a loop calling pause() for the desired number of times the PID shall be written. After the parent has signaled the current child, it goes to sleep on a semaphore. After the child has written its PID to the file, it awakes the parent by incrementing the semaphore and calls pause() again. The parent goes on to signal the next child, and so on. Good luck
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Dear all,
suppose that I start a process (named "father"). "father" starts in turns a process called "child" with an execv call (after a fork). In this way "father" will be notified if "chlid" crashes (SIGCHILD mechanism). The problem is:
if "father" crashes, how can I do to be recreate a... (1 Reply)
Discussion started by: npalmentieri
1 Replies
2. UNIX for Dummies Questions & Answers
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
3. Shell Programming and Scripting
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
4. Programming
Hello,
How many child processes are actually created when running this code ?
#include <signal.h>
#include <stdio.h>
int main () {
int i ;
setpgrp () ;
for (i = 0; i < 10; i++) {
if (fork () == 0) {
if ( i & 1 ) setpgrp () ;
printf ("Child id: %2d, group: %2d\n", getpid(),... (0 Replies)
Discussion started by: green_dot
0 Replies
5. Shell Programming and Scripting
Hello,
How many child processes are actually created when running this code ?
#include <signal.h>
#include <stdio.h>
int main () {
int i ;
setpgrp () ;
for (i = 0; i < 10; i++) {
if (fork () == 0) {
if ( i & 1 ) setpgrp () ;
printf ("Child id: %2d, group: %2d\n",... (1 Reply)
Discussion started by: green_dot
1 Replies
6. UNIX for Advanced & Expert Users
Hi,
Is there a way I can kill all the child processes of a process, given its process id.
Many thanks in advance.
J. (1 Reply)
Discussion started by: superuser84
1 Replies
7. Programming
All,
Ok...so I know I *should* be able to control a process's stdin and stdout from the parent by creating pipes and then dup'ing them in the child. And, this works with all "normal" programs that I've tried. Unfortunately, I want to intercept the stdin/out of the scp application and it seems... (9 Replies)
Discussion started by: DreamWarrior
9 Replies
8. Windows & DOS: Issues & Discussions
I have a .NET application that remotely starts, stops, and gets status of Windows services and scheduled tasks. I would like to add the capability of starting, stopping, and getting status of remote AIX applications also. Based on some preliminary research, one option may be to use 3rd party .NET... (0 Replies)
Discussion started by: auser1
0 Replies
9. Shell Programming and Scripting
I am trying to implement the below using Ksh script on a Lx machine.
There is a file(input_file) with 100K records. For each of these records, certain script(process_rec) needs to be called with the record as input. Sequential processing is time-consuming and parallel processing would eat up... (2 Replies)
Discussion started by: APT_3009
2 Replies
10. Shell Programming and Scripting
is there a universal way of getting the children of a particular process? i'm looking for a solution that works across different OSes...linux, aix, sunos, hpux.
i did a search online and i kept finding answers that were specific to Linux..i.e. pstree.
i want to be able to specify a process... (2 Replies)
Discussion started by: SkySmart
2 Replies
waitid(2) System Calls Manual waitid(2)
NAME
waitid - wait for child process to change state
SYNOPSIS
DESCRIPTION
The function suspends the calling process until one of its children changes state. It records the current state of a child in the structure
pointed to by infop. If a child process changed state prior to the call to returns immediately.
The idtype and id arguments are used to specify which children will wait for.
If idtype is will wait for the child with a process ID equal to (pid_t)pid.
If idtypeis will wait for any child with a process group ID equal to (pid_t)pid.
If idtypeis will wait for any children and id is ignored.
The options argument is used to specify which state changes will wait for. It is formed by OR-ing together one or more of the following
flags:
Wait for processes that have exited.
Status will be returned for any child that has stopped upon receipt
of a signal.
Status will be returned for any child that was stopped and has been
continued.
Return immediately if there are no children to wait for.
Keep the process whose status is returned in
infop in a waitable state. This will not affect the state of the process; the process may be waited for
again after this call completes.
The infop argument must point to a structure. If returns because a child process was found that satisfied the conditions indicated by the
arguments idtype and options, then the structure pointed to by infop will be filled in by the system with the status of the process. The
si_signo member will always be equal to
RETURN VALUE
If returns due to the change of state of one of its children, 0 is returned. Otherwise, -1 is returned and is set to indicate the error.
ERRORS
The function will fail if:
[ECHILD] The calling process has no existing unwaited-for child processes.
[EINTR] The function was interrupted due to the receipt of a signal by the calling process.
[EINVAL] An invalid value was specified for options, or idtype and id specify an invalid set of processes.
APPLICATION USAGE
Threads Considerations
In a multi-threaded application, only the calling thread is suspended by
will not return until all threads in the process have reached the desired state. For example, if the or options are specified, will not
return until all threads in the process have terminated, stopped or continued respectively.
SEE ALSO
exec(2), exit(2), wait(2), <sys/wait.h>.
CHANGE HISTORY
First released in Issue 4, Version 2.
waitid(2)