*정의
프로그램 내에서 처리 부분을 맡고 있고, os의 unit of work이다.
*수행 task
*Memory layout
Text section: the executable code
Data section: global variables
Heap section: program run time하는 동안 메모리는 할당됩니다.
Stack section: invoking functions할 때 일시적인 데이터 저장소로 function parameters, return addresses, local variables이다
New: process가 새로 생성됨
Running: Instructions가 실행됨
Waiting: process가 사건이 발생되길 기다림
Ready: process가 processor이 승인되길 기다림
Terminated: 실행 종료
*PCB(Process Control Block) or TCB(Task Control Block)
각 프로세스는 PCB로 인해서 OS안에서 표현됨
Process of PCB
*Summary
program은 하나의 스레드를 실행
스레드 제어는 process가 수행되도록 허락(only one task at a time)
현대 os는 process개념의 확장
멀티프로그래밍(The objective of multiprogramming)
타임 공유(The objective of time sharing)
스케쥴링 큐(Sheduling Queues)
ready queue
wait queue
위의 큐들은 PCBs의 연결 리스트로 보충됨
Context Switch
PCB, context process기 표현됨
Interrupt occurs
Context switch
Mechanism: process creation and termination
Create several new processes
Two possibilities for execution
Two possibilities of address-space
CODE
#include <stdio.h>
#include <unistd.h>
#include <wait.h>
int main()
{{
pid_t pid;
// fork a child process
pid = fork();
if (pid <0 ) { // error occurred
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0) { // child process
execlp("/bin/ls", "ls", NULL);
}
else { // parent process
wait(NULL)
printf("Child Complete");
}
return 0;
}
프로세스 종결
최종 statement가 실행
exit()system call
OS deallocates and reclaims all the resources:
ex) allocated memories, open files, and I/O buffers, etc
Zombie and Orphan
UNIX-like O/S
fork()system call로 부터 새로운 process가 생성됨
A new process is created by the fork() system call.
a copy of the address space of the parent process.
• Both processes continue execution
• With one difference:
After a fork() system call,
the parent can continue its execution ; or
if it has nothing else to do while the child runs,
it can issue a wait() system call
to move itself off the ready queue until the termination of the child.