[OS] Process Management

moolsan3ยท2023๋…„ 10์›” 1์ผ
0

OS

๋ชฉ๋ก ๋ณด๊ธฐ
2/4
  • S30~ ํ›„๋ฐ˜๋ถ€๋Š” ๊ตฌํ˜„ ์„ค๋ช… ์ƒ๋žตํ•˜์‹ฌ.
    context ์ดํ•ด ์ •๋ฆฌํ•˜๊ณ  IPCํŒŒํŠธ๋Š” ์ข…๋ฅ˜, ๋ช…์นญ - ์ปจ์…‰ ๋งค์น˜ ์ •๋„๋งŒ ํ•˜๋„๋ก ~

Process Concept

job (vs process)

  • job; ์ปดํ“จํ„ฐ์— ์„ค์น˜๋œ program + data (์‹คํ–‰ ์—ฌ๋ถ€ ๊ด€๊ณ„ x)

process context(5)

  • program code -> text
  • global data -> data
  • temporary data -> stack
    • local var, func param, ret adr ..
  • dynamically allocated Mem area -> heap
  • values of the proc regs

resource(vs process)

  • passive entity (cf. process: active)

Process States & transition

  • Determined by proc - rsc interaction

created state

K ์— proc ๋“ฑ๋ก, PCB ํ• ๋‹น๋ฐ›์€ ์ƒํƒœ

- K : mem ๊ณต๊ฐ„ ํ™•์ธ -> O: ready / X: suspended state

Q. fork()?

  • UNIX ๋ฐ ์œ ๋‹‰์Šค ๊ธฐ๋ฐ˜ ์‹œ์Šคํ…œ ์ฃผ์š” ํ”„๋กœ์„ธ์Šค ์ƒ์„ฑ ๋ฉ”์ปค๋‹ˆ์ฆ˜
  • ์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ž์‹ ์˜ ๋ณต์‚ฌ๋ณธ์„ ์ƒ์„ฑํ•˜๋ฉฐ,
    ๊ธฐ์กด: parent proc, ์ƒ์„ฑ: child proc
  • ์ž์‹ ํ”„๋กœ์„ธ์Šค๋Š” ๋ถ€๋ชจ ํ”„๋กœ์„ธ์Šค๋กœ๋ถ€ํ„ฐ ์ฝ”๋“œ, ์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ ๋ฐ ์Šคํƒ, ํž™, ํ™˜๊ฒฝ ๋ณ€์ˆ˜, ์—ด๋ฆฐ ํŒŒ์ผ ๋””์Šคํฌ๋ฆฝํ„ฐ ๋“ฑ์„ ์ƒ์†๋ฐ›์ง€๋งŒ
  • ์ž์‹ ํ”„๋กœ์„ธ์Šค๋Š” ๋…๋ฆฝ๋œ ์‹คํ–‰ ์Šค๋ ˆ๋“œ ๊ฐ–๊ณ  ๋ณ„๋„๋กœ ๋™์ž‘ํ•˜๋ฉฐ ์„œ๋กœ์˜ ๋ฉ”๋ชจ๋ฆฌ์— ์ง์ ‘ ์ ‘๊ทผ ๋ถˆ๊ฐ€

+์ฐธ๊ณ : fork() in c

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main() {
    pid_t pid;
    pid = fork();

    if (pid < 0) {
        // ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ
        perror("fork failed");
        return 1;
    }

    if (pid == 0) {
        // ์ž์‹ ํ”„๋กœ์„ธ์Šค์˜ ์ฝ”๋“œ
        printf("child process with PID: %d\n", getpid());
    } else {
        // ๋ถ€๋ชจ ํ”„๋กœ์„ธ์Šค์˜ ์ฝ”๋“œ
        printf("the parent process with PID: %d, and my child's PID is: %d\n", getpid(), pid);
    }

    return 0;
}

Q. ๊ฐ‘์ž๊ธฐ ๋“œ๋Š” ์˜๋ฌธ sys call์˜ system์˜ def??

