Overclock.net - An Overclocking Community - View Single Post - fork script in c++

View Single Post
post #6 of (permalink) Old 12-24-2005, 06:23 PM - Thread Starter
Mental
New to Overclock.net
 
Join Date: Feb 2005
Posts: 1,555
Rep: 67 (Unique: 55)
when i try to compile this script

Code:
#include <sys/types.h>
#include <unistd.h>

pid_t fork(void);

pid_t pid;

switch (pid = fork())
{
case -1:
    /* Here pid is -1, the fork failed */
    /* Some possible reasons are that you're */
    /* out of process slots or virtual memory */
    perror("The fork failed!");
    break;

case 0:
    /* pid of zero is the child */
    /* Here we're the child...what should we do? */
    /* ... */
    /* but after doing it, we should do something like: */
    _exit(0);

default:
    /* pid greater than zero is parent getting the child's pid */
    printf("Child's pid is %d\
",pid);
}
i get an error in line 8 about the switch command. any ideas?

Mental is offline