I'm trying to run my first "process" program, but I get the following error :
./fork.c: line 4: syntax error near unexpected token `('
./fork.c: line 4: `int main()'
I'm pretty sure that the code is correct:
#include <sys/types.h>
#include <stdio.h>
int main() {
pid_t pid;
printf("Hello fork()\n");
switch(pid=fork()) {
case -1: printf("Error by fork().....\n"); exit(0);
case 0: printf("I'm the child process \n"); break;
default: printf("I'm the dad \n"); break;
}
exit(0);
}
What is wrong?
_exit
? What's wrong with doing any cleanup that's been registered?fork()
works includes learning that it can copy buffered output. Being a reasonably complicated system call, some confusion is probably necessary in the learning process.