설명: 설명: 설명

Download Report

Transcript 설명: 설명: 설명

목차
Ⅰ
프로세스 생성
Ⅱ
신호
Ⅲ
프로세스 종료
Ⅳ
프로세스 종료 대기
Ⅴ
다른 프로그램의 호출
Ⅰ
프로세스 생성
Ⅱ
신호
Ⅲ
프로세스 종료
Ⅳ
프로세스 종료 대기
Ⅴ
다른 프로그램의 호출
프로세스 생성
Parent
Process
Fork()를
호출한
프로세스
Fork()
Child
Process
새로 생성된
프로세스
사용자가 프로세스
내에서 새로운 프로세스를
생성하는 유일한 방법은
fork 시스템 호출을 사용
하는 것이다.
프로세스 생성
<Process Table>
PID
상
태
필
드
프로
세스
크기
사용자
식별자
수면
이벤트
식별자
프로
세스
식별
자
스케
줄링
매개
변수
신호
필드
324
325
.
.
425
<inode Table>
<Memory>
inode
사용여부
230
사용
가능
231
사용
가능
.
.
.
.
.
.
타이
머
Algorithm fork
Input: none
Output: to parent process, child PID number
to child process, 0.
{
check for available kernel resources;
Get free proc table slot, unique PID number;
Check that user not running too many processes;
Mark child state “being created;”
copy data from parent proc table slot to new child slot;
increment counts on current directory inode and changed root;
increment open file counts in file table;
make copy of parent context(u area, text, data, stack) in memory;
push dummy system level context layer onto child system level
context;
dummy context contains data allowing child process
to recognize itself, and start running from here
when scheduled;
if(executing process is parent process)
{
change child state to “ready to run;”
return(child ID)
/* from system to user*/
}
else
/* executing process is the child process*/
{
initialize u area timing fields;
return(0);
/*to user*/
}
}
프로세스 생성
프로세스 테이블 엔트리
프로세스의 상태 언급
수면 상태 일 때,
프로세스 간의
프로세스에 보내
스케줄링 우선순위
이벤트 식별자
프로세스의 크기
스케줄링에
이용
상호관계 명시
지는 여러 신호
계산시에 이용
사용자 ID나 UID
프로세스 ID
PID
상태
필드
프로세스
크기
사용자
식별자
수면
이벤트
식별자
프로세스
식별자
스케줄링
매개변수
신호 필드
타이머
가장 작은
PID 할당
324
325
가장 작은
PID 할당
.
.
425
<Process Table>
프로세스 생성
프로세스 테이블에서 PID 할당 예제
 PID 할당 시나리오
