Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fork() and PID Question

7 views
Skip to first unread message

Bldahdad

unread,
Feb 20, 2002, 6:05:58 PM2/20/02
to
1) How would I make the first-generation process wait for its child to
complete before exiting?

and

2) How do you make the second-generation process sleep for 100 seconds and
do nothing else?


example of what I am trying to do is

#include <iostream.h>
#include <unistd.h>

int main(int argc, char *argv[]){
int parentPid, kidPid;
cout << "process start pid=" << getpid() << "\n";
parentPid = getpid();
kidPid=fork();
if (kidPid == 0)
cout << " I am the child process - " << getpid() << endl;
else
cout << "I am the parent process - " << getpid() << "\n";
return 0;

Felix von Leitner

unread,
Feb 20, 2002, 6:12:26 PM2/20/02
to
Thus spake Bldahdad (bl...@blasdh.com):

> 1) How would I make the first-generation process wait for its child to
> complete before exiting?

Please solve your trivial homework assignments yourself. At home.

Patrick Schaaf

unread,
Feb 21, 2002, 4:05:34 AM2/21/02
to
Bldahdad <bl...@blasdh.com> writes:

>1) How would I make the first-generation process wait for its child to
>complete before exiting?

Do not transfer large parts of your posessions to the child before
your own death, and care for the education of the child. A well-educated
child will complete, becoming a worthy member of society, before you exit.
Of course, raising kids takes time, so be patient, and good at wait(0).

>2) How do you make the second-generation process sleep for 100 seconds and
>do nothing else?

You will find that a young second-generation child, does that by itself
quite regularly. You will even hear a loud warning sound after the sleep,
a feature not found with the boring, normal sleep(100)!

[X] This was a helpful answer.
[X] You have the right to understand.
[X] But, please, buy and read a good book on programming.
[X] Sorry an Alle fuer Englisch in einer deutschsprachigen Newsgroup...

best regards
Patrick

0 new messages