how to tell when jobs are finished
Pedro Díaz Jiménez
pdiaz88 at terra.es
Sat Aug 4 16:21:52 PDT 2001
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Saturday 04 August 2001 20:44, Ron Chen wrote:
> Why don't you try to catch the SIGCHLD?
nicer
>
> When child exits, the parent receives SIGCHLD:
and when the child is stopped. I don't know if that could be an issue here
>
> #include <signal.h>
> #include <sys/types.h>
> #include <sys/wait.h>
>
> int sh(int i) /* signal handler */
> {
> int status;
> pid_t pid;
>
> printf("Hello\t");
> pid = wait(&status);
> printf("pid = %d status = %d\n", pid, (status>>8));
> }
>
>
> main()
> {
> int i;
>
> signal(SIGCHLD, sh); /* install handler */
>
> for (i=0;i<3;i++)
> if (fork()==0)
> { sleep(i);
> exit(i);
> }
>
> for (i=0; i<10;i++) /* parent work on other stuff */
> sleep(10);
> }
>
> The parent (main function) may not call sleep(10), I
> used it as a hack. For you, you should call select to
> listen to the new execution request from the cluster
> master (like qmaster in SGE).
>
> The program will print out the pid and exit status:
> Hello pid = 19443 status = 0
> Hello pid = 19444 status = 1
> Hello pid = 19445 status = 2
>
>
> Just wanted to point out one thing here:
> We are working on the process level. We need more work
> to trace the process tree to make sure that we can get
> the information about the job (which consists of 1
> more more processes). Currently, if the child forks
> another child, we won't be able to know.
>
> -Ron
>
> --- Nicholas Henke <henken at seas.upenn.edu> wrote:
> > Thanks guys for the input--
> > I think the signal handler with a polling mechanism
> > should work
> > very nice.
> >
> > Nic
> >
> > > Hi,
> > >
> > > I agree with Sean about the use of waitpid().
> >
> > About the daemon, well, I think
> >
> > > is not necesary. If I not misunderstood you, what
> >
> > you want to do is execute
> >
> > > a certain number of programs and know when anyone
> >
> > of those programs exited.
> >
> > > Here is my proposal, in the form of a
> >
> > pseudo-shell
> >
> > > 1.read somehow the list of programs to execute
> > > 2. For each program to run, create a child using
> >
> > fork() (the master
> >
> > > creates all the childs)
> > > 3. (optional) you may want to redirect each child
> >
> > output to some file
> >
> > > 4. get from the childs its pid via some IPC
> >
> > mechanism (a pipe will do) and
> >
> > > store the in an array or something (i would use a
> >
> > linked list, or a
> >
> > > search-tree table if you will have lots of pids)
> > > 5. Finally, each child calls exec*() and replaces
> >
> > its memory image with the
> >
> > > program desired - that is - executes the program
> > > 6. Now, you have to know when each of the programs
> >
> > you executed has exited.
> >
> > > For simplicity, lets assume you whant to printf
> >
> > something like "Hey!, PID
> >
> > > XXXX finished!". You can do this in two forms (to
> >
> > mi knowledge):
> > > a) loop until all the programs have exited. You
> >
> > can use waitpid with WNOHANG
> >
> > > to poll each pid. Advantage: Simple.
> >
> > Disadvantage: You can't do other
> >
> > > productive things while waiting
> > > b) Set a signal handler to the alarm signal, and
> >
> > test say each second for
> >
> > > completion of one of the pids in your list. If
> >
> > completion, print message and
> >
> > > remove that pid from the list. Disable signal
> >
> > callback when list is empty,
> >
> > > and re-enable when list has at leat one element.
> >
> > Advantages: You can do other
> >
> > > productive things, like launching more processes.
> >
> > Disadvantages: A little
> >
> > > more complicated. If you use this option, see
> >
> > sigaction(2) and signal(2)
> >
> >
> >
> > _______________________________________________
> > Beowulf mailing list, Beowulf at beowulf.org
> > To change your subscription (digest mode or
> > unsubscribe) visit
>
> http://www.beowulf.org/mailman/listinfo/beowulf
>
>
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with Yahoo! Messenger
> http://phonecard.yahoo.com/
- --
__________________________________________________
/ \
| Pedro Diaz Jimenez |
| |
| pdiaz88 at terra.es pdiaz at acm.asoc.fi.upm.es |
| |
| |
| http://planetcluster.org |
| Clustering & H.P.C. news and documentation |
| |
| There are no stupid questions, but there're a |
| lot of inquisitive idiots |
| Anonymous |
| |
| "I find your lack of faith disturbing." |
| Darth Vader, Star Wars Episode IV |
\__________________________________________________/
- -----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org
mQGiBDqcGZsRBADFIahNPLk8suMlS39m8RqatLgX4dO7PU2F5p1oVv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EYEGBECAAYFAjqcGaoACgkQnu53feEYxlHdVACgjVhU
Y8CKf6MYZgQOR9eIDNvTX0AAn3dwbW1HLxEF5OQKJIsngl0BUlYK
=d4S3
- -----END PGP PUBLIC KEY BLOCK-----
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE7bIOWnu53feEYxlERAifYAJ9so6xJC1TzQRGUJwhucNYsciBhSwCcD53m
g8koEeBw2tvjPKvr4B9ytMU=
=WEcF
-----END PGP SIGNATURE-----
More information about the Beowulf
mailing list