1. Process A가 PID 할당 요청
2. PID 324는 사용 중.
3. PID 325는 Process B가 예약
PID
상태
필드
프로세스
크기
사용자
식별자
수면
이벤트
식별자
프로세스
식별자
스케줄링
매개변수
신호 필드
타이머
324
비어있는
가장 작은
그
PID다음으로
할당
작으면서 비
다른어있는
프로세스의
PID
예약으로
할당.
사용 불가!!!
325
326
425
<Process Table>
PID 할당 성공!
프로세스 생성
<Parent Process Table>
PID
PID
324
324
325
.
.
425
PID
326
상
프로
사용자
수면
프로
스케 신호
타이
태
세스
식별자
이벤트
세스
줄링 필드
머
<Process
Table>
필
크기
식별자
식별
매개
상
프로
사용자
수면
프로
스케 신호
타이
드
자
변수
태
세스
식별자
이벤트
세스
줄링 필드
머
<User Process Count Table>
필
크기
식별자
식별
매개
드
자 사용가능
변수 프로세스 수
유저 이름
사용 중 프로세스 수
USER A
70
USER B
125
부모의 필드들을
300
복사
SUPER USER
155
400
총계
<Child Process
Table>
350
400
상
태
필
드
프로
세스
크기
사용자
식별자
수면
이벤트
식별자
100
프로
세스
식별
자
스케
줄링
매개
변수
필요한 만큼의
많은
프로세스를
상태슈퍼유저는
필드에 프로세스가
생성되어
졌음을
실행 할
수도 created”를
있다. 또한 다른
프로세스를
표시하는
“being
마킹한다.
강제로 종료 시킬 수 있는 프로세스를 만들
수도 있다.
신호
필드
타이
머
Algorithm fork
Input: none
Output: to parent process, child PID number
to child process, 0.
{
check for available kernel resources;
Get free proc table slot, unique PID number;
Check that user not running too many processes;
Mark child state “being created;”
copy data from parent proc table slot to new child slot;
increment counts on current directory inode and changed root;
increment open file counts in file table;
make copy of parent context(u area, text, data, stack) in memory;
push dummy system level context layer onto child system level
context;
dummy context contains data allowing child process
to recognize itself, and start running from here
when scheduled;
if(executing process is parent process)
{
change child state to “ready to run;”
return(child ID)
/* from system to user*/
}
else
/* executing process is the child process*/
{
initialize u area timing fields;
return(0);
/*to user*/
}
}
프로세스 생성
프로세스 당
영역 테이블
부모
데이터
U Area
파일 테이블
열린 화일들
현재 디렉토리
변경된 루트
.
.
.
부모
사용자
스택
커널 스택
공유된
텍스트
공유되는 파일과
디렉토리의
inode에 참조계
수를 1 증가 시
킨다.
텍스트자원은 공유
될 수 있다.
Inode 테이블
프로세스 당
영역 테이블
자식
데이터
자식
사용자
스택
U Area
열린 화일들
현재 디렉토리
변경된 루트
Data, stack 영
역은 부모 프로
세스의 내용을
그대로 복사
.
.
.
커널 스택
Algorithm fork
Input: none
Output: to parent process, child PID number
to child process, 0.
{
check for available kernel resources;
Get free proc table slot, unique PID number;
Check that user not running too many processes;
Mark child state “being created;”
copy data from parent proc table slot to new child slot;
increment counts on current directory inode and changed root;
increment open file counts in file table;
make copy of parent context(u area, text, data, stack) in memory;
push dummy system level context layer onto child system level
context;
dummy context contains data allowing child process
to recognize itself, and start running from here
when scheduled;
if(executing process is parent process)
{
change child state to “ready to run;”
return(child ID)
/* from system to user*/
}
else
/* executing process is the child process*/
{
initialize u area timing fields;
return(0);
/*to user*/
}
}
프로세스 생성
공유된
텍스트
프로세스 당
영역 테이블
자식
데이터
자식
사용자
스택
U Area
열린 화일들
현재 디렉토리
변경된 루트
.
.
.
커널 스택
부모 프로세스와 동일한 실행환경(프로그램 카
운터, 레지스터 주소값 등)을 복사. 이러한 작업
으로 자식 프로세스에서 실제 실행되지 않았던
작업들도 실행된 된 후 저장된 것처럼 복구시킬
수 있으며, 따라서 자식 프로세스는 자신이 어
떤 프로세스의 자식임을 인지할 수 있다.
Algorithm fork
Input: none
Output: to parent process, child PID number
to child process, 0.
{
check for available kernel resources;
Get free proc table slot, unique PID number;
Check that user not running too many processes;
Mark child state “being created;”
copy data from parent proc table slot to new child slot;
increment counts on current directory inode and changed root;
increment open file counts in file table;
make copy of parent context(u area, text, data, stack) in memory;
push dummy system level context layer onto child system level
context;
dummy context contains data allowing child process
to recognize itself, and start running from here
when scheduled;
if(executing process is parent process)
{
change child state to “ready to run;”
return(child ID)
/* from system to user*/
}
else
/* executing process is the child process*/
{
initialize u area timing fields;
return(0);
/*to user*/
}
}
프로세스 생성
<Child Process Table>
PID
상
태
필
드
프로
세스
크기
사용자
식별자
수면
이벤트
식별자
프로
세스
식별
자
스케
줄링
매개
변수
324
325
.
.
425
1. 부모 프로세스의 경우
상태 필드에 프로세스가 실행 준비 됐음을
표시하는 “ready to run”를 마킹하고,
자식 프로세스의 PID를 리턴한다.
2. 자식 프로세스의 경우
U area의 timing field를 초기화하고 0을
리턴한다.
신호
필드
타이
머
Algorithm fork
Input: none
Output: to parent process, child PID number
to child process, 0.
{
check for available kernel resources;
Get free proc table slot, unique PID number;
Check that user not running too many processes;
Mark child state “being created;”
copy data from parent proc table slot to new child slot;
increment counts on current directory inode and changed root;
increment open file counts in file table;
make copy of parent context(u area, text, data, stack) in memory;
push dummy system level context layer onto child system level
context;
dummy context contains data allowing child process
to recognize itself, and start running from here
when scheduled;
if(executing process is parent process)
{
change child state to “ready to run;”
return(child ID)
/* from system to user*/
}
else
/* executing process is the child process*/
{
initialize u area timing fields;
return(0);
/*to user*/
}
}
프로세스 생성
프로세스 생성의 결과
1. 자식 프로세스는 fork가 실행될 당시의 부모 프로세스와
동일한 실행환경, 텍스트, 데이터 스택 리전을 가진다.
2. 두 프로세스는 fork를 호출한 시점에서 부모 프로세스가
열어놓은 파일 들을 공유하고, 그 파일 들에 대한 파일
테이블 참조계수는 전보다 1이 증가한다.
3. 자식 프로세스는 부모와 동일한 루트, 현재 디렉토리를
가지며, 해당 디렉토리 들의 inode 참조계수는 전보다
1이 증가된다.
Ⅰ
프로세스 생성
Ⅱ
신호
Ⅲ
프로세스 종료
Ⅳ
프로세스 종료 대기
Ⅴ
다른 프로그램의 호출
신호
신호들은 프로세스들에게 비동기적인 이벤트의 발생을 알린다.
1.
2.
3.
4.
5.
프로세스가 종료할 때나 death of child 매개변수를 가지
고 signal 시스템 호출을 했을 때 보내지는 프로세스와 관
련되는 신호들
프로세스가 자신의 가상 주소공간을 벗어난 주소를 엑세
스 할 때, 읽기 전용인 메모리에 쓰려고 할 때, 기타 다양
한 예외 상태와 관련된 신호들
읽는 프로세스가 없는 파이프에 쓰거나, 존재하지 않는 시
스템 호출을 하거나, 시스템 호출 시에 예상치 못했던 오
류 조건에 의해 발생되는 신호들
어떤 프로세스가 얼마만큼의 시간 후에 alarm 신호를 받
기를 원할 때, 또는 프로세스들이 kill 시스템 호출을 사용
하여 서로에게 임의의 신호를 보내려고 할 때처럼 사용자
모드에서의 프로세스로부터 발생되는 신호들
사용자 단말기의 전원을 켰을 때, 또는 사용자가 단말기
키보드에서 “break”나 “delete”키를 눌렀을 때와 같이 단
말기 통신에 관련된 신호들
신호
신호의 취급의 2가지 측면
 커널이 어떻게 프로세스에 신호를 보내는가?
 프로세스는 어떻게 신호를 처리 하는가?
