Kumar |
08-20-2004 04:53 AM |
Hi,
This is one way I could think of -
Code:
#include <stdio.h>
#include <pthread.h>
#include <stdio.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
pid_t pid;
pthread_t t1, t2;
void *
workthread (void *arg)
{
pid = fork ();
if (pid == 0)
{
fprintf (stderr, "\nchild pid : %d and it's parent is %d\n", getpid (),
getppid ());
sleep (5);
}
}
int
main ()
{
int i = 0;
for (i = 0; i < 5; ++i)
{
pthread_create (&t2, NULL, &workthread, NULL);
}
for (i = 0; i < 5; ++i)
{
pid = wait (NULL);
fprintf (stderr, "\nchild %d terminated", pid);
}
return 0;
}
The code can be changed a bit if you want every child to perform different functions.
|