#include <stdio.h>
int scanf(Formatstring, Variablenzeiger1, Variablenzeiger2, ...);
Beispiel
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h> /*fuer pid_t benoetigt*/
int main() {
pid_t retval;
retval = fork();
switch (retval) {
case -1: perror("fork"); exit(EXIT_FAILURE);
case 0: printf("I'm the child.\n"); break;
default: printf("I'm the parent, my child's pid is %d.\n",retval);
}
return 0;
}
/* ... */
retval = fork();
switch (retval) {
case -1: perror("fork"); exit(EXIT_FAILURE);
case 0: printf("I'm the child.\n"); return 42;
default:
{
printf("I'm the parent, my child's pid is %d.\n",retval);
if (waitpid(retval, &status, 0) == -1) {
perror("waitpid");
exit(EXIT_FAILURE);
}
printf("Child exited with %d\n",WEXITSTATUS(status));
if (WEXITSTATUS(status)) {
printf("Child terminated with an error\n");
}
}