Skip to main content

Usage avancé du bash Linux

Job management

Stopping Jobs

  1. Type ./sample_job.

    • The program will start running.

  2. Press Control+C.

    • The program should exit.

  3. Type ./sample_job sigterm.

    • The program will start running.

  4. Press Control+C.

    • This time the program will not die.

Stopping “Out of Control” Jobs

  1. Open a new terminal window.

  2. Type ps ax.

  3. Scroll up until you find python ./sample_job sigterm.

    • This is the job that is running in the first window.

    • The first field in the table is the ID of the process (use man ps to learn more about the other fields).

  4. Type ps ax | grep sample.

    • You will notice that only a few lines are returned.

    • This is useful if you want to find a particular process

    • Note: this is an advanced technique called “piping”, where the output of one program is passed into the input of the next. This is beyond the scope of this class, but is useful to learn if you intend to use the terminal extensively.

  5. Type kill <id>, where <id> is the job number you found with the ps ax.

  6. In the first window, type ./sample_job sigterm sigkill.

    • The program will start running.

  7. In the second window, type ps ax | grep sample to get the id of the process.

  8. Type kill <id>.

    • This time, the process will not die.

  9. Type kill -SIGKILL <id>.

    • This time the process will exit.

Showing Process and Memory usage

  1. In a terminal, type top.

    • A table will be shown, updated once per second, showing all of the processes on the system, as well as the overall CPU and memory usage.

  2. Press the Shift+P key.

    • This will sort processes by CPU utilization.
      This can be used to determine which processes are using too much CPU time.

  3. Press the Shift+M key.

    • This will sort processes by memory utilization
      This can be used to determine which processes are using too much memory.

  4. Press q or Ctrl+C to exit the program.