test
发布时间 2023-09-27 20:43:22作者: traveller-2333
#include <stdlib.h>
#include <unistd.h>
int main(void) {
pid_t pid = fork();
if (pid < 0) {
// 创建子进程失败
fprintf(stderr, "Failed to create child process.\n");
exit(EXIT_FAILURE);
} else if (pid == 0) {
// 子进程
printf("This is the child process.\n");
exit(EXIT_SUCCESS);
} else {
// 父进程
printf("This is the parent process. Child process ID is %d.\n", pid);
}
return 0;
}