
本文共 4363 字,大约阅读时间需要 14 分钟。
���������������������
������������������������������������������������������������������������������Linux������������������������������������������������������������������CPU���������������������������������������������������������������������������������������PCB���������task_struct���������������������������������������������������
���������������������
- ���������������������������������������������������������������������������
- ������������������������������������������������������������������������
- ���������������������������������������������������������������������������������������������
- ������������������task_struct���������������������������������������������������������������������������������������������������������������
task_struct������������
- ���������������������������������ID���
- ������������������������������������������������������������������������������������������
- ������������������������������������������������������
- ���������������������������������������������������������������
- ������������������������������������������������������
- ���������������������������������������������������
- I/O������������������������������I/O������������������������
- ������������������������������������CPU������������������������
������������������������
���������������
������������������������������������������������������������������������������������������������������������������������������������������������������
Linux���������������������user-space���������������������kernel-space������������������������������������mm_struct���������������������������������������������������������������������������
���������������
������������������������������������������������������������������������������������������������
������������������
���Linux������������������������following system API���������������������
- getpid()������������������������������������
- getppid()���������������������������������������
- ps axj | grep <���������>���������������������������������������������
������������
������fork()
������������������������������������fork���������������
- ������������parent������������������PID������������������0���
- parent������������������fork������������������������������
- ���������������������������������������������������������������
- parent���������������������������������������������������������
������������
������������������state���������������������������������������
- R (Running)���������������������������������������������
- S (Sleeping)���������������������������������������������
- D (Deep Sleep)���������������������I/O���������������
- T (Stopped)���������������������������������SIGCONT���������������
- X (Dead)���������������������
- Z (Zombie)������������������������������
������������
���������������������������������������������������������������������������������������������wait���������������������������������������������������������������������������������������������
������������
������������������������������������������������������������������������������������������������init���������PID 1������������������������������������������������������������parent������������init���������
������������������
���������������������������������������������������
#include#include #include int main() { pid_t pid = getpid(); printf("������������������PID: %d\n", pid); pid_t ppid = getppid(); printf("���������������PID: %d\n", ppid); while(1) { sleep(1); } return 0;}
������������������������������������������
ps axj | grep ./.background
������������������������������������������fork()
���������
#include#include #include int main() { int ret = fork(); if (ret < 0) { perror("fork"); return 1; } else if (ret == 0) { printf("���������PID: %d\n", getpid()); sleep(5); } else { printf("������������������PID: %d\n", getpid()); sleep(5); } return 0;}
������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
