summaryrefslogtreecommitdiffstats
path: root/src/userprog/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/userprog/process.c')
-rw-r--r--src/userprog/process.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/userprog/process.c b/src/userprog/process.c
index 589b48b..fadd14d 100644
--- a/src/userprog/process.c
+++ b/src/userprog/process.c
@@ -93,11 +93,12 @@ start_process (void *args_)
if_.eflags = FLAG_IF | FLAG_MBS;
success = load (args->file_name, &if_.eip, &if_.esp);
args->success = success;
+ t->load_success = success;
if (success) {
t->parent = malloc (sizeof (struct parent_child));
- // sema_init (&t->parent.exit_sema, 0);
+ sema_init (&t->parent->exit_sema, 0);
lock_init (&t->parent->l);
t->parent->child_tid = t->tid;
@@ -132,9 +133,22 @@ start_process (void *args_)
This function will be implemented in problem 2-2. For now, it
does nothing. */
int
-process_wait (tid_t child_tid UNUSED)
+process_wait (tid_t child_tid)
{
- for (;;) {}
+ struct thread *t = thread_current ();
+ struct list_elem *e;
+ for (e = list_begin (&t->children); e != list_end (&t->children);
+ e = list_next (e))
+ {
+ struct parent_child *pc = list_entry (e, struct parent_child, elem);
+ if (child_tid == pc->child_tid) {
+ sema_down (&pc->exit_sema);
+ int exit_status = pc->exit_status;
+ pc->exit_status = -1;
+ return exit_status;
+ }
+ }
+ return -1;
}
static void
@@ -157,14 +171,18 @@ process_exit (void)
struct thread *cur = thread_current ();
uint32_t *pd;
- free_pc (cur->parent);
+ if (cur->load_success) {
+ sema_up (&cur->parent->exit_sema);
+ free_pc (cur->parent);
+ printf("%s: exit(%d)\n", cur->name, cur->parent->exit_status);
- struct list_elem *e;
- struct parent_child *child;
- while (!list_empty (&cur->children)) {
- e = list_pop_front (&cur->children);
- child = list_entry (e, struct parent_child, elem);
- free_pc (child);
+ struct list_elem *e;
+ struct parent_child *child;
+ while (!list_empty (&cur->children)) {
+ e = list_pop_front (&cur->children);
+ child = list_entry (e, struct parent_child, elem);
+ free_pc (child);
+ }
}
/* Destroy the current process's page directory and switch back
@@ -318,6 +336,7 @@ load (const char *file_name, void (**eip) (void), void **esp)
}
file_name = esp_cmd;
+ strlcpy (thread_current ()->name, file_name, 16);
/* argv entries are pointers so they need to be aligned to the pointer size. */
size_t psize = sizeof (char *);