コード例 #1
0
ファイル: process.c プロジェクト: kazyka/2aar
process_id_t process_spawn(const char *executable, const char **argv)
{
  TID_t thread;
  process_id_t pid = alloc_process_id();
  int ret;

  if (pid == PROCESS_MAX_PROCESSES) {
    return PROCESS_PTABLE_FULL;
  }

  spinlock_acquire(&process_table_slock);
  process_table[pid].parent = process_get_current_process();
  thread = thread_create((void (*)(uint32_t))(&process_run), pid);
  ret = setup_new_process(thread, executable, argv,
                          &process_table[pid].entry_point,
                          &process_table[pid].stack_top);

  if (ret != 0) {
    process_table[pid].state = PROCESS_ZOMBIE;
    ret = -1;
  } else {
    ret = pid;
  }

  thread_run(thread);
  spinlock_release(&process_table_slock);
  return ret;
}
コード例 #2
0
ファイル: process_helpers.c プロジェクト: PtxDK/OSM
//Load and run the executable as a new process in a new thread
//  Argument: executable file name; Returns: process ID of the new process
process_id_t process_spawn(char const* executable, char const **argv){

  // Initialise 'global' variables
  interrupt_status_t intr_status;
  TID_t my_thread;
  process_id_t pid;
  int ret;
  pid = 0;

  kprintf("vi er nu i spawn jaaaaa \n");
  //stop disables
  intr_status = _interrupt_disable();
  //spinlock
  spinlock_acquire(&process_table_slock);

  //Find empty spot
  for ( int i = 0; i < PROCESS_MAX_PROCESSES; i++) {
    if (process_table[i].state == STATE_FREE) {
      pid = i;
      break;
    }
  }

  kprintf("vi er nu længere i spawn wuuhuu\n");
  //Spawn new thread in 'process run'
  my_thread = thread_create((void (*)(uint32_t))(&process_run), pid);
  process_table[pid].Thread_ID = my_thread;

  kprintf("fejler spawn ved checket? %d\n",my_thread);
  // Check if thread has been created
  if (!(my_thread >= 0)) {
    kprintf("Her er fejl  spawn my threads er for lille");
    return -1;
  }


  kprintf("lige før setup new process. pid: %d\n",pid);
  kprintf("lige før setup new process. my_thread: %d\n",my_thread);
  kprintf("lige før setup new process. entry_point: %d\n",process_table[pid].entry_point);
  // Attempt to start new process
  ret = setup_new_process(
                          my_thread,
                          executable,
                          argv,
                          &process_table[pid].entry_point,
                          &process_table[pid].stack_top
                          );
  if (ret < 0){
    kprintf("fejl i setup_new_process ret < 0 ret: %d\n",ret);
    return -1;
  }

  /* Unlock the process table */
  spinlock_release(&process_table_slock);
  //enable interrupts
  _interrupt_set_state(intr_status);


  kprintf("retval ved s**t af spawn: %d\n",ret);
   
  thread_run(my_thread);

  return pid;
}