신호
신호의 취급의 2가지 측면
 커널이 어떻게 프로세스에 신호를 보내는가?
 프로세스는 어떻게 신호를 처리 하는가?
신호
신호의 취급의 2가지 측면
(커널이 어떻게 프로세스에 신호를 보내는가?)
<Process Table>
PID
324
상태
필드
프로세스
크기
사용자 식
별자
수면
이벤트 식
별자
프로세스
식별자
스케줄
링 매개
변수
신호 필
드
타이머
10020
325
.
.
425
프로세스 테이블의 신호 필드에 받아야 할 신호
유형에 대응하는 비트셋을 쓴다.
신호
신호의 취급의 2가지 측면
(커널이 어떻게 프로세스에 신호를 보내는가?)
<Process Table>
PID
324
상태
필드
프로세스
크기
사용자 식
별자
수면
이벤트 식
별자
프로세스
식별자
스케줄
링 매개
변수
신호 필
드
타이머
10020
12350
325
.
.
425
프로세스는 서로 다른 종류의 신호는 기억할 수 있으나, 하나의 신호를 얼마나 많이 받았
는지는 기억할 수 없다.
신호
신호의 취급의 2가지 측면
(커널이 어떻게 프로세스에 신호를 보내는가?)
사용자
수행중
1
시스템 호출
인터럽트
신호를 조사하고 처리
커널은 프로세스가 커널 모드에서 사용자 모
드로 돌아갈 때나, 인터럽트에서 사용자 모드
로 복귀할 때만 신호를 인식하고 처리한다.
복귀
사용자 모드로 복귀
커널
수행중
exit
2
9
프리엠프트된 상태
프리엠프트
Zombie
수면
4
프로세서를 다시 스케쥴
Swap-in
Swap-out
메모리에서
수행 대기
3
깨움
Swap-out
메모리
에서 수면
7
그러므로 신호는 커널 모드에서 실행하는 프
로세스에게는 직접적인 효과가 없다.
생성
fork
8
메모리부족
(스웹핑 시스템에서)
6
5
깨움
수면, 스웹됨
스웹된 실행준비
신호
신호의 취급의 2가지 측면
 커널이 어떻게 프로세스에 신호를 보내는가?
 프로세스는 어떻게 신호를 처리 하는가?
