Process Table PID 324 325 425 inode Table
프로세스 생성 <Process Table> PID 상 태 필 드 프로 세스 크기 사용자 식별자 수면 이벤트 식별자 프로 세스 식별 자 스케 줄링 매개 변수 신호 필드 324 325. . 425 <inode Table> inode 사용여 부 230 사용 가능 231 사용 가능 <Memory> . . . 타이 머 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*/ } }
프로세스 생성 <Parent Process Table> PID 324 상 태 필 상 드 태 필 드 유저 프로 사용자 수면 프로 스케 신호 타이 세스 식별자 이벤트 세스 줄링 필드 머 <Process Table> 크기 식별자 식별 매개 프로 사용자 수면 프로 스케 신호 타이 자 변수 세스 식별자 이벤트 세스 줄링 필드 머 <User Process Count Table> 크기 식별자 식별 매개 자 변수 이름 사용 중 프로세스 수 사용가능 프로세스 수 324 USER A 70 100 325 USER B 125 부모의 필드들을 300 복사 . . SUPER USER 155 400 425 PID 326 총계 상 프로 태 세스 필 크기 드 <Child Process Table> 사용자 식별자 350 수면 이벤트 식별자 프로 세스 식별 자 스케 줄링 매개 변수 400 신호 필드 필요한 만큼의 많은 프로세스를 상태슈퍼유저는 필드에 프로세스가 생성되어 졌음을 실행 할 수도 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*/ } }
신호 신호의 취급의 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가지 측면 (프로세스는 어떻게 신호를 처리 하는가? ) u 신호를 처리하기로 정해진 함수가 있을 경우 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가지 측면 (프로세스는 어떻게 신호를 처리 하는가? ) u 신호가 예외적인 에러를 반환할 경우 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; }
프로세스 종료 종료하는 프로세스가 제어 터미널과 관련되는 프로 세스 그룹 리더일 경우 커널 해당 프로세스는 종료신호종료되어야 하므로 모든 신호를 무시한다. 리더 프로세스 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 6 메모리에서 수행 대기 3 깨움 Swap-out 9 수행중 exit 자신과 프로세스 테이블 2 내에 있는 자신의 자손 프 프리엠프트된 상태 프리엠프트 로세스들에 대해 합해진 7 수면 커널 실행 시간, 사용자와 프로세서를 다시 스케쥴 CPU 사용량 등을 저장한 다. 메모리 생성 fork 8 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; }
다른 프로그램의 호출 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!
- Slides: 42