Print out the process termination message
Whenever a user process terminates, because it called
exit
or for any other reason, print the process's name and exit code, formatted as if printed byprintf ("%s: exit(%d)\n", ...);
The name printed should be the full name passed to
fork()
. Do not print these messages when a kernel thread that is not a user process terminates, or when the halt system call is invoked. The message is optional when a process fails to load.Aside from this, don't print any other messages that Pintos as provided doesn't already print. You may find extra messages useful during debugging, but they will confuse the grading scripts and thus lower your score.
종료 메시지를 출력해라. 사용자가
exit
시스템콜을 부르거나 다른 어떤이유에던 프로세스가 종료되는데, 이때 프로세스의 이름과exit
코드를 입력해야한다. 포맷은 아래와 같이 하면 된다.printf ("%s: exit(%d)\n", ...);
fork()
함수에 전달된 전체 이름이 출력되어야 한다. 사용자 프로세스가 아닌 커널 스레드가 종료되거나 정지 시스템 호출이 호출될 때 이러한 메시지를 인쇄하지 마십시오. 프로세스를 로드하지 못한 경우 메시지는 선택 사항입니다.이 외에도 제공된 Pintos가 아직 인쇄하지 않은 다른 메시지를 인쇄하지 마십시오. 디버깅 중에 유용한 추가 메시지를 찾을 수 있지만 채점 스크립트를 혼동하여 점수를 낮춥니다.
즉 종료메시지를 출력하라는 말이다.
void exit (int status);
void exit(int status)
{
thread_current()->exit_status = status;
**printf("%s: exit(%d)\n", thread_name(), status);**
thread_exit();
// Terminates the current user program, returning status to the kernel.
// If the process's parent waits for it (see below), this is the status that will be returned.
// Conventionally, a status of 0 indicates success and nonzero values indicate errors.
}
exit()
에 printf
를 통해 thread
의 이름과 상태를 출력한다.
Deny write on executables.
Add code to deny writes to files in use as executables. Many OSes do this because of the unpredictable results if a process tried to run code that was in the midst of being changed on disk. This is especially important once virtual memory is implemented in project 3, but it can't hurt even now.
You can use
file_deny_write()
to prevent writes to an open file. Callingfile_allow_write()
on the file will re-enable them (unless the file is denied writes by another opener). Closing a file will also re-enable writes. Thus, to deny writes to a process's executable, you must keep it open as long as the process is still running.
실행 파일 쓰기 거부
실행 파일에 대한 쓰기를 거부합니다.
실행 파일로 사용 중인 파일에 대한 쓰기를 거부하는 코드를 추가합니다. 프로세스가 디스크에서 변경되는 도중에 코드를 실행하려고 하면 예측할 수 없는 결과가 발생하기 때문에 많은 OS에서 이 작업을 수행합니다. 이것은 가상 메모리가 프로젝트 3에서 구현되면 특히 중요하지만 지금도 아프지 않습니다.
file_deny_write()
열린 파일에 대한 쓰기를 방지하기 위해 사용할 수 있습니다 . 파일을 호출file_allow_write()
하면 다시 활성화됩니다(파일이 다른 오프너에 의해 쓰기가 거부되지 않는 한). 파일을 닫아도 쓰기가 다시 활성화됩니다. 따라서 프로세스의 실행 파일에 대한 쓰기를 거부하려면 프로세스가 실행 중인 동안에는 실행 파일을 열어 두어야 합니다.
void file_deny_write (struct file *file)
/* Prevents write operations on FILE's underlying inode
* until file_allow_write() is called or FILE is closed. */
void
file_deny_write (struct file *file) {
ASSERT (file != NULL);
if (!file->deny_write) {
file->deny_write = true;
inode_deny_write (file->inode);
}
}
열린 파일의 데이터가 변경되는것을 예방하는 함수이다.
void file_allow_write (struct file *file)
/* Re-enables write operations on FILE's underlying inode.
* (Writes might still be denied by some other file that has the
* same inode open.) */
void
file_allow_write (struct file *file) {
ASSERT (file != NULL);
if (file->deny_write) {
file->deny_write = false;
inode_allow_write (file->inode);
}
}
파일의 데이터가 변경되는 것을 허락하는 함수이다.
file_close()
함수 호출 시 해당 함수가 호출된다.
struct thread
{
(...)
struct file *running_file; // 현재 실행중인 파일
};
thread
구조체에 running_file
을 추가한다.
static void
init_thread(struct thread *t, const char *name, int priority)
{
(...)
t->running_file = NULL;
}
running_file
을 초기화해준다.
/* Exit the process. This function is called by thread_exit (). */
void process_exit(void)
{
struct thread *curr = thread_current();
sema_up(&curr->wait_sema);
file_close(curr->running_file);
sema_down(&curr->free_sema);
process_cleanup();
}
sema_free
하기전에 file_close
static bool
load(const char *file_name, struct intr_frame *if_) // parsing 기능을 추가해야됨
{
(...)
t->running_file = file;
file_deny_write(t->running_file);
(...)
done:
/* We arrive here whether the load is successful or not. */
// file_close(file);
return success;
}
process
가 open
되고 read
되기 전에 file_deny_write
를 해줌
그러기위해 현재 스레드에서 running_file
을 가려와서 현재 file
을 저장해줌
기존에 있던 file_close
를 주석처리
즉 현재 thread
에 지금 실행중인 file
구조체를 저장하고 나중에 close
를 process_exit
에서 해주는 로직이다.