신호
신호의 취급의 2가지 측면
(프로세스는 어떻게 신호를 처리 하는가?)
 프로세스가 종료
 신호를 무시
 받은 신호에 대해 정의된 특정한 함수 실행
신호
신호의 취급의 2가지 측면
(프로세스는 어떻게 신호를 처리 하는가?)
<Process Table>
PID
324
상
태
필
드
프로
세스
크기
사용
자식
별자
수면
이벤
트식
별자
프로
세스
식별
자
스
케
줄
링
매
개
변
수
신호
필드
타
이
머
100
20
325
.
.
425
신호 필드를
필드에서
리셋한다.
신호 비트셋을
꺼내온다.
Algorithm psig
Input: none
Output: none
{
get signal number set in proc table entry;
clear signal number in proc table entry;
If(user had called signal sys call to ignore this signal)
return;
if(user specified function to handle the signal)
{
get user virtual address of signal catcher stored in u area;
clear u area entry that stored address of signal catcher;
modify user level context;
artificially create user stack frame to mimic call
to signal catcher function;
modify system level context;
write address of signal catcher into program
counter field of user saved register context;
return;
}
if(signal is type that system should dump core image of process)
{
create file named “core” in current directory;
write contents of user level context to file “core”;
}
invoke exit algorithm immediately;
}
신호
신호의 취급의 2가지 측면
(프로세스는 어떻게 신호를 처리 하는가?)
사용자가 신호를 무시하라는 신호를 보냈을 경우 바
로 리턴한다.
signal(signum, 1);
*signum 은 신호의 번호.
Algorithm psig
Input: none
Output: none
{
get signal number set in proc table entry;
clear signal number in proc table entry;
If(user had called signal sys call to ignore this signal)
return;
if(user specified function to handle the signal)
{
get user virtual address of signal catcher stored in u area;
clear u area entry that stored address of signal catcher;
modify user level context;
artificially create user stack frame to mimic call
to signal catcher function;
modify system level context;
write address of signal catcher into program
counter field of user saved register context;
return;
}
if(signal is type that system should dump core image of process)
{
create file named “core” in current directory;
write contents of user level context to file “core”;
}
invoke exit algorithm immediately;
}
신호
신호의 취급의 2가지 측면
(프로세스는 어떻게 신호를 처리 하는가?)
 신호를 처리하기로 정해진 함수가 있을 경우
