コード例 #1
0
    /**
     * Start running user programs, by creating a process and running a shell
     * program in it. The name of the shell program it must run is returned by
     * <tt>Machine.getShellProgramName()</tt>.
     *
     * @see	nachos.machine.Machine#getShellProgramName
     */
    public void run() {
	super.run();

	UserProcess process = UserProcess.newUserProcess();
	
	String shellProgram = Machine.getShellProgramName();	
	Lib.assert(process.execute(shellProgram, new String[] { }));

	KThread.currentThread().finish();
    }
コード例 #2
0
ファイル: UserProcess.java プロジェクト: twistedmove/cs162-1
  /*
   * if the input arguments are negative, return -1
   * @return the child process Id
   */
  private int handleExec(int file, int argc, int argv) {
    if (file < 0 || argc < 0 || argv < 0) {
      return -1;
    }
    String fileName = readVirtualMemoryString(file, 256);

    if (fileName == null) {
      return -1;
    }

    String args[] = new String[argc];

    int byteReceived, argAddress;
    byte temp[] = new byte[4];
    for (int i = 0; i < argc; i++) {
      byteReceived = readVirtualMemory(argv + i * 4, temp);
      if (byteReceived != 4) {
        return -1;
      }

      argAddress = Lib.bytesToInt(temp, 0);
      args[i] = readVirtualMemoryString(argAddress, 256);

      if (args[i] == null) {
        return -1;
      }
    }
    UserProcess child = UserProcess.newUserProcess();
    childProcess newProcessData = new childProcess(child);
    child.myChildProcess = newProcessData;

    if (child.execute(fileName, args)) {
      map.put(child.process_id, newProcessData);
      return child.process_id;
    }

    return -1;
  }