← Back to Blog

[Operating System] Interrupt

computer science > operating system

2026-07-043 min read

#computer-science #operating-system #interrupt

본 자료는 인하대학교 정진만 교수님의 Operating System 강의 자료를 참고하여 제작되었습니다.

Processor Register

Register역할
Program Counter (PC)다음에 실행할 명령어의 주소를 저장한다.
Instruction Register (IR)현재 fetch된 명령어를 저장한다.
Program Status Word (PSW)조건 코드, interrupt mask 등 CPU 상태 정보를 저장한다.
Memory Address Register (MAR)접근할 메모리 주소를 저장한다.
Memory Buffer Register (MBR)메모리에서 읽거나 메모리에 쓸 데이터 값을 저장한다.

Instruction

< Instruction format >
+--------+----------+
| opcode | operands |
+--------+----------+

Instruction Fetch

PC가 가리키는 명령어를 가져와 IR에 적재한다.

Instruction Cycle

  1. PC -> MAR
  2. MAR -> MBR
  3. MBR -> IR
  4. PC = PC + 1

OS Time Management

구분시간 기준사용 목적
Time-driven Managementrelative timeOS가 일정 주기로 제어권을 얻을 때 사용한다.
Managing the current time of dayabsolute time파일 시스템 시간처럼 실제 시각이 필요할 때 사용한다.

System Timer

Timer시간 기준역할
PIT(Programmable Interval Timer, System Timer)relative timeOS tick을 발생시키는 타이머이다. Hz 값을 설정할 수 있고 보통 100Hz로 설정한다.
Jiffiesrelative time컴퓨터 부팅 후 발생한 tick 수를 저장하는 global variable이다.
RTC(Real Time Clock)absolute time실제 시각을 관리하는 hardware clock이다. /dev/rtc로 접근할 수 있다.

Interrupt

용어의미
Interrupt하드웨어에서 발생하는 이벤트이다.
Interrupt HandlerInterrupt를 처리하는 OS 코드이다.
Time Interrupttime slice를 넘으면 발생하는 interrupt이다.

그래서 Interrupt가 발생하면, Interrupt handler가 관리한다.

Interrupt Mechanism

e.g.,

  1. Update the jiffies
  2. Update the wall time
  3. Update the process time
    3-1. Upgrade resouce usage
    3-2. Update time slice
  4. Run dynamic timers

Programmable Interrupt Controller(PIC)

CPU랑 I/O controller 사이에서 중간 관리자 역할을 수행한다.
장치로부터 #IRQ를 받아 interrupt를 마스킹한다.

Interrupt 처리 과정

interrupt processing

Hardware

  1. Interrupt가 발생한다.
  2. 현재 명령어를 종료한다.
  3. Interrupt 신호를 인지한다.
  4. Control Stack에 PSW와 PC를 push한다.
  5. Interrupt에 맞는 PC를 load한다.

Software

  1. 프로세스 상태 정보를 저장한다. (Save all)
  2. Interrupt Service Routine(ISR)을 실행한다.
  3. 프로세스 상태를 복구한다.
  4. PSW와 PC를 복구한다. (Restore all)

Interrupt와 Exception

Interrupt는 hardware에서 발생하는 것이라 비동기 처리가 되고.
Exception은 divid by zero처럼 CPU에서 발생하는 것이라 동기 처리이다.

구분발생 위치처리 특성예시
InterruptH/W 장치비동기 처리I/O 완료, timer interrupt
ExceptionCPU동기 처리divide by zero, invalid instruction