-
프로세스란 ?Computer Engineering/Computer Science 2023. 6. 5. 00:54
- 프로그램 : 실행되기 전까지 보조기억장치에 있는 데이터 덩어리
- 프로세스 : 프로그램을 메모리에 적재하고, 실행한 것
프로그램을 메모리에 적재하고 실행한다 = 프로세스를 생성한다
프로세스는 윈도우 작업관리자, 유닉스 ps명령어로 확인할 수 있다.
1. 포그라운드 프로세스 : 사용자가 보는 앞에서 실행되는 프로세스
2. 백그라운드 프로세스 : 사용자가 보지 못하는 뒤에서 실행되는 프로세스
2-1. 사용자와 상호작용할 수 있는 백그라운드 프로세스
2-2. 사용자와 상호작용하지 않고 묵묵히 정해진 일을 수행하는 백그라운드 프로세스
유닉스 : 데몬, 윈도우 : 서비스
모든 프로세스는 실행하기 위해 CPU 필요로 하지만, CPU 자원은 한정적임.
그래서 프로세스는 차례대로 돌아가며 한정된 시간만큼만 cpu이용
시간의 끝을 알리는 타이머 인터럽트 발생하면 차례 양보하고 다음 차례 올 때까지 기다림.
* 타이머 인터럽트 ( 타임아웃 인터럽트 ) : 클럭 신호를 발생시키는 장치에 의해 주기적으로 발생하는 하드웨어 인터럽트
운영체제가 하는 일
1. 프로세스 실행 순서 관리
2. CPU 비롯한 자원 배분
메모리
1. 커널 : PCB
2. 사용자 : 스택영역, 힙영역, 코드영역, 데이터영역
< 프로세스 메모리 커널 영역 >
프로세스 제어 블록 ( PCB )
: 프로세스와 관련된 정보를 저장하는 자료구조 , 상품의 태그
- 해당 프로세스 식별하기 위해 꼭 필요한 정보 저장
- 프로세스 생성시에 만들어지고, 실행히 끝나면 폐기
예시 ) 프로세스 ID, 레지스터 값(프로그램 카운터 등), 프로세스 상태, CPU 스케줄링 정보, 메모리 관리 정보(저장, 페이지 테이블, 한계/베이스 레지스터 값 등 ), 사용한 파일과 입출력장치 목록( 할당되었던 입출력장치, 열었던 파일 )
문맥교환
- 문맥 : 프로세스가 중간에 기억해야 할 정보, PCB에 저장되어 있음
- 문맥교환 : 기존 프로세스의 문맥을 PCB에 백업하고, 새로운 프로세스 실행하기 위해 문맥을 PCB로부터 복구하여 새로운 프로세스 실행하는 것
문맥교환 자주 일어나면 프로세스 동시에 실행되는 것처럼 보이나 오버헤드가 발생할 수 있다
< 프로세스 메모리 사용자 영역 >
1. 코드 영역 : 텍스트 영역, 실행할 수 있는 코드 ( 기계어로 이루어진 명령어 저장 )
- cpu가 실행할 명령어가 담겨있기 때문에 쓰기가 금지되어 있음.
- 읽기 전용 공간
- 크기가 변하지 않음, 고정
- 정적 할당 영역
2. 데이터 영역 : 프로그램이 실행되는 동안 유지할 데이터가 저장되는 공간
- 전역 변수가 대표적
- 크기가 변하지 않음, 고정
- 정적 할당 영역
3. 힙 영역 : 프로그래머가 직접 할당할 수 있는 저장 공간
- 힙 영역에 메모리 공간 할당했다면 언젠가는 해당 공간 반환해야 함.
- 메모리 공간 반환 = 더 이상 해당 메모리 공간을 사용하지 않겠다
-> 메모리 공간 반환하지 않는다면, 할당 공간은 메모리에 계속 남아 메모리 낭비 초래 = 메모리 누수
- 메모리의 낮은 주소에서 높은 주소로 할당
4. 스택 영역 : 데이터를 일시적으로 저장하는 공간
- 잠깐 쓰다가 말 값들이 저장되는 공간
- 매개 변수, 지역 변수
- 메모리 높은 주소에서 낮은 주소로 할당요약
- 프로세스 : 실행 중인 프로그램 ( 포그라운드 프로세스, 백그라운드 프로세스 )
- 운영체제는 프로세스 제어 블록 PCB 통해 프로세스 관리
- 문맥 교환 : 프로세스 간에 실행을 전환하는 것, PCB와 같이 중간에 정보 저장한 것 백업하고 새로운 거 복구
- 프로세스 사용자 영역 : 코드 영역, 데이터 영역 ( 정적 할당 영역 ) , 스택 영역, 힙 영역 ( 동적 할당 영역 )< 혼자 공부하는 컴퓨터 구조 + 운영체제 > 책을 공부하며 정리한 내용입니다.