2012年1月11日 星期三

Forking

{{{

#include
void main(void) {
int pid, i;

pid = fork();

/*Child process the pid is zero at this */
if (pid ==0) {
printf("I am child and pid %d\n",getpid());
for (i=0; i < 44; i++) {
printf("I am chid and say %d\n", i);
}
}
else if (pid > 0) { /* Parent pid will use choild*/
printf("I am parent and pid %d\n",getpid());
for (i = 0; i < 40; i++) {
printf("I am parent process and say %d\n", i);
}
}
else if (pid < 0) {
printf ("Sorry, can't fork my self\n");
}
}


}}}

Reference:
http://forum.slime.com.tw/thread190607.html

沒有留言:

張貼留言