Process Concept Process Control Block PCB PCB new
프로세스 개념(Process Concept) • 프로세스 제어 블럭(Process Control Block) » 각 프로세스는 PCB로 표현됨 » PCB • 프로세스 상태: new, ready, running, waiting, halted • 프로그램 카운터: next instruction의 주소 • CPU레지스터들: accumulator, index register, stack pointers, 범용 registers, condition-code • CPU스케줄 정보: priority, pointers to scheduling queues • 메모리 관리 정보: base and limit registers, page tables, segment tables • 계정 정보: time used, time limits, account numbers, job#, process# • 입출력 상태 정보: I/O devices list allocated to the process, list of open files • 스레드(Threads) » a process = a single thread of execution (one task) » 많은 현대 OS들이 multiple threads of control (multitasks at a time) 지원 2000 운영체제 4. 4 인천대학교 컴퓨터공학과 성미영
프로세스 스케줄링(Process Scheduling) ~ • 스케줄링 큐(Scheduling Queues) » 작업 큐 (job queue) : memory 할당 기다리는 큐(disk에서) » 준비 큐 (ready queue) : CPU에 할당 기다리는 큐 » 장치 큐 (device queue() : 입출력 기다리는 큐 » 큐잉 도표 (queueing diagram) : 그림 4. 5 • 스케줄러(Schedulers) » 장기 스케줄러(long-term scheduler, job scheduler) • pool -> memory(degree of multiprogramming) • Unix 같은 시분할 시스템에는 없음 » 단기 스케줄러(short-term scheduler, CPU scheduler) • CPU 할당 : must be very fast » 중기 스케줄러(medium-term scheduler) • swapping » degree of multiprogramming을 줄임 » memory -> backing store 2000 운영체제 4. 6 인천대학교 컴퓨터공학과 성미영
프로세스 스케줄링(Process Scheduling) • 문맥 교환(Context Switch) » CPU가 한 process에서 다른 process로 switch될 때 • save the state of the old process : CPU와 메모리 상태 (PCB정보) • load the saved state for new process : CPU와 메모리 상 태(PCB정보) » pure overhead : performance bottleneck -> threads로 해결 » context-switch time : 1 -1000 microsecond » address space 보존 방법 : memory 관리기법에 좌우 2000 운영체제 4. 10 인천대학교 컴퓨터공학과 성미영
Fork()로 새 프로세스를 생성하는 C program #include <stdio. h> void main(int argc, char *argv[]) { int pid; /* fork another process */ pid = fork(); if(pid < 0) { /* error occurred */ fprintf(stderr, “Fork Failed”); exit(-1); } else if (pid== 0) { /* child process) */ execl(“/bin/ls”, “ls”, NULL); } else { /* parent process */ wait(NULL); printf(“Child Complete”); exit(0); } } 2000 운영체제 4. 15 인천대학교 컴퓨터공학과 성미영
공유 메모리를 이용하는 생산자-소비자 문제 Import java. util. *; public class Bounded. Buffer { public Bounded. Buffer() { // buffer is initially empty count = 0; in = 0; out = 0; buffer = new Object[BUFFER_SIZE]; } // producer calls this method public void enter(Object item) { //Figure 4. 10 The enter method } // consumer calls this method public Object remove() { //Figure 4. 11 The remove() method } public static final int NAP_TIME = 5; private static final int BUFFER_SIZE = 5; private volatile int count; private int in; // points to the next free position private int out; //points to the next full posiiton private Object[] buffer; } 2000 운영체제 4. 19 인천대학교 컴퓨터공학과 성미영
생산자 enter() 메소드 public void enter(Object item) { while (count == BUFFER_SIZE) ; // do nothing // add an item to the buffer ++count; buffer[in] = item; in = (in + 1) % BUFFER_SIZE; if (count == BUFFER_SIZE) System. out. print. It(“Producer Entered “ + item + “ Buffer Full”); else System. out. print. It(“Producer Entered “ + item + “ Buffer size = “ + count); } 2000 운영체제 4. 20 인천대학교 컴퓨터공학과 성미영
소비자 remove() 메소드 public Oject remove() { Object item; while (count == 0) ; // do nothing // remove an item to the buffer --count; item = buffer[out]; out = (out + 1) % BUFFER_SIZE; if (count == 0) System. out. print. It(“Consumer Consumed “ + item + “ Buffer. Empty”); else System. out. print. It(“Consumer “ + item + “ Buffer size = “ + count); } 2000 운영체제 4. 21 인천대학교 컴퓨터공학과 성미영
Mailbox를 이용하는 생산자-소비자 문제 Import java. util. *; public class Message. Queue { public Message. Queue() { queue = new Vector(); } // This implements a nonblocking send public void send(Object item) { queue. add. Element(item); } // This implements a nonblocking receive public Object receive() { Object item; if (queue. size() == 0) return null; else { item = queue. first. Element(); queue. remove. Element. At(0); return item; } } private Vector queue; } 2000 운영체제 4. 27 인천대학교 컴퓨터공학과 성미영
메시지 시스템의 생산자 프로세스와 소비자 프로세스 • 생산자 프로세스 Message. Queue mail. Box; while (true) { Date message = new Date(); mail. Box. send(message); } • 소비자 프로세스 Message. Queue mail. Box; while (true) { Date message =(Date) mail. Box. receive(); if (message !=null) // consume the message } 2000 운영체제 4. 28 인천대학교 컴퓨터공학과 성미영
프로세스간 통신(Interprocess Communication) ~ • 실례 : Mach » 분산시스템을 위한 OS » 시스템 호출, task 간 정보전달을 메시지로 » port(= mailbox) » task 생성 => (kernel mailbox, notify mailbox) 생성 » system calls • msg_send • msg_receive • msg_rpc (remote procedure call) • port_allocate : 새 mailbox 생성, buffer size = 8, FIFO order • port_status : 주어진 mailbox의 메시지 수 반환 » 메시지 형태 • 고정길이 header » 메시지 길이 » 두 mailbox 이름(그 중 하나는 sender의 mailbox; reply 위한 return address 포함) • 가변길이 data portion: 정형화된(typed) 데이터 항목들의 리스트 2000 운영체제 4. 29 인천대학교 컴퓨터공학과 성미영
- Slides: 32