1. u area 내의 신호 포착 함수의 주소를 얻어온다.
2. 신호포착 함수 엔트리를 초기화 한다.
3. 사용자 스택에 새로운 스택 프레임을 만들고, 사용자
스택에서 가져온 프로그램 카운터와 스택 포인터
값을 새로운 스택 프레임에 쓴다.
커널
모드
4. 프로그램 카운터의 값을 신호 포착 함수의 주소로
세팅한다.
5. 프로세스 내의 신호 처리 함수를 실행 한다.
사용자
모드
Algorithm psig
Input: none
Output: none
{
get signal number set in proc table entry;
clear signal number in proc table entry;
If(user had called signal sys call to ignore this signal)
return;
if(user specified function to handle the signal)
{
get user virtual address of signal catcher stored in u area;
clear u area entry that stored address of signal catcher;
modify user level context;
artificially create user stack frame to mimic call
to signal catcher function;
modify system level context;
write address of signal catcher into program
counter field of user saved register context;
return;
}
if(signal is type that system should dump core image of process)
{
create file named “core” in current directory;
write contents of user level context to file “core”;
}
invoke exit algorithm immediately;
}
신호
신호의 취급의 2가지 측면
(프로세스는 어떻게 신호를 처리 하는가?)
 신호가 예외적인 에러를 반환할 경우