๊ทธ๋ƒฅ OS..?

ready state

Mem O -> ๋‹ค๋ฅธ rsc ๋‹ค ์žˆ์Œ / CPU๋งŒ X
  • if processor allocation ๊ฐ€๋Šฅ -> dispatch(=schedule)
    if processor allocation ๊ฐ€๋Šฅ X -> ๊ทธ๋ƒฅ waiting

dispatch

CPU ํ• ๋‹น
ready -> running state

running state

Mem O CPU O : ๋‹ค ์žˆ๋‹ค!

preemption

K์ด proc์˜ CPU ๋บ์Œ
running -> ready state
  1. timerunout( expiration of time quantum )
  2. higher priority proc

block(sleep)

I/O syscall๋กœ proc์ด CPU ๋ฐ˜๋‚ฉ, I/O ํ• ๋‹น ๋ฐ›์Œ
running -> asleep state
  • processor, mem์™ธ ๋‹ค๋ฅธ rsc request

blocked(asleep) state

Mem O CPU X(๋ฐ˜๋‚ฉ)  I/O O

wakeup

I/O ๋๋ƒ„
blocked -> ready

suspended state

Mem X
  • suspended ready & suspended asleep

swap out = suspend

losing mem
ready -> suspended ready
asleep -> suspended asleep

swap in = resume

getting mem
suspended ready -> ready 
suspended asleep -> asleep -

terminated/zombie state

  • PCB์˜ ์ผ๋ถ€ ์ •๋ณด ์ œ์™ธ ๋ชจ๋“  rsc ๋ฐ˜๋‚ฉ
  • ์ดํ›„ ์ „๋ถ€ ๋ฐ˜๋‚ฉ

Process States in Unix(์ฐจ์ด์ )

  • 1,2 : K, user์˜ running state๋ฅผ ๊ตฌ๋ณ„ํ•จ

  • 3,7 : ์ผ๋ฐ˜ ready, preempted๋ฅผ ๊ตฌ๋ณ„ํ•จ

  • ๊ท€์ฐจ๋Š  ์‹œํ—˜ ์ „์— ํ•ด๋ณด๊ธฐ

Process States in Linux(์ฐจ์ด์ )

  • ready ๋„ task-running ์ด๋ผ ํ•ด
  • virtual Mem ์ด ์žˆ์–ด์„œ suspended ์ƒํƒœ๊ฐ€ ์—†์Œ ๊ตณ์ด ~?

Scheduling (๊ฐ„๋‹จ)

Scheduler Queues

ready queue

  • priority Q, 1๊ฐœ

asleep queue

  • I/O reason๋ณ„๋กœ, ์—ฌ๋Ÿฌ๊ฐœ

scheduler ์ข…๋ฅ˜(3๊ฐ€์ง€, term ๊ธฐ์ค€)

  • long-term - sys
  • medium-term - mem, swapping
  • short-term - cpu

Interrupt

interrupt handling process

  1. interrupt from external source
  2. pause process execution
  3. Interrupt handling
  4. check interrupt source, reason
  5. decision for interrupt service
    ์ง€๊ธˆ ํ•˜๋Š” ์ผ vs interrupt ์šฐ์„  ์ˆœ์œ„ ๋น„๊ต
  6. invoke ISR(interrupt service routine)

Context Switching

context (what)

ctx saving, restoring,switching


IPC(๋ญ ์ค„์ธ๊ฑฐ๊ฒŒ)

IPC ํ•„์š” -> process cooperation ํ•„์š” ์ด์œ ?

Scheme (2๊ฐ€์ง€)

Message passing

RPC (+ RMI, LRPC)

shared memory

DSM

profile
๊ณต๋ถ€ ์šด๋™ ์žก๋‹ด .. ... . ๊ฐˆ ๊ธธ์ด ๋ฉ€๋‹ค!!!

0๊ฐœ์˜ ๋Œ“๊ธ€