group/pintos/src/userprog/process.c
/* Starts a new thread running a user program loaded from
   FILENAME.  The new thread may be scheduled (and may even exit)
   before process_execute() returns.  Returns the new process's
   thread id, or TID_ERROR if the thread cannot be created. */
Starts a new thread running a user program loaded from
FILENAME.  The new thread may be scheduled (and may even exit)
before process_execute() returns.  Returns the new process's
thread id, or TID_ERROR if the thread cannot be created.
Starts a new thread running a user program loaded from FILENAME . The new thread may be scheduled ( and may even exit ) before process_execute () returns . Returns the new process ' s thread id or TID_ERROR if the thread cannot be created .
tid_t
process_execute (const char *cmd)
{
  char *fn_copy;
  tid_t tid;
  char fname[NAME_MAX + 1];
  char *ppath = malloc(sizeof(char) * PATH_MAX);
  struct start_info si;
  get_ppath(cmd, ppath);
  path_basename(ppath, fname);
  fn_copy = palloc_get_page (0);
  if (fn_copy == NULL) {
    tid = TID_ERROR;
    goto done;
  }
  strlcpy (fn_copy, cmd, PGSIZE);
  si.cmd = fn_copy;
  sema_init(&si.sema, 0);
  tid = thread_create (fname, PRI_DEFAULT, start_process, &si);
  if (tid == TID_ERROR)
    palloc_free_page (fn_copy);
  sema_down(&si.sema);
  if (!si.success)
      tid = TID_ERROR;
done:
  free(ppath);
  return tid;
}
tid_t process_execute ( const char * cmd ) { char * fn_copy ; tid_t tid ; char fname [ NAME_MAX + 1 ] ; char * ppath = malloc ( sizeof ( char ) * PATH_MAX ) ; struct start_info si ; get_ppath ( cmd , ppath ) ; path_basename ( ppath , fname ) ; fn_copy = palloc_get_page ( 0 ) ; if ( fn_copy == NULL ) { tid = TID_ERROR ; goto done ; } strlcpy ( fn_copy , cmd , PGSIZE ) ; si . cmd = fn_copy ; sema_init ( & si . sema , 0 ) ; tid = thread_create ( fname , PRI_DEFAULT , start_process , & si ) ; if ( tid == TID_ERROR ) palloc_free_page ( fn_copy ) ; sema_down ( & si . sema ) ; if ( ! si . success ) tid = TID_ERROR ; done : free ( ppath ) ; return tid ; }
Starts a new thread running a user program loaded from
FILENAME.
Starts a new thread running a user program loaded from FILENAME .
/* Make a copy of FILE_NAME.
     Otherwise there's a race between the caller and load(). */ /* Create a new thread to execute FILE_NAME. */