How do I fork more than one process in unix. There are lot of examples how to fork one child process from the main process. But there are no examples as to how to fork more than one process. Can you please just give me an example of forking two processes. Thank you.
fork more than one process
Started by vibhu, Nov 14 2008 07:59 PM
3 replies to this topic
#1
Posted 14 November 2008 - 07:59 PM
|
|
|
#2
Posted 14 November 2008 - 10:34 PM
Use <pthread.h>.
I copied and pasted this from another forum.
I copied and pasted this from another forum.
#include <stdio.h>
#include <pthread.h>
// The follwing is a GCCE toolchain workaround needed when compiling with GCCE
// and using main() entry point
#ifdef __GCCE__
#include <staticlibinit_gcce.h>
#endif
void *TestFunction(void*)
{
printf("Test function....\n");
return NULL;
}
int CreateThread()
{
pthread_t thread_hdl;
if(pthread_create(&thread_hdl,NULL,TestFunction, NULL) != 0)
{
printf("Thread creation failed \n");
return -1;
}
}
int main(void)
{
CreateThread();
printf("Hello Open C!\n");
return 0;
}
#3
Posted 15 November 2008 - 02:58 PM
That did not help. There is a constraint that I should use fork(). any other answers.
#4
Posted 15 November 2008 - 03:01 PM
Have your child process fork then. Just pass it a counter indicating how many times it should fork.
PARENT (fork 3 times) ->child(2)->grandchild(1)->greatgrandchild(0)
PARENT (fork 3 times) ->child(2)->grandchild(1)->greatgrandchild(0)


Sign In
Create Account

Back to top









