Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- qq플롯
- 앱
- 자바
- 잔차
- 최대우도법
- 행렬
- 알고리즘
- 논리회로 #컴퓨터
- ios
- AIC
- 군간
- 개발
- Eigenvector
- Flutter
- 평균로그우도
- 파스칼삼각형
- 앱개발
- f비
- Android
- 군내
- 비둘기집원리
- Java
- 개발자
- 상대 엔트로피
- 운영체제
- 조건부정리
- 일반화오차
- Eigenvalue
- pintos
- 선형대수학
Archives
- Today
- Total
Dev_bob
[pintOs]Process Termination Message 본문
목표
유저 프로세스가 종료될 때마다 아래와 같은 형식으로 프로세스 이름과 exit 코드를 출력해야 합니다:
printf("%s: exit(%d)\\n", process_name, exit_code);
세부 조건
- 출력 시점
- exit() 호출 시
- 또는 그 외 유저 프로세스가 종료되는 모든 상황
- 출력 예외
- 커널 스레드가 종료될 때는 출력하지 않음
- halt 시스템 콜이 호출된 경우 출력하지 않음
- load 실패 시 출력 여부는 선택사항
- 프로세스 이름
- process_execute() 또는 fork()에 전달된 전체 이름 사용
- 추가 출력 금지
- 위 형식 외에 추가 메시지 출력 금지
- 디버깅용 메시지도 제출 시 제거 (채점 스크립트 오류 발생 가능)
구현
- 프로세스 이름, exit 코드를 출력
- 호출되었을때
- 다른이유로 유저프로세스(UserProg)가 종료될때
thread_exit()에 의해 호출된다.
기존코드
process_exit()
/* Exit the process. This function is called by thread_exit (). */
void
process_exit (void) {
struct thread *curr = thread_current ();
/* TODO: Your code goes here.
* TODO: Implement process termination message (see
* TODO: project2/process_termination.html).
* TODO: We recommend you to implement process resource cleanup here. */
process_cleanup ();
}
Thread_exit()
/* Deschedules the current thread and destroys it. Never
returns to the caller. */
void
thread_exit (void) {
ASSERT (!intr_context ());
#ifdef USERPROG
process_exit ();
#endif
/* Just set our status to dying and schedule another process.
We will be destroyed during the call to schedule_tail(). */
intr_disable ();
do_schedule (THREAD_DYING);
NOT_REACHED ();
}
struct thread
struct thread {
/* Owned by thread.c. */
tid_t tid; /* Thread identifier. */
enum thread_status status; /* Thread state. */
char name[16]; /* Name (for debugging purposes). */
int priority; /* Priority. */
/* Shared between thread.c and synch.c. */
struct list_elem elem; /* List element. */
int64_t wakeup_tick;
#ifdef USERPROG
/* Owned by userprog/process.c. */
uint64_t *pml4; /* Page map level 4 */
#endif
#ifdef VM
/* Table for whole virtual memory owned by thread. */
struct supplemental_page_table spt;
#endif
/* Owned by thread.c. */
struct intr_frame tf; /* Information for switching */
unsigned magic; /* Detects stack overflow. */
};
흐름도
thread_exit()→process_exit() → (내부에서 thread_current)로 현재 스레드 호출
문제 1 : thread를 종료시킬때, 프로세스 이름, exit코드를 출력해야함.
void
process_exit (void) {
struct thread *curr = thread_current ();
/* TODO: Your code goes here.
* TODO: Implement process termination message (see
* TODO: project2/process_termination.html).
* TODO: We recommend you to implement process resource cleanup here. */
**printf("%s : exit(%d) \\n", curr->name ,curr->exit_code);**
process_cleanup ();
}
문제 2 : 유저프로세스가 아닌 커널 쓰레드가 프로세스를 종료하는 상황이거나, halt 시스템 콜이 호출된 상황이라면 이 메세지를 출력하지 말아야함.
커널스레드가 프로세스를 종료하는 상황
pml4값이 null이라면 커널스레드
halt 시스템 콜의 경우
halt의 경우 thread_exit의 경로를 거치지 않기 때문에 구현하지 않아도 됨.
pml4란?(page map level 4)
pml4는 유저 프로세스의 주소 공간을 관리하는 페이지 테이블의 최상위 포인터로, Pintos 프로젝트에서 사용하는 가상 메모리 구조입니다.
유저 모드(User Mode)에서 실행되는 각 프로세스는 자신만의 페이지 테이블(pml4) 을 가지며, 해당 테이블이 생성되고 활성화되어 있어야 합니다.
반면, pml4 값이 NULL이라는 것은 해당 스레드가 유저 주소 공간을 가지지 않는다, 즉 커널 모드(Kernel Mode) 에서 동작하는 커널 스레드임을 의미합니다.
최종구현
process_exit()
void
process_exit (void) {
struct thread *curr = thread_current ();
/* TODO: Your code goes here.
* TODO: Implement process termination message (see
* TODO: project2/process_termination.html).
* TODO: We recommend you to implement process resource cleanup here. */
//pml4가 NULL이면 커널스레드
if(curr->pml4 !=NULL){
printf("%s : exit(%d) \\n", curr->name ,curr->exit_code);
}
process_cleanup ();
}
'프로젝트 > pintOs' 카테고리의 다른 글
| [PintOs] Argument Passing 주요 개념 정리 (1) | 2025.05.25 |
|---|