create c_pprocess

This commit is contained in:
MAO Dongyang 2023-03-15 10:23:06 +01:00
parent a4e444f43a
commit 29706fe8be
No known key found for this signature in database

View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
pid_t fpid;
fpid = fork();
// create child process
if (fpid < 0) {
printf("error in fork!");
} else if (fpid == 0) {
printf("I am the child process, my process id is %d\n", getpid());
sleep(10);
} else {
printf("I am the parent process, my process id is %d\n", getpid());
wait(NULL);
// exit(0);
}
return 0;
}