/**
   * Returns the process which is bound to the given address. This returns null if there isn't any
   * process with the given binding.
   *
   * @param binding The address to inspect.
   * @return The process which binds itself to the given address.
   */
  public Process getProcess(Address binding) {

    for (Process process : getAllProcesses()) {
      if (process.getExecutor().getPacketListener(binding) != null) {
        return process;
      }
    }

    return null;
  }
  /**
   * Calculates and returns a new pid for a new process.
   *
   * @return The calculated pid.
   */
  public synchronized int requestPid() {

    List<Integer> pids = new ArrayList<Integer>();
    for (Process process : getAllProcesses()) {
      pids.add(process.getPid());
    }
    int pid = 0;
    while (pids.contains(pid)) {
      pid++;
    }
    return pid;
  }
  /**
   * Returns a list of all current running processes.
   *
   * @return A list of all current running processes.
   */
  public List<Process> getAllProcesses() {

    List<Process> processes = new ArrayList<Process>();
    processes.add(rootProcess);
    processes.addAll(rootProcess.getAllChildren());
    return processes;
  }
  @Override
  public int hashCode() {

    final int prime = 31;
    int result = 1;
    result = prime * result + (rootProcess == null ? 0 : rootProcess.hashCode());
    return result;
  }
  /**
   * Changes the running state of the process manager.
   *
   * @param running True if the process manager is running, false if not.
   */
  public void setRunning(boolean running) {

    if (running) {
      rootProcess =
          new Process(
              host, null, 0, host.getFileSystemManager().getFile("C:/system/boot/kernel"), null);
    } else {
      rootProcess.interrupt(true);
    }
  }
  @Override
  public boolean equals(Object obj) {

    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    ProcessManager other = (ProcessManager) obj;
    if (rootProcess == null) {
      if (other.rootProcess != null) {
        return false;
      }
    } else if (!rootProcess.equals(other.rootProcess)) {
      return false;
    }
    return true;
  }