1. 현재 디렉토리에 Core 파일을 만든다
2. Core 파일에 관련 에러와 발생원인들을 쓴다.
Algorithm psig
Input: none
Output: none
{
get signal number set in proc table entry;
clear signal number in proc table entry;
If(user had called signal sys call to ignore this signal)
return;
if(user specified function to handle the signal)
{
get user virtual address of signal catcher stored in u area;
clear u area entry that stored address of signal catcher;
modify user level context;
artificially create user stack frame to mimic call
to signal catcher function;
modify system level context;
write address of signal catcher into program
counter field of user saved register context;
return;
}
if(signal is type that system should dump core image of process)
{
create file named “core” in current directory;
write contents of user level context to file “core”;
}
invoke exit algorithm immediately;
}
Ⅰ
프로세스 생성
Ⅱ
신호
Ⅲ
프로세스 종료
Ⅳ
프로세스 종료 대기
Ⅴ
다른 프로그램의 호출
프로세스 종료
사용자
수행중
exit(status)
1
시스템 호출
인터럽트
복귀
인터럽트,
인터럽트 복귀
커널
수행중
exit
2
9
프리엠프트된 상태
프리엠프트
Zombie
수면
4
프로세스들은 exit 시스템 콜을 통해 종료
된다. Exit를 호출한 프로세스는 좀비 상태
로 돌아가고, 자원을 모두 반환하고, 프로세
스 테이블내의 슬롯을 제외한 실행환경을
없애 버린다.
프로세서를 다시 스케쥴
Swap-in
Swap-out
메모리에서
수행 대기
3
깨움
Swap-out
메모리
에서 수면
7
생성
fork
8
메모리부족
(스웹핑 시스템에서)
6
5
깨움
수면, 스웹됨
스웹된 실행준비
프로세스 종료
종료하는 프로세스가 제어 터미널과 관련되는 프로
세스 그룹 리더일 경우
커널
해당 프로세스는
종료신호종료되어야
하므로 모든 신호를 무시한다.
리더 프로세스
프로세스 A
Hangup
신호
프로세스 B
프로세스 C
프로세스 D
그룹 번호를 0으로 설정
Algorithm exit
Input: return code for parent process
Output: none
{
ignore all signals;
if(process group leader with associated control terminal)
{
send hangup signal to all members of process group;
reset process group for all members to 0;
}
close all open files(internal version of algorithm close);
release current directory(algorithm iput);
release current (changed) root, if exits(algorithm iput);
free regions, memory associaterd with process(algorithm
freereg);
write associating record;
make process state zombie
assign parent process ID of all child processes to be init
process(1);
if any children were zombie, send death of child signal to init;
send death of child signal to parent process;
context switch;
}
프로세스 종료
프로세스 당
영역 테이블
부모
데이터
부모
사용자
스택
U Area
파일 테이블
열린 화일들
현재 디렉토리
변경된 루트
.
.
.
커널 스택
공유된
텍스트
Inode 테이블
Algorithm exit
Input: return code for parent process
Output: none
{
ignore all signals;
if(process group leader with associated control terminal)
{
send hangup signal to all members of process group;
reset process group for all members to 0;
}
close all open files(internal version of algorithm close);
release current directory(algorithm iput);
release current (changed) root, if exits(algorithm iput);
free regions, memory associaterd with process(algorithm
freereg);
write associating record;
make process state zombie
assign parent process ID of all child processes to be init
process(1);
if any children were zombie, send death of child signal to init;
send death of child signal to parent process;
context switch;
}
프로세스 종료
사용자
수행중
1
시스템 호출
인터럽트
복귀
인터럽트,
인터럽트 복귀
커널
Zombie
에서 수면
4
Swap-in
Swap-out
메모리에서
수행 대기
3
깨움
Swap-out
9
수행중
exit
자신과
프로세스 테이블
2
내에 있는 자신의
자손 프 프리엠프트된 상태
프리엠프트 7
로세스들에 대해 합해진
수면 커널 실행 시간,
사용자와
프로세서를 다시 스케쥴
CPU 사용량 등을 저장한
다.
메모리
생성
fork
8
메모리부족
(스웹핑 시스템에서)
6
5
깨움
수면, 스웹됨
스웹된 실행준비
Algorithm exit
Input: return code for parent process
Output: none
{
ignore all signals;
if(process group leader with associated control terminal)
{
send hangup signal to all members of process group;
reset process group for all members to 0;
}
close all open files(internal version of algorithm close);
release current directory(algorithm iput);
release current (changed) root, if exits(algorithm iput);
free regions, memory associaterd with process(algorithm
freereg);
write associating record;
make process state zombie
assign parent process ID of all child processes to be init
process(1);
if any children were zombie, send death of child signal to init;
send death of child signal to parent process;
context switch;
}
프로세스 종료
만약
자식프로세스와
프로세스가모든
좀비
종료되는
상태가
되면 이닛 프로세스
자손 프로세스들을
init 프로
에
“death
of
child”신호를
세스의 자식이 되도록 하여
보내서
init이
테이
프로세스
트리프로세스
로부터 연결
블에서
그들을 제거할 수 있
을 끊는다.
게 하고, 해당 자식 프로세스
의 부모에세도“Death of
child”신호를 보낸다.(7.9절
참조)
Algorithm exit
Input: return code for parent process
Output: none
{
ignore all signals;
if(process group leader with associated control terminal)
{
send hangup signal to all members of process group;
reset process group for all members to 0;
}
close all open files(internal version of algorithm close);
release current directory(algorithm iput);
release current (changed) root, if exits(algorithm iput);
free regions, memory associaterd with process(algorithm
freereg);
write associating record;
make process state zombie
assign parent process ID of all child processes to be init
process(1);
if any children were zombie, send death of child signal to init;
send death of child signal to parent process;
context switch;
}
33
Ⅰ
프로세스 생성
Ⅱ
신호
Ⅲ
프로세스 종료
Ⅳ
프로세스 종료 대기
Ⅴ
다른 프로그램의 호출
프로세스 종료 대기
사용자
수행중
Pid =
Wait(stat_addr)
1
시스템 호출
인터럽트
복귀
인터럽트,
인터럽트 복귀
커널
수행중
exit
2
9
프리엠프트된 상태
프리엠프트
Zombie
수면
4
7
부모 프로세스가 wait 호출을 했을 때, 일어
날 수 있는 경우의 수는 아래의 3가지 이다.
프로세서를 다시 스케쥴
Swap-in
Swap-out
1.
2.
3.
메모리에서
수행 대기
3
깨움
Swap-out
메모리
에서 수면
생성
fork
8
메모리부족
(스웹핑 시스템에서)
6
5
깨움
수면, 스웹됨
프로세스들은 wait 호출을 통해 자식 프로세
스 종료와 동기화할 수 있다.
스웹된 실행준비
좀비 상태인 자식 프로세스가 없을 경우
좀비 상태인 자식 프로세스가 있을 경우
자식 프로세스가 없을 경우
프로세스 종료 대기
1. 좀비 상태인 자식 프로세스가 없을 경우
커널은 wait 호출을 한 프로세스의 자식들
중에 어떤 것도 좀비 상태인 것이 없을 경우,
“death of child”신호가 도달할 때까지 인
터럽트 가능한 우선순위에서 수면 상태로
들어간다.
프로세스 종료 대기
2. 좀비 상태인 자식 프로세스가 있을 경우
Wait 호출을 한 프로세스에 좀비 상태인
자식 프로세스가 있을 경우, 다시 2가지 경
우가 생긴다.
“death
신호를
“deathofofchild”
child”
신호받
아도
부모 프로세스는
를 무시할
경우
수면상태에서 깨어나지 않으
며, 따라서 모든 자식 프로세
Signal(signum,
1) 자식
스가 종료하고 더 이상
프로세스가 없을 때 나오는
오류 메시지로 수면상태에서
깨어나게 된다.
“death
신호가
“deathofofchild”
child”
신호들
어오면, 즉 하나의 자식
를
무시하지 않을 경우
프로세스가 종료되면 바로
수면상태에서 깨어난다.
프로세스 종료 대기
3. 자식 프로세스가 없을 경우
Wait 호출을 한 프로세스에 자식 프로세스
가 없을 경우, 커널은 오류를 리턴한다.
38
Ⅰ
프로세스 생성
Ⅱ
신호
Ⅲ
프로세스 종료
Ⅳ
프로세스 종료 대기
Ⅴ
다른 프로그램의 호출
다른 프로그램의 호출
Execve(filename, argv, envp)
 Filename은 새로이 수행될 실행 파일의 이름
 Argv는 실행 프로그램에 대한 매개변수인 문자 포인터
 Envp는 실행된 프로그램의 환경인 문자 포인터의 배열
 Execl, execv, execle 등의 라이브러리가 존재
