Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Free the current process's resources. */
- void
- process_exit (int status)
- {
- struct thread *cur = thread_current ();
- uint32_t *pd;
- // update child status in parent_child_list
- update_status(thread_current ()->parent_pid , thread_current ()->tid , -1 , status);
- thread_current ()->exit_status = status ;
- // close all files
- process_close_all();
- // termination print
- printf ("%s: exit(%d)\n", thread_current()->name, status);
- /* Destroy the current process's page directory and switch back
- to the kernel-only page directory. */
- pd = cur->pagedir;
- if (pd != NULL)
- {
- /* Correct ordering here is crucial. We must set
- cur->pagedir to NULL before switching page directories,
- so that a timer interrupt can't switch back to the
- process page directory. We must activate the base page
- directory before destroying the process's page
- directory, or our active page directory will be one
- that's been freed (and cleared). */
- cur->pagedir = NULL;
- pagedir_activate (NULL);
- pagedir_destroy (pd);
- }
- }
- void process_close (int fd)
- {
- if (get_elem(fd) != NULL){
- // get file
- struct file * fil = get_elem(fd);
- // close file
- file_close(fil);
- // remove file descriptor from decriptor list
- remove_elem(fd);
- }
- }
- void process_close_all()
- {
- // get descriptor list of thread
- struct list *fd_table = &thread_current()->description_table;
- struct list_elem *e = list_begin (fd_table);
- // close all open files
- while (e != list_end (fd_table)){
- struct file_descriptor * tmp = list_entry (e, struct file_descriptor , desc_element);
- e = list_next (e);
- process_close(tmp->file_number);
- }
- // close excutable
- file_close (thread_current()->exe);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement