task_struct is defined in include/linux/sched.h (search for "task_struct {"). Which fields of the task_struct contain information for process id, parent process id, user id, process status, children processes, the memory location of the process, the files opened, the priority of the process, program name?
---process id: pid_t pid
---parent process id: struct task_struct *parent
---user id: uid_t uid
---process status: volatile long state
---memory location of the process: struct mm_struct *mm
---files opened: struct files_struct *files
---priority of the process: unisigned int rt_priority
---program name: char comm[TASK_COMM_LEN]
Display all processes with "ps –ef". Find the pid of "ps -ef", the process you have just executed. Find the pid and program name of the parent process of it, then the parent of this parent, and so on, until you see the init_task whose process ID is 0.
모든 process를 확인할 수 있는 ps -ef | more 명령어를 사용합니다.
조사를 하니 ps -ef 명령어의 pid는 4591이고 ppid를 따라서 올라가면 -bash (PID 4455) -> /bin/login – (PID 4436) -> init[3] (PID 1) -> PID 0 이다.
Define display_processes() in init/main.c (right before the first function definition). Call this function in the beginning of start_kernel(). Confirm that there is only one process in the beginning. Find the location where the number of processes becomes 2. Find the location where the number of processes becomes 3. Find the location where the number of processes is the greatest. Use "dmesg" to see the result of display_processes().
만들어준 새로운 display_processes함수는 포인터형 struct 인 temp를 선언하고, init_task 을 넣어줍니다. 해당하는 프로세스마다 각각 pid, pname, state를 출력하고, temp는 그 다음 프로세스를 지정하도록 합니다. Init_task 다음에도 init_task라면 for문을 탈출하고 함수가 끝나게 됩니다.
Init/main.c 에 있는 start_kernel함수의 가장 처음부분에 display_processes를 호출하여주었습니다.
Make a system call that, when called, displays all processes in the system. Run an application program that calls this system call and see if this program displays all processes in the system.
프로세스 정보를 출력하는 system call을 만들어준다.
이후 arch/x86/kernel/syscall_table_32.S에서 44번 index에 새로운 함수를 설정해준다.
Echo 8 > /proc/sys/kernel/printk로 화면 log level을 낮추고, 위와 같은 코드로 만들어진 파일을 실행해보면 아래와 같습니다.
Make a system call that, when called, displays all ancestor processes of the calling process in the system. For example, if ex1 calls this system call, you should see: ex1, ex1’parent, ex1’s parent’s parent, etc. until you reach pid=0 which is Linux itself.
Ex1(pid: 4729 ppid: 4455) -> -bash(pid:4455 ppid:4436) -> /bin/login –-(pid:4436 ppid: 1)
Run three user programs, f1, f2, and f3, and run another program that calls the above system call as follows. State 0 means runnable and 1 means blocked. Observe the state changes in f1, f2, f3 and explain what these changes mean.
Ex1파일을 실행하니 f1, f2, f3 각각의 pid는 4632, 4633, 4634이고 마지막으로 ex1파일은 4635인 것을 볼 수 있었다. 실행 순서대로 프로세스가 증가하는 것을 확인할 수 있었다. 또한 ex1만 state가 0이므로 실행 시킬 수 있는 파일 임을 알 수 있었다.
Modify your display_processes() so that it can also display the remaining time slice of each process (current->rt.time_slice) and repeat 3.5) as below to see the effect. "chrt -rr 30 ./f1" will run f1 with priority value = max_priority-30 (lower priority means higher priority). "-rr" is to set scheduling policy to SCHED_RR (whose max_priority is 99).
#chrt –rr 30 ./f1&
#chrt -rr 30 ./f2&
#chrt -rr 30 ./f3&
#chrt -rr 30 ./ex1
'Quality control (Univ. Study) > Operating System' 카테고리의 다른 글
OS (pthread) (0) | 2022.11.13 |
---|---|
OS (fork) (0) | 2022.11.10 |
OS(interrupt) (0) | 2022.11.05 |
OS(system_call) (0) | 2022.10.11 |
OS(modificating kernel) (0) | 2022.10.07 |