다른 프로그램의 호출
Execve(filename, argv, envp)
Filename의 inode에 접근
할당되었던 inode를 반환한
다.
파일에 대한 사용자의 권한
검사
사용자 모드로 복귀하기 위
해 스택 포인터와 프로그램
카운터를 초기화 한다.
헤더를 읽어서 실행 화일의
내용 정보를 결정
커널은 setid 프로그램과 프
로세스 tracing에 대해 특별
한 조치를 취한다.(11장)
매개변수가 사용자 주소이므
로, 커널은 주소의 내용을 복
사해서 커널 공간으로 옮긴
다.
매개변수들을 새로운 사용자
스택 리전에 복사한다.
프로세스에 할당되어 있는
모든 리전을 제거한다.
새로 실행된 프로세스에 새
리전들을 할당하고 적재한다.
또한 리전들을 메모리에 적
재한다.
Algorithm exec
Input: (1) file name
(2) parameter list
(3) environment variables list
Output: none
{
get file inode(algorithm namei);
verify file executable, user has permission to execute;
read file headers, check that it is a load module;
copy exec parameters from old address space to system space;
for(every region attached to process)
detach all old regions(algorithm detach);
for(every region specified in load module)
{
allocate new regions(algorithm allocreg);
attach the regions(algorithm attachreg);
load region into memory if appropriate(algorithm loadreg);
}
copy exec parameters into new user stack region;
special processing for setuid programs, tracing;
initialize user register save area for return to user mode;
release inode of file(algorithm iput);
}
Thank you
for
your attention!
Signal 시스템 호출
Oldfunction =
signal(signum, function)
 signum은 신호의 번호, function은 신호를 받았을 때, 실행되기를 원하는
함수의 주소
 function대신 1을 넣으면 signum에 해당하는 앞으로 발생할 모든 신호를
무시하라는 의미
 function대신 0을 넣으면 signum에 해당하는 신호가 오면 종료하라는 의미
복귀
신호를 받기 전/후의 사용자 스택과 커널 저장 영역
사용자 스택의
꼭대기
호출 순서의 새로
운 프레임
복귀 주소(10c)
신호를 받기 전의
사용자 스택
신호를 받기 전의
사용자 스택
<사용자 스택>
<사용자 스택>
프로세스의 복귀
주소(10c)
프로세스의 복귀
주소(104)
사용자 보관
레지스터 실행환경
사용자 보관
레지스터 실행환경
커널 실행 환경층 1
레지스터 보관 영역
커널 실행 환경층 1
레지스터 보관 영역
<신호 받기 전>
<신호 받은 후>
복귀