1. fork
#include <unistd.h>
pid_t fork(void);
子进程复制父进程的0到3g空间和父进程内核中的PCB,但id号不同。 fork调用一次返回两次
- 父进程中返回子进程ID
- 子进程中返回0
- 读时共享,写时复制
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
pid_t pid;
char *message;
int n;
pid = fork();
if (pid < 0) {
perror("fork failed");
exit(1);
}
if (pid == 0) {
message = "This is the child\n";
n = 6;
} else {
message = "This is the parent\n";
n = 3;
}
for(; n > 0; n--) {
printf(message);
sleep(1);
}
return 0;
}
![![[Android C++系列:Linux进程(二).png]]](https://i-blog.csdnimg.cn/direct/3070c437c6554358a299e2f970ec562a.png)
1.1 进程相关函数
#include <sys/types.h> #include <uni











![[Java]Swing版坦克大战小游戏项目开发(1)——new出一个窗口](https://img-blog.csdnimg.cn/img_convert/0f3f5fedebb7e3efe70e426b97aa6e4a.png?x-oss-process=image/watermark,image_bG9nby9jc2RuXzEucG5nP3gtb3NzLXByb2Nlc3M9aW1hZ2UvcmVzaXplLGhfMTU1,g_se,x_0,y_0,t_100)







