Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1.  
  2. /* Free the current process's resources. */
  3. void
  4. process_exit (int status)
  5. {
  6. struct thread *cur = thread_current ();
  7. uint32_t *pd;
  8.  
  9. // update child status in parent_child_list
  10. update_status(thread_current ()->parent_pid , thread_current ()->tid , -1 , status);
  11. thread_current ()->exit_status = status ;
  12.  
  13. // close all files
  14. process_close_all();
  15.  
  16. // termination print
  17. printf ("%s: exit(%d)\n", thread_current()->name, status);
  18.  
  19. /* Destroy the current process's page directory and switch back
  20. to the kernel-only page directory. */
  21. pd = cur->pagedir;
  22. if (pd != NULL)
  23. {
  24. /* Correct ordering here is crucial. We must set
  25. cur->pagedir to NULL before switching page directories,
  26. so that a timer interrupt can't switch back to the
  27. process page directory. We must activate the base page
  28. directory before destroying the process's page
  29. directory, or our active page directory will be one
  30. that's been freed (and cleared). */
  31. cur->pagedir = NULL;
  32. pagedir_activate (NULL);
  33. pagedir_destroy (pd);
  34. }
  35. }
  36.  
  37.  
  38.  
  39. void process_close (int fd)
  40. {
  41. if (get_elem(fd) != NULL){
  42. // get file
  43. struct file * fil = get_elem(fd);
  44. // close file
  45. file_close(fil);
  46. // remove file descriptor from decriptor list
  47. remove_elem(fd);
  48. }
  49. }
  50.  
  51. void process_close_all()
  52. {
  53. // get descriptor list of thread
  54. struct list *fd_table = &thread_current()->description_table;
  55. struct list_elem *e = list_begin (fd_table);
  56.  
  57. // close all open files
  58. while (e != list_end (fd_table)){
  59. struct file_descriptor * tmp = list_entry (e, struct file_descriptor , desc_element);
  60. e = list_next (e);
  61. process_close(tmp->file_number);
  62. }
  63. // close excutable
  64. file_close (thread_current()->exe);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement