create c_pprocess
This commit is contained in:
parent
a4e444f43a
commit
29706fe8be
22
file_operate/create_ps/main.c
Normal file
22
file_operate/create_ps/main.c
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user