Usage avancé du bash Linux
Job management
Stopping Jobs
-
Type
./sample_job
.-
The program will start running.
-
-
Press Control+C.
-
The program should exit.
-
-
Type
./sample_job sigterm
.-
The program will start running.
-
-
Press Control+C.
-
This time the program will not die.
-
Stopping “Out of Control” Jobs
-
Open a new terminal window.
-
Type
ps ax
. -
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).
-
-
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.
-
-
Type
kill <id>
, where<id>
is the job number you found with theps ax
. -
In the first window, type
./sample_job sigterm sigkill
.-
The program will start running.
-
-
In the second window, type
ps ax | grep sample
to get the id of the process. -
Type
kill <id>
.-
This time, the process will not die.
-
-
Type
kill -SIGKILL <id>
.-
This time the process will exit.
-
Showing Process and Memory usage
-
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.
-
-
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.
-
-
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.
-
-
Press q or Ctrl+C to exit the program.