3.3 Operations on Processes
Process creation
프로세스는 새로운 프로세스를 생성한다.
프로세스를 만든 프로세스는 부모 프로세스, 만들어진 프로세스는 자식 프로세스라고한다.
프로세스는 process identifie(pid)로 구분한다.
systemd process는 sstem boot 할 때 생성되는 user process로 다른 user process들의 부모 process이다.
systemd 의 두 child process인 logind, sshd process가 존재한다.
logind process는 clients가 system 로그인을 운영한다.
sshd process는 client가 ssh를 사용하는 연결을 운영한다.
UNIN system에서는 init process가 root process이고 Linux system에서는 systemd process가 root process이다.
같은 역할을 하지만 systemd process가 더 flexible하다.
ps -el : 현재 시스템의 모든 process를 보여줌
pstree : 현재 시스템에서 모든 프로세스를 트리형태로 보여줌
process가 새로운 프로세스를 생성했을 때 2가지 동작이 존재
1. child & parent process가 동시에 실행
2. child process가 종료될 때 까지 parent wait
2가지 address space 경우 존재
1. parent & child process 중복
2. child process가 새로운 프로그램을 전달받음
자식 프로세스는 execlp로 /bin/ls 명령어를 수행하고, 부모 프로세스는 wait을 통해 자식프로세스가 끝날 때까지 block 된다.
Process Termination
exit 시스템 콜을 호출해 process를 종료한다.
이 때 child process는 waiting parent process에게 wait system call을 통해 status value를 return 한다.
parent process는 다양한 이유로 child process를 kill할 수 있다.
1. child process가 할당된 resource를 초과해서 사용한 경우
2. child에 할당된 task가 필요없는 경우
3. parent가 종료된 경우
OS에서 parent process가 죽으면 child process를 모두 죽이는데 이를 cascading termination이라 지칭한다.
프로세스가 종료되면 OS는 자원을 해제한다.
하지만 프로세스가 종료되었지만 parent process가 wait을 호출하지 않은 경우 process table에 exit status가 남아있게 된다. 이를 zombie process라고 한다.
parent process가 wait를 호출하지 않으면 좀비 프로세스들은 남게 될 것이다. 이를 UNIX 시스템의 root process인 init process가 주기적으로 wait를 호출하여 zombie process를 처리한다.
Android Process Hierarchy
importance hierachy : 중요도 순서대로 프로세스를 종료한다.
most to least 순서이다.
Foreground process — The current process visible on the screen, representing the application the user is currently interacting with
• Visible process — A process that is not directly visible on the foreground but that is performing an activity that the foreground process is referring to (that is, a process performing an activity whose status is displayed on theforegroundprocess)
• Service process — A process that is similar to a background process but is performing an activity that is apparent to the user (such as streaming music)
• Background process — A process that may be performing an activity but is not apparent to the user.
• Empty process — A process that holds no active components associated with any application