提交 79e93a8c 编写于 作者: H hypox64

uint3

上级 730507fc
# Linux修改时区的正确方法
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# centOS 7 gcc install
yum install gcc -y
# 编译和运行HelloWorld
gcc HelloWorld.c -o HelloWorld-getchar
HelloWorld-getchar
# Linux修改时区的正确方法
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# centOS 7 gcc install
yum install gcc -y
# 编译和运行HelloWorld
gcc HelloWorld.c -o HelloWorld-getchar
HelloWorld-getchar
#include <stdio.h>
int main()
{
printf("HelloWorld!\n");
getchar();
return 0;
#include <stdio.h>
int main()
{
printf("HelloWorld!\n");
getchar();
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <unistd.h>
//1_topology_1───10*[1_topology_1]
int main(int argc, char ** argv )
{
int i = 0;
for (i = 0; i < 10; ++i)
{
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process %d!\n",i);
getchar();
}
}
{
printf("This is the parent process!");
getchar();
wait(NULL);
}
return 0;
#include <stdio.h>
#include <unistd.h>
//1_topology_1───10*[1_topology_1]
int main(int argc, char ** argv )
{
int i = 0;
for (i = 0; i < 10; ++i)
{
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process %d!\n",i);
getchar();
}
}
{
printf("This is the parent process!");
getchar();
wait(NULL);
}
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <unistd.h>
//1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2
void recursive_fork(num)
{
num--;
if (num != -1)
{
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process %d!\n",num);
recursive_fork(num);
getchar();
}
}
}
int main(int argc, char ** argv )
{
int i = 0;
recursive_fork(10);
{
printf("This is the parent process!\n");
getchar();
wait(NULL);
}
return 0;
#include <stdio.h>
#include <unistd.h>
//1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2───1_topology_2
void recursive_fork(num)
{
num--;
if (num != -1)
{
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process %d!\n",num);
recursive_fork(num);
getchar();
}
}
}
int main(int argc, char ** argv )
{
int i = 0;
recursive_fork(10);
{
printf("This is the parent process!\n");
getchar();
wait(NULL);
}
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <unistd.h>
/*
| | `-1_topology_3
| | |-1_topology_3
| | | |-1_topology_3
| | | | |-1_topology_3
| | | | `-1_topology_3
| | | `-1_topology_3
| | | |-1_topology_3
| | | `-1_topology_3
| | `-1_topology_3
| | |-1_topology_3
| | | |-1_topology_3
| | | `-1_topology_3
| | `-1_topology_3
| | |-1_topology_3
| | `-1_topology_3
| | |-grep --color=auto 1_topology_3
*/
void btree_fork(num)
{
num--;
if (num != -1)
{
int j = 0;
for (j = 0; j < 2; ++j)
{
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process %d_%d\n",j);
btree_fork(num);
getchar();
}
}
}
}
int main(int argc, char ** argv )
{
int i = 0;
btree_fork(3);
{
printf("This is the parent process!\n");
getchar();
wait(NULL);
}
return 0;
#include <stdio.h>
#include <unistd.h>
/*
| | `-1_topology_3
| | |-1_topology_3
| | | |-1_topology_3
| | | | |-1_topology_3
| | | | `-1_topology_3
| | | `-1_topology_3
| | | |-1_topology_3
| | | `-1_topology_3
| | `-1_topology_3
| | |-1_topology_3
| | | |-1_topology_3
| | | `-1_topology_3
| | `-1_topology_3
| | |-1_topology_3
| | `-1_topology_3
| | |-grep --color=auto 1_topology_3
*/
void btree_fork(num)
{
num--;
if (num != -1)
{
int j = 0;
for (j = 0; j < 2; ++j)
{
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process %d_%d\n",j);
btree_fork(num);
getchar();
}
}
}
}
int main(int argc, char ** argv )
{
int i = 0;
btree_fork(3);
{
printf("This is the parent process!\n");
getchar();
wait(NULL);
}
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <execinfo.h>
#include <unistd.h>
void my_backtrace()
{
void *buffer[100] = { NULL };
char **trace = NULL;
int size = backtrace(buffer, 100);
trace = backtrace_symbols(buffer, size);
if (NULL == trace) {
return;
}
for (int i = 0; i < size; ++i) {
printf("%s\n", trace[i]);
}
free(trace);
printf("----------done----------\n");
}
void thread(void)
{
// int i = 0;
my_backtrace();
printf("This is a pthread");
sleep(10);
}
int main(void)
{
pthread_t id[3];
int i,ret;
for(i=0;i<3;i++)
{
ret=pthread_create(&id[i],NULL,(void *) thread,NULL);
if(ret!=0)
{
// printf ("Create pthread error!\n");
exit (1);
}
}
// printf("This is the main process.");
my_backtrace();
for(i=0;i<10;i++)
{
pthread_join(id[i],NULL);
}
return (0);
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <execinfo.h>
#include <unistd.h>
void my_backtrace()
{
void *buffer[100] = { NULL };
char **trace = NULL;
int size = backtrace(buffer, 100);
trace = backtrace_symbols(buffer, size);
if (NULL == trace) {
return;
}
for (int i = 0; i < size; ++i) {
printf("%s\n", trace[i]);
}
free(trace);
printf("----------done----------\n");
}
void thread(void)
{
// int i = 0;
my_backtrace();
printf("This is a pthread");
sleep(10);
}
int main(void)
{
pthread_t id[3];
int i,ret;
for(i=0;i<3;i++)
{
ret=pthread_create(&id[i],NULL,(void *) thread,NULL);
if(ret!=0)
{
// printf ("Create pthread error!\n");
exit (1);
}
}
// printf("This is the main process.");
my_backtrace();
for(i=0;i<10;i++)
{
pthread_join(id[i],NULL);
}
return (0);
}
\ No newline at end of file
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define SH_TOK_BUFSIZE 64
#define SH_TOK_DELIM " \t\r\n\a"
char *shell_read_line();
char **shell_split_line(char * line);
int shell_execute(char **args);
void shell_loop(void){
char *line;
char **args;
int size;
while(1){
printf(">>");
line = shell_read_line();
args = shell_split_line(line);
shell_execute(args);
free(line);
free(args);
}
}
char *shell_read_line(){
char *line = NULL;
ssize_t bufsize = 0; // getline()function will help us allocate a buffer
getline(&line,&bufsize,stdin);
return line;
}
char **shell_split_line(char *line){
int bufsize = SH_TOK_BUFSIZE;
int position = 0;
char **tokens = malloc(bufsize * sizeof(char*));
char **token;
if(!tokens){
fprintf(stderr,"allocation error!\n");
exit(EXIT_FAILURE);
}
token = strtok(line,SH_TOK_DELIM);
while(token != NULL){
tokens[position] = token;
position++;
if(position >= bufsize){
bufsize += SH_TOK_BUFSIZE;
tokens = realloc(tokens,bufsize * sizeof(char*));
if(!tokens){
fprintf(stderr,"allocation error!\n");
exit(EXIT_FAILURE);
}
}
token = strtok(NULL,SH_TOK_DELIM);
}
tokens[position] = NULL;
return tokens;
}
// char *shell_read_line(){
// static char buff[1024];
// //scanf("%s", buff);
// fgets(buff, sizeof(buff), stdin);
// // printf("stren buff[%ld]\n", strlen(buff));
// buff[strlen(buff)-1] = '\0';
// return buff;
// }
int shell(char **args){
pid_t pid,wpid;
int status;
pid = fork();
if(pid == -1 )
{
printf("error!\n");
}
else if( pid ==0 )
{
if(execvp(args[0],args) == -1){
perror("shell");
}
exit(EXIT_FAILURE);
// execvp(args[0],args);
}
do {
wpid = waitpid(pid,&status,WUNTRACED);
}while (!WIFEXITED(status) && !WIFSIGNALED(status));
return 1;
}
int shell_execute(char **args)
{
// printf("%s\n",args[0] );
if (strcmp(args[0], "help") == 0){
printf("%s\n","This is a smaple shell build by C @Hypo");
}
else if(strcmp(args[0], "exit") == 0){
exit(0);
}
else if(strcmp(args[0], "cd") == 0){
printf("%s\n","No such command!" );
}
else{
shell(args);
}
}
int main(int argc, char **argv[])
{
shell_loop();
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define SH_TOK_BUFSIZE 64
#define SH_TOK_DELIM " \t\r\n\a"
char *shell_read_line();
char **shell_split_line(char * line);
int shell_execute(char **args);
void shell_loop(void){
char *line;
char **args;
int size;
while(1){
printf(">>");
line = shell_read_line();
args = shell_split_line(line);
shell_execute(args);
free(line);
free(args);
}
}
char *shell_read_line(){
char *line = NULL;
ssize_t bufsize = 0; // getline()function will help us allocate a buffer
getline(&line,&bufsize,stdin);
return line;
}
char **shell_split_line(char *line){
int bufsize = SH_TOK_BUFSIZE;
int position = 0;
char **tokens = malloc(bufsize * sizeof(char*));
char **token;
if(!tokens){
fprintf(stderr,"allocation error!\n");
exit(EXIT_FAILURE);
}
token = strtok(line,SH_TOK_DELIM);
while(token != NULL){
tokens[position] = token;
position++;
if(position >= bufsize){
bufsize += SH_TOK_BUFSIZE;
tokens = realloc(tokens,bufsize * sizeof(char*));
if(!tokens){
fprintf(stderr,"allocation error!\n");
exit(EXIT_FAILURE);
}
}
token = strtok(NULL,SH_TOK_DELIM);
}
tokens[position] = NULL;
return tokens;
}
// char *shell_read_line(){
// static char buff[1024];
// //scanf("%s", buff);
// fgets(buff, sizeof(buff), stdin);
// // printf("stren buff[%ld]\n", strlen(buff));
// buff[strlen(buff)-1] = '\0';
// return buff;
// }
int shell(char **args){
pid_t pid,wpid;
int status;
pid = fork();
if(pid == -1 )
{
printf("error!\n");
}
else if( pid ==0 )
{
if(execvp(args[0],args) == -1){
perror("shell");
}
exit(EXIT_FAILURE);
// execvp(args[0],args);
}
do {
wpid = waitpid(pid,&status,WUNTRACED);
}while (!WIFEXITED(status) && !WIFSIGNALED(status));
return 1;
}
int shell_execute(char **args)
{
// printf("%s\n",args[0] );
if (strcmp(args[0], "help") == 0){
printf("%s\n","This is a smaple shell build by C @Hypo");
}
else if(strcmp(args[0], "exit") == 0){
exit(0);
}
else if(strcmp(args[0], "cd") == 0){
printf("%s\n","No such command!" );
}
else{
shell(args);
}
}
int main(int argc, char **argv[])
{
shell_loop();
}
\ No newline at end of file
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
// int **addOne(int a[M][N]){
// int **b =(int **)malloc(M*sizeof(int *));
char **split(char **args, schar *str, char key){
// char **args = malloc(10 * sizeof(char*));
args[0] = "sef";
return args;
// static char args[10][64];
// int part = 0;
// int flag = 0;
// int i = 0;
// while(str[i] != '\0'){
// if (str[i] == key){
// int j;
// for (j = 0; j < (i-flag); ++j){
// args[part][j] = str[i];
// }
// args[part][i-flag]='\0';
// part++;
// flag = i;
// }
// // printf("%d\n",i );
// // printf("%c\n",str[i]);
// i++;
// }
// printf("%c\n",args[0][0] );
// return args;
}
int main(void)
{
char *str = "abc a";
char args[10][64];
// printf("%s\n",str );
char a[10][64] = split(args,str,'a');
// char **args = malloc(64 * sizeof(char*));
// args[0] = str;
// printf("%c\n",args[0][0] );
// int i = 0;
// while(str[i] != '\0'){
// printf("%c\n",str[i]);
// i++;
// }
// char* str2 = "abc";
// char *args[10];
// args[0] = str1;
// printf("%s\n", args[0]);
// if (args[3]=="/0")
// {
// printf("%s\n","true" );
// /* code */
// }
return 0;
}
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
// int **addOne(int a[M][N]){
// int **b =(int **)malloc(M*sizeof(int *));
char **split(char **args, schar *str, char key){
// char **args = malloc(10 * sizeof(char*));
args[0] = "sef";
return args;
// static char args[10][64];
// int part = 0;
// int flag = 0;
// int i = 0;
// while(str[i] != '\0'){
// if (str[i] == key){
// int j;
// for (j = 0; j < (i-flag); ++j){
// args[part][j] = str[i];
// }
// args[part][i-flag]='\0';
// part++;
// flag = i;
// }
// // printf("%d\n",i );
// // printf("%c\n",str[i]);
// i++;
// }
// printf("%c\n",args[0][0] );
// return args;
}
int main(void)
{
char *str = "abc a";
char args[10][64];
// printf("%s\n",str );
char a[10][64] = split(args,str,'a');
// char **args = malloc(64 * sizeof(char*));
// args[0] = str;
// printf("%c\n",args[0][0] );
// int i = 0;
// while(str[i] != '\0'){
// printf("%c\n",str[i]);
// i++;
// }
// char* str2 = "abc";
// char *args[10];
// args[0] = str1;
// printf("%s\n", args[0]);
// if (args[3]=="/0")
// {
// printf("%s\n","true" );
// /* code */
// }
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//返回一个 char *arr[], size为返回数组的长度
char **split(char sep, const char *str, int *size)
{
int count = 0, i;
for(i = 0; i < strlen(str); i++)
{
if (str[i] == sep)
{
count ++;
}
}
char **ret = calloc(++count, sizeof(char *));
if (count == 0) {
ret[0] = calloc(strlen(str), sizeof(char)); //分配子串长度+1的内存空间
memcpy(ret[0], str, strlen(str) - 1);
return ret;
}
int lastindex = -1;
int j = 0;
for(i = 0; i < strlen(str); i++)
{
if (str[i] == sep)
{
ret[j] = calloc(i - lastindex, sizeof(char)); //分配子串长度+1的内存空间
memcpy(ret[j], str + lastindex + 1, i - lastindex - 1);
j++;
lastindex = i;
}
}
//处理最后一个子串
if (lastindex <= strlen(str) - 1)
{
ret[j] = calloc(strlen(str) - lastindex, sizeof(char));
memcpy(ret[j], str + lastindex + 1, strlen(str) - 1 - lastindex);
j++;
}
*size = j;
return ret;
}
void test(){
int size;
char **args;
char *str = "aaabbb";
args = split(',',str, &size);
printf("%s\n",args[0] );
}
int main()
{ int i =0;
for (i = 0; i < 10; ++i)
{
test();
}
// int i;
// for(i = 0; i < size; i++)
// {
// printf("%s\n", ret[i]);
// free(ret[i]);
// }
// free(ret);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//返回一个 char *arr[], size为返回数组的长度
char **split(char sep, const char *str, int *size)
{
int count = 0, i;
for(i = 0; i < strlen(str); i++)
{
if (str[i] == sep)
{
count ++;
}
}
char **ret = calloc(++count, sizeof(char *));
if (count == 0) {
ret[0] = calloc(strlen(str), sizeof(char)); //分配子串长度+1的内存空间
memcpy(ret[0], str, strlen(str) - 1);
return ret;
}
int lastindex = -1;
int j = 0;
for(i = 0; i < strlen(str); i++)
{
if (str[i] == sep)
{
ret[j] = calloc(i - lastindex, sizeof(char)); //分配子串长度+1的内存空间
memcpy(ret[j], str + lastindex + 1, i - lastindex - 1);
j++;
lastindex = i;
}
}
//处理最后一个子串
if (lastindex <= strlen(str) - 1)
{
ret[j] = calloc(strlen(str) - lastindex, sizeof(char));
memcpy(ret[j], str + lastindex + 1, strlen(str) - 1 - lastindex);
j++;
}
*size = j;
return ret;
}
void test(){
int size;
char **args;
char *str = "aaabbb";
args = split(',',str, &size);
printf("%s\n",args[0] );
}
int main()
{ int i =0;
for (i = 0; i < 10; ++i)
{
test();
}
// int i;
// for(i = 0; i < size; i++)
// {
// printf("%s\n", ret[i]);
// free(ret[i]);
// }
// free(ret);
return 0;
}
# 实验记录
### 2-1 察看HelloWorld-gechar 的三个进程<br>
```bash
ps -aux | grep HelloWorld
```
3个进程的PID分别是26608 26649 26689<br>
![image](./record/pic/2-1.jpg)
### 2-2 屏显 HelloWorld 可执行文件信息<br>
```bash
file HelloWorld
```
![image](./record/pic/2-2.png)
x86-64 平台上的ELF 格式可执行文件。
一种用于二进制文件、可执行文件、目标代码、共享库和核心转储格式文件。
ELF文件由4部分组成,分别是ELF头(ELF header)、程序头表(Program header table)、节(Section)和节头表(Section header table)。
由于ELF 文件内部包含了足够的信息,操作系统可以根据ELF 可执行文件创建出进程映像,进程映像以及各种管理数据结构构成了进程实体,另外进程还可能向系统申请各种资源——共同组成了进程实体的全部内涵。进程实体被调度运行就构成了进程的活动,如果系统中有多个活动的进程,那么它们各自有独立的进程空间(各自独立地使用自己的0~0xFFFFFFFF 虚存空间)。<br>
在Linux 中进程PCB 是task_struct 结构体,<br>
### 进程间组织关系<br>
Linux 系统中所有进程通过进程控制块PCB(struct task_struct)形成多种组织关系。根据
进程创建过程可以有亲缘关系,通过进程间的父子关系组织成一个进程树<br>
一个进程通过创建一个子进程则形成父子关系,如果创建多个子进程,那么这些新创建的
进程间属于兄弟关系<br>
### 2-3 pstree 输出
![image](./record/pic/2-3.png)
### 2-4 查看会话、进程组和控制终端的例子
![image](./record/pic/2-4.png)
### PPID(PPID,Parent PID) PID(进程ID) PGID(Process Group ID 进程组 ID号) SID(Session ID 会话ID) TTY TPGID(tty process group ID for the process group leader) STAT() UID TIME COMMAND<br>
STAT:D 无法中断的休眠状态(通常 IO 的进程);R 正在运行可中在队列中可过行的;S 处于休眠状态;T 停止或被追踪;W 进入内存交换(从内核2.6开始无效);X 死掉的进程(从来没见过);Z 僵尸进程;+ 位于后台的进程组<br>
“会话/进程组/线程组”几个概念呈现层级关系,Linux 系统中可以有多个会话(session),
每个会话可以包含多个进程组(process group),每个进程组可以包含多个进程,每个进程构
成一个线程组——一个线程组由一个进程内的一个或多个线程组成,这些对象都有各自的ID。会话是从用户登录系统到退出前的全部活动,不同帐户的登录属于不同会话,而同一帐户的多次登录也构成不同的会话。而进程组主要出于作业控制的目的,有些shell 没有作用控制能力,就将整个会话的所有进程构成一个进程组。
### 2-5 创建进程的命令
```bash
chmod a+x shell-script
shell-script
```
![image](./record/pic/2-5.png)
第一行用于指出该脚本需要用/usr/bin/bash 来解
释执行,第二行shell 内部命令echo 用来显示,第三行HelloWorld 是外部命令(磁盘上的可执
行文件)。
### 2-6 通过ps 查找进程的PID
1.查找进程的PID<br>
2.kill PID <br>
```bash
ps -ef | grep HelloWorld-getchar
```
![image](./record/pic/2-6.png)
### 2-7 fork-demo 的输出
![image](./record/pic/2-7.png)
fork 函数被成功调用后将按照父进程的样子复制出一个完全相同的子进程。父进程fork()
函数结束时的返回值是子进程的PID 编号。新创建的子进程则也是从fork()返回处开始执行,
但不同的是它获得的返回值是0。也就是说父子进程执行上几乎相同,<br>
* 唯一区别是子进程中返回0 值而父进程中返回子进程PID。<br>
* 如果fork()出错则只有父进程获得返回值-1 而子进程未能创建。<br>
### 2-8 fork-demo 的输出
![image](./record/pic/2-8.png)
### 2-9 fork-twice-demo 执行后的 输出
![image](./record/pic/2-9.png)
### 孤儿进程和僵尸进程
(1) 孤儿进程:一个父进程退出,而它的一个或多个子进程还在运行,那么那些子进程将成为孤儿进程。孤儿进程将被init 进程(进程号为1)所收养,并由init 进程对它们完成状态收集工作。
(2) 僵尸进程:一个子进程在其父进程还没有调用wait()或waitpid()的情况下退出。这个子进程就是僵尸进程。
子进程结束后大部分资源都将直接回收,但是还将在PCB(struct task_struct 和内核堆栈)中记录一些退出时的状态等信息,这些信息供父进程检查后才能销毁回收。因此,僵尸进程因相应的数据没有父进程处理并回收,将会导致资源浪费,而孤儿则不会有这样的问题。
* 孤儿进程
![image](./record/pic/孤儿进程.png)
* 僵尸进程
![image](./record/pic/僵尸进程.png)
### 2-10 fork-exec-demo 的执行结果
![image](./record/pic/2-10.png)
* 这里可以看到子进程通过execve()将自己变身为“/usr/bin/ls”,因此不再执行与父进程里的代——即后面的“printf("this printf()will not be executed, because …”是没有机会得到执行的。
* fork()和exec 函数族构成了创建新进程的完整操作,如果父子进程功能相同则只用fork(),如果父子进程不同则利用exec 函数族的来实现。
### 2-11 用ps –ajx 查看daemon-demo 守护进程
![image](./record/pic/2-11.png)
关闭daemon-demo运行终端后仍能找到daemon-demo进程,且PID为1
### 2-12 /etc/rsyslog.conf 中的内容
![image](./record/pic/2-12.png)
日志信息写入了/var/log/messages 文件中。
### 2-13 查看/var/log/messages
![image](./record/pic/2-13.png)
由于前后运行了多次,所以出现了3个。
### 2-14&2-15 pthread-demo 的输出及ps –aLf 的输出
![image](./record/pic/2-14&2-15.png)
两个线程公用一个PID号19392,但是LWP却不一样。
### 2-16&2-17 PCB 开销
```bash
cat /proc/slabinfo | grep task_struct
```
比较两者在进程控制块上的开销(包括 struct task_struct 和内核栈)
2-16 fork-100-demo 运行前后的/proc/slabinfo 中关于 task_struct 数量
![image](./record/pic/2-16.png)
2-17 pthread-100-demo 运行前后的/proc/slabinfo 中关于 task_struct 数量
![image](./record/pic/2-17.png)
两者在运行后的task_struct数量均增加100,说明线程作为调度执行单位,进程控制块PCB(task_struct)还是需要的,这是最小资源的一部分。因此这方面资源开销对进程和线程都是一样的。
### 2-18&2-19&2-20&2-21内存描述符开销
* 查看mm_struct数量
```bash
cat /proc/slabinfo | grep mm_struct
```
2-18 fork-100-demo 运行前后的/proc/slabinfo 中关于 mm_struct 数量
![image](./record/pic/2-18.png)
2-19 pthread-100-demo 运行前后的/proc/slabinfo 中关于 mm_struct 数量
![image](./record/pic/2-19.png)
前者运行时mm_struct数量增加了100,而后者没有变化,说明,pthread-100-demo 虽然创建了 100 个线程,但是用于共享进程空间,并没有增加一个 mm_struct
* 查看vm_area_struct数量
```bash
cat /proc/slabinfo | grep vm_area_struct
```
2-20 fork-100-demo 运行前后的/proc/slabinfo 中关于 vm_area_struct 数量
![image](./record/pic/2-20.png)
2-21 pthread-100-demo 运行前后的/proc/slabinfo 中关于 vm_area_struct 数量
![image](./record/pic/2-21.png)
可以发现pthread-100-demo需要新增大约 150 左右的使用量,而fork-100-demo需要约 1300 左右的使用量,故线程的开销确实比进程要小。
# 课后作业
### 1.编写 C 语言程序,利用 fork()创建子进程,形成以下父子关系:并通过 ps 命令检查进程的进程号 PID 和父进程号 PPID 证明你成功创建相应的父子关系,同时也用 pstree 输出进程树结构来验证其关系。
![image](./homework/pic/problem_1.png)
* 解答:
* (1).[code](./homework/code/1_topology_1.c)
![image](./homework/pic/1_topology_1.png)
可以看到父进程12232拥有10个子进程且满足题目的要求
* (2).[code](./homework/code/1_topology_2.c)
![image](./homework/pic/1_topology_2.png)
可以看到父进程13738拥有10个子进程且满足题目的要求
* (3).[code](./homework/code/1_topology_3.c)
![image](./homework/pic/1_topology_3.png)
可以看子进程结构满足题目要求。
### 3.创建多个线程,在各个线程中打印出堆栈变量的地址,大致标记出其位置,注意区分主线程的堆栈和其他线程堆栈位置的差异。
* 解答:[code](./homework/code/3_pthread.c)
注意:编译时需要链接文件-lpthread -rdynamic
```bash
gcc ./3_pthread.c -lpthread -rdynamic -o 3_pthread
```
![image](./homework/pic/3_pthread.png)
程序中有一个父线程以及3个子线程,可以发现子线程的偏移地址以及返回地址都是一样的,且斗与父线程不一样。
### 4.尝试自行设计一个 C 语言小程序,完成最基本的 shell 角色:给出命令行提示符、能够接受命令;对于命令分成三种,内部命令(例如 help 命令、exit 命令等)、外部命令(常见的 ls、cp 等,以及其他磁盘上的可执行程序 HelloWrold 等)以及无效命令(不是上述两种命令)。
* 解答:[code](./homework/code/shell.c)
![image](./homework/pic/4_shell.png)
捕获键盘输入->判断是那种命令->
* 1.内部命令:打印help文件或exit(0);退出<br>
* 2.外部命令,fork出新的进程并使用execvp函数执行
* 3.可执行程序,与外部命令方法相同
* 4.无效命令:打印无效警告
# 实验记录
### 2-1 察看HelloWorld-gechar 的三个进程<br>
```bash
ps -aux | grep HelloWorld
```
3个进程的PID分别是26608 26649 26689<br>
![image](./record/pic/2-1.jpg)
### 2-2 屏显 HelloWorld 可执行文件信息<br>
```bash
file HelloWorld
```
![image](./record/pic/2-2.png)
x86-64 平台上的ELF 格式可执行文件。
一种用于二进制文件、可执行文件、目标代码、共享库和核心转储格式文件。
ELF文件由4部分组成,分别是ELF头(ELF header)、程序头表(Program header table)、节(Section)和节头表(Section header table)。
由于ELF 文件内部包含了足够的信息,操作系统可以根据ELF 可执行文件创建出进程映像,进程映像以及各种管理数据结构构成了进程实体,另外进程还可能向系统申请各种资源——共同组成了进程实体的全部内涵。进程实体被调度运行就构成了进程的活动,如果系统中有多个活动的进程,那么它们各自有独立的进程空间(各自独立地使用自己的0~0xFFFFFFFF 虚存空间)。<br>
在Linux 中进程PCB 是task_struct 结构体,<br>
### 进程间组织关系<br>
Linux 系统中所有进程通过进程控制块PCB(struct task_struct)形成多种组织关系。根据
进程创建过程可以有亲缘关系,通过进程间的父子关系组织成一个进程树<br>
一个进程通过创建一个子进程则形成父子关系,如果创建多个子进程,那么这些新创建的
进程间属于兄弟关系<br>
### 2-3 pstree 输出
![image](./record/pic/2-3.png)
### 2-4 查看会话、进程组和控制终端的例子
![image](./record/pic/2-4.png)
### PPID(PPID,Parent PID) PID(进程ID) PGID(Process Group ID 进程组 ID号) SID(Session ID 会话ID) TTY TPGID(tty process group ID for the process group leader) STAT() UID TIME COMMAND<br>
STAT:D 无法中断的休眠状态(通常 IO 的进程);R 正在运行可中在队列中可过行的;S 处于休眠状态;T 停止或被追踪;W 进入内存交换(从内核2.6开始无效);X 死掉的进程(从来没见过);Z 僵尸进程;+ 位于后台的进程组<br>
“会话/进程组/线程组”几个概念呈现层级关系,Linux 系统中可以有多个会话(session),
每个会话可以包含多个进程组(process group),每个进程组可以包含多个进程,每个进程构
成一个线程组——一个线程组由一个进程内的一个或多个线程组成,这些对象都有各自的ID。会话是从用户登录系统到退出前的全部活动,不同帐户的登录属于不同会话,而同一帐户的多次登录也构成不同的会话。而进程组主要出于作业控制的目的,有些shell 没有作用控制能力,就将整个会话的所有进程构成一个进程组。
### 2-5 创建进程的命令
```bash
chmod a+x shell-script
shell-script
```
![image](./record/pic/2-5.png)
第一行用于指出该脚本需要用/usr/bin/bash 来解
释执行,第二行shell 内部命令echo 用来显示,第三行HelloWorld 是外部命令(磁盘上的可执
行文件)。
### 2-6 通过ps 查找进程的PID
1.查找进程的PID<br>
2.kill PID <br>
```bash
ps -ef | grep HelloWorld-getchar
```
![image](./record/pic/2-6.png)
### 2-7 fork-demo 的输出
![image](./record/pic/2-7.png)
fork 函数被成功调用后将按照父进程的样子复制出一个完全相同的子进程。父进程fork()
函数结束时的返回值是子进程的PID 编号。新创建的子进程则也是从fork()返回处开始执行,
但不同的是它获得的返回值是0。也就是说父子进程执行上几乎相同,<br>
* 唯一区别是子进程中返回0 值而父进程中返回子进程PID。<br>
* 如果fork()出错则只有父进程获得返回值-1 而子进程未能创建。<br>
### 2-8 fork-demo 的输出
![image](./record/pic/2-8.png)
### 2-9 fork-twice-demo 执行后的 输出
![image](./record/pic/2-9.png)
### 孤儿进程和僵尸进程
(1) 孤儿进程:一个父进程退出,而它的一个或多个子进程还在运行,那么那些子进程将成为孤儿进程。孤儿进程将被init 进程(进程号为1)所收养,并由init 进程对它们完成状态收集工作。
(2) 僵尸进程:一个子进程在其父进程还没有调用wait()或waitpid()的情况下退出。这个子进程就是僵尸进程。
子进程结束后大部分资源都将直接回收,但是还将在PCB(struct task_struct 和内核堆栈)中记录一些退出时的状态等信息,这些信息供父进程检查后才能销毁回收。因此,僵尸进程因相应的数据没有父进程处理并回收,将会导致资源浪费,而孤儿则不会有这样的问题。
* 孤儿进程
![image](./record/pic/孤儿进程.png)
* 僵尸进程
![image](./record/pic/僵尸进程.png)
### 2-10 fork-exec-demo 的执行结果
![image](./record/pic/2-10.png)
* 这里可以看到子进程通过execve()将自己变身为“/usr/bin/ls”,因此不再执行与父进程里的代——即后面的“printf("this printf()will not be executed, because …”是没有机会得到执行的。
* fork()和exec 函数族构成了创建新进程的完整操作,如果父子进程功能相同则只用fork(),如果父子进程不同则利用exec 函数族的来实现。
### 2-11 用ps –ajx 查看daemon-demo 守护进程
![image](./record/pic/2-11.png)
关闭daemon-demo运行终端后仍能找到daemon-demo进程,且PID为1
### 2-12 /etc/rsyslog.conf 中的内容
![image](./record/pic/2-12.png)
日志信息写入了/var/log/messages 文件中。
### 2-13 查看/var/log/messages
![image](./record/pic/2-13.png)
由于前后运行了多次,所以出现了3个。
### 2-14&2-15 pthread-demo 的输出及ps –aLf 的输出
![image](./record/pic/2-14&2-15.png)
两个线程公用一个PID号19392,但是LWP却不一样。
### 2-16&2-17 PCB 开销
```bash
cat /proc/slabinfo | grep task_struct
```
比较两者在进程控制块上的开销(包括 struct task_struct 和内核栈)
2-16 fork-100-demo 运行前后的/proc/slabinfo 中关于 task_struct 数量
![image](./record/pic/2-16.png)
2-17 pthread-100-demo 运行前后的/proc/slabinfo 中关于 task_struct 数量
![image](./record/pic/2-17.png)
两者在运行后的task_struct数量均增加100,说明线程作为调度执行单位,进程控制块PCB(task_struct)还是需要的,这是最小资源的一部分。因此这方面资源开销对进程和线程都是一样的。
### 2-18&2-19&2-20&2-21内存描述符开销
* 查看mm_struct数量
```bash
cat /proc/slabinfo | grep mm_struct
```
2-18 fork-100-demo 运行前后的/proc/slabinfo 中关于 mm_struct 数量
![image](./record/pic/2-18.png)
2-19 pthread-100-demo 运行前后的/proc/slabinfo 中关于 mm_struct 数量
![image](./record/pic/2-19.png)
前者运行时mm_struct数量增加了100,而后者没有变化,说明,pthread-100-demo 虽然创建了 100 个线程,但是用于共享进程空间,并没有增加一个 mm_struct
* 查看vm_area_struct数量
```bash
cat /proc/slabinfo | grep vm_area_struct
```
2-20 fork-100-demo 运行前后的/proc/slabinfo 中关于 vm_area_struct 数量
![image](./record/pic/2-20.png)
2-21 pthread-100-demo 运行前后的/proc/slabinfo 中关于 vm_area_struct 数量
![image](./record/pic/2-21.png)
可以发现pthread-100-demo需要新增大约 150 左右的使用量,而fork-100-demo需要约 1300 左右的使用量,故线程的开销确实比进程要小。
# 课后作业
### 1.编写 C 语言程序,利用 fork()创建子进程,形成以下父子关系:并通过 ps 命令检查进程的进程号 PID 和父进程号 PPID 证明你成功创建相应的父子关系,同时也用 pstree 输出进程树结构来验证其关系。
![image](./homework/pic/problem_1.png)
* 解答:
* (1).[code](./homework/code/1_topology_1.c)
![image](./homework/pic/1_topology_1.png)
可以看到父进程12232拥有10个子进程且满足题目的要求
* (2).[code](./homework/code/1_topology_2.c)
![image](./homework/pic/1_topology_2.png)
可以看到父进程13738拥有10个子进程且满足题目的要求
* (3).[code](./homework/code/1_topology_3.c)
![image](./homework/pic/1_topology_3.png)
可以看子进程结构满足题目要求。
### 3.创建多个线程,在各个线程中打印出堆栈变量的地址,大致标记出其位置,注意区分主线程的堆栈和其他线程堆栈位置的差异。
* 解答:[code](./homework/code/3_pthread.c)
注意:编译时需要链接文件-lpthread -rdynamic
```bash
gcc ./3_pthread.c -lpthread -rdynamic -o 3_pthread
```
![image](./homework/pic/3_pthread.png)
程序中有一个父线程以及3个子线程,可以发现子线程的偏移地址以及返回地址都是一样的,且斗与父线程不一样。
### 4.尝试自行设计一个 C 语言小程序,完成最基本的 shell 角色:给出命令行提示符、能够接受命令;对于命令分成三种,内部命令(例如 help 命令、exit 命令等)、外部命令(常见的 ls、cp 等,以及其他磁盘上的可执行程序 HelloWrold 等)以及无效命令(不是上述两种命令)。
* 解答:[code](./homework/code/shell.c)
![image](./homework/pic/4_shell.png)
捕获键盘输入->判断是那种命令->
* 1.内部命令:打印help文件或exit(0);退出<br>
* 2.外部命令,fork出新的进程并使用execvp函数执行
* 3.可执行程序,与外部命令方法相同
* 4.无效命令:打印无效警告
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/syslog.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int init_daemon(void)
{
int pid;
int i;
// 1)忽略一些控制终端发来的信号,信号的内容请参考其他文献
signal(SIGTTOU,SIG_IGN);
signal(SIGTTIN,SIG_IGN);
signal(SIGTSTP,SIG_IGN);
signal(SIGHUP ,SIG_IGN);
// 2)在后台运行
if( pid=fork() )
{ // 父进程
exit(0); //结束父进程,子进程继续
}
else if(pid< 0)
{ // 出错
perror("fork");
exit(EXIT_FAILURE);
}
// 3)脱离控制终端、登录会话和进程组
setsid();
// 4)禁止进程重新打开控制终端
if( pid=fork() )
{ // 父进程
exit(0); // 结束第1 代子进程,第2 代子进程继续(第2 代子进程不再是会话组长)
}
else if(pid< 0)
{ // 出错
perror("fork");
exit(EXIT_FAILURE);
}
// 5)关闭打开的文件描述符
// NOFILE 为文件描述符最大个数,不同系统有不同限制,<sys/param.h> 的宏定义
for(i=0; i< NOFILE; ++i)
{
close(i);
}
// 6)改变当前工作目录
chdir("/tmp");
// 7)重设文件创建掩模
umask(0);
// 8)处理 SIGCHLD 信号
signal(SIGCHLD,SIG_IGN);
// 9) 输出日志
openlog("daemon-demo.log",LOG_PID,0);
syslog(LOG_INFO,"daemon-demo is running ...\n");
return 0;
}
int main(int argc, char *argv[])
{
init_daemon();
while(1);
return 0;
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/syslog.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int init_daemon(void)
{
int pid;
int i;
// 1)忽略一些控制终端发来的信号,信号的内容请参考其他文献
signal(SIGTTOU,SIG_IGN);
signal(SIGTTIN,SIG_IGN);
signal(SIGTSTP,SIG_IGN);
signal(SIGHUP ,SIG_IGN);
// 2)在后台运行
if( pid=fork() )
{ // 父进程
exit(0); //结束父进程,子进程继续
}
else if(pid< 0)
{ // 出错
perror("fork");
exit(EXIT_FAILURE);
}
// 3)脱离控制终端、登录会话和进程组
setsid();
// 4)禁止进程重新打开控制终端
if( pid=fork() )
{ // 父进程
exit(0); // 结束第1 代子进程,第2 代子进程继续(第2 代子进程不再是会话组长)
}
else if(pid< 0)
{ // 出错
perror("fork");
exit(EXIT_FAILURE);
}
// 5)关闭打开的文件描述符
// NOFILE 为文件描述符最大个数,不同系统有不同限制,<sys/param.h> 的宏定义
for(i=0; i< NOFILE; ++i)
{
close(i);
}
// 6)改变当前工作目录
chdir("/tmp");
// 7)重设文件创建掩模
umask(0);
// 8)处理 SIGCHLD 信号
signal(SIGCHLD,SIG_IGN);
// 9) 输出日志
openlog("daemon-demo.log",LOG_PID,0);
syslog(LOG_INFO,"daemon-demo is running ...\n");
return 0;
}
int main(int argc, char *argv[])
{
init_daemon();
while(1);
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv )
{
int i;
for(i=0;i<100;i++)
{
int pid = fork();
if(pid == -1 )
{
printf("error!\n");
}
else if( pid ==0 )
{
printf("This is the child process!\n");
sleep(10);
return 0;
}
else
{
printf("This is the parent process! child process id = %d\n", pid);
}
}
sleep(10);
return 0;
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv )
{
int i;
for(i=0;i<100;i++)
{
int pid = fork();
if(pid == -1 )
{
printf("error!\n");
}
else if( pid ==0 )
{
printf("This is the child process!\n");
sleep(10);
return 0;
}
else
{
printf("This is the parent process! child process id = %d\n", pid);
}
}
sleep(10);
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv )
{
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process!\n");
getchar();
}
else
{
printf("This is the parent process! child process id = %d\n", pid);
getchar();
wait(NULL);
}
return 0;
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv )
{
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process!\n");
getchar();
}
else
{
printf("This is the parent process! child process id = %d\n", pid);
getchar();
wait(NULL);
}
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv )
{
int pid = fork();
if(pid == -1 )
{
printf("error!\n");
}
else if( pid ==0 )
{
printf("This is the child process!\n");
char *argv[ ]={"ls", "-al", "/etc/passwd", NULL};
char *envp[ ]={"PATH=/usr/bin", NULL};
execve("/usr/bin/ls", argv, envp);
printf("this printf() will not be executed,because it will be replaced by /usr/bin/ls code!\n");
}
else
{
printf("This is the parent process! child process id = %d\n", pid);
getchar();
}
return 0;
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv )
{
int pid = fork();
if(pid == -1 )
{
printf("error!\n");
}
else if( pid ==0 )
{
printf("This is the child process!\n");
char *argv[ ]={"ls", "-al", "/etc/passwd", NULL};
char *envp[ ]={"PATH=/usr/bin", NULL};
execve("/usr/bin/ls", argv, envp);
printf("this printf() will not be executed,because it will be replaced by /usr/bin/ls code!\n");
}
else
{
printf("This is the parent process! child process id = %d\n", pid);
getchar();
}
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv )
{
int pid = fork();
if(pid == -1 )
{
printf("error!\n");
}
else if( pid ==0 )
{
printf("This is the child process!\n");
fork();
getchar();
}
else
{
printf("This is the parent process! child process id = %d\n", pid);
fork();
getchar();
}
return 0;
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv )
{
int pid = fork();
if(pid == -1 )
{
printf("error!\n");
}
else if( pid ==0 )
{
printf("This is the child process!\n");
fork();
getchar();
}
else
{
printf("This is the parent process! child process id = %d\n", pid);
fork();
getchar();
}
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv )
{
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process!\n");
getchar();
}
else
{
printf("This is the parent process! child process id = %d\n", pid);
getchar();
// wait(NULL);
}
return 0;
#include <stdio.h>
#include <unistd.h>
int main(int argc, char ** argv )
{
int pid = fork();
if(pid == -1)
{
printf("error!\n");
}
else if(pid ==0)
{
printf("This is the child process!\n");
getchar();
}
else
{
printf("This is the parent process! child process id = %d\n", pid);
getchar();
// wait(NULL);
}
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void thread(void)
{
printf("This is a pthread.\n");
sleep(10);
}
int main(void)
{
pthread_t id[100];
int i,ret;
for(i=0;i<100;i++)
{
ret=pthread_create(&id[i],NULL,(void *) thread,NULL);
if(ret!=0)
{
printf ("Create pthread error!\n");
exit (1);
}
}
printf("This is the main process.\n");
for(i=0;i<100;i++)
{
pthread_join(id[i],NULL);
}
return (0);
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void thread(void)
{
printf("This is a pthread.\n");
sleep(10);
}
int main(void)
{
pthread_t id[100];
int i,ret;
for(i=0;i<100;i++)
{
ret=pthread_create(&id[i],NULL,(void *) thread,NULL);
if(ret!=0)
{
printf ("Create pthread error!\n");
exit (1);
}
}
printf("This is the main process.\n");
for(i=0;i<100;i++)
{
pthread_join(id[i],NULL);
}
return (0);
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void thread(void)
{
printf("This is a pthread.\n");
sleep(10);
}
int main(void)
{
pthread_t id;
int i,ret;
ret=pthread_create(&id,NULL,(void *) thread,NULL);
if(ret!=0)
{
printf ("Create pthread error!\n");
exit (1);
}
printf("This is the main process.\n");
pthread_join(id,NULL);
return (0);
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void thread(void)
{
printf("This is a pthread.\n");
sleep(10);
}
int main(void)
{
pthread_t id;
int i,ret;
ret=pthread_create(&id,NULL,(void *) thread,NULL);
if(ret!=0)
{
printf ("Create pthread error!\n");
exit (1);
}
printf("This is the main process.\n");
pthread_join(id,NULL);
return (0);
}
\ No newline at end of file
#!/usr/bin/bash
echo Running a shell script!
#!/usr/bin/bash
echo Running a shell script!
HelloWorld
\ No newline at end of file
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
main()
{
pid_t pid;
pid = fork();
if(pid < 0)
printf("error occurred!\n");
else if(pid == 0)
{
printf("Hi father! I'm a ZOMBIE\n");
exit(0); //no one waits for this process.
}
else
{
sleep(10);
wait(NULL); //the zombie process will be reaped now.
}
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
main()
{
pid_t pid;
pid = fork();
if(pid < 0)
printf("error occurred!\n");
else if(pid == 0)
{
printf("Hi father! I'm a ZOMBIE\n");
exit(0); //no one waits for this process.
}
else
{
sleep(10);
wait(NULL); //the zombie process will be reaped now.
}
}
\ No newline at end of file
#### 3-1 /proc/cpuinfo 信息
```bash
cat /proc/cpuinfo
```
![image](./record/pic/3-1.png)
CPU型号为Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz,拥有四核心八线程
#### 3-2 top 命令的输出
```bash
top
```
![image](./record/pic/3-2.png)
其中 7.7 us 表示 7.7%的时间用于运行用户空间的代码,相应地有 sy 对应运行内核代码占用 CPU 时间的百分比、ni 表示低优先级用户态代码占用 CPU时间的百分比、id 表示空闲(运行 idle 任务进程)CPU 时间的百分比、wa 表示 IO 等待占用CPU 时间的百分比、hi 表示硬件中断(Hardware IRQ)占用 CPU 时间的百分比、si 表示软中断(Software Interrupts)占用 CPU 时间的百分比以及和虚拟化有关的 st(steal time)占用 CPU时间的百分比。
#### 3-3 top 命令的输出(展开 CPU 利用率)
![image](./record/pic/3-3.png)
#### 3-4&3-5 全系统的调度统计
```bash
cat /proc/sched_debug
cat /proc/schedstat
```
![image](./record/pic/3-4.png)
![image](./record/pic/3-5.png)
\ No newline at end of file
## Linux-homework of SZU
* 这是深圳大学罗秋明老师开设的linux操作系统课程的作业, 配套书籍《操作系统之编程观察》罗秋明 著。
* 包含实验过程记录以及课后思考的截图图像以及代码。
### [Example](./2.进程控制/note.md)
![image](./example.png)<br>
![image](./example_2.png)
## Linux-homework of SZU
* 这是深圳大学罗秋明老师开设的linux操作系统课程的作业, 配套书籍《操作系统之编程观察》罗秋明 著。
* 包含实验过程记录以及课后思考的截图图像以及代码。
### [Example](./2.进程控制/note.md)
![image](./example.png)<br>
![image](./example_2.png)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册