# Usage avancé du bash Linux

### Job management

#### Stopping Jobs

<div class="section" id="bkmrk-type-.%2Fsample_job.-t"><div class="section"><div class="section" id="bkmrk-type-.%2Fsample_job.-t-1">1. Type `<span class="pre">./sample_job</span>`.
    
    
    - The program will start running.
2. Press Control+C.
    
    
    - The program should exit.
3. Type `<span class="pre">./sample_job</span> <span class="pre">sigterm</span>`.
    
    
    - The program will start running.
4. Press Control+C.
    
    
    - This time the program will not die.

</div></div></div>#### Stopping “Out of Control” Jobs

<div class="section" id="bkmrk-open-a-new-terminal-"><div class="section"><div class="section" id="bkmrk-open-a-new-terminal--1">1. Open a new terminal window.
2. Type `<span class="pre">ps</span> <span class="pre">ax</span>`.
3. Scroll up until you find `<span class="pre">python</span> <span class="pre">./sample_job</span> <span class="pre">sigterm</span>`.
    
    
    - This is the job that is running in the first window.
    - The first field in the table is the ID of the process (use `<span class="pre">man</span> <span class="pre">ps</span>` to learn more about the other fields).
4. Type `<span class="pre">ps</span> <span class="pre">ax</span> <span class="pre">|</span> <span class="pre">grep</span> <span class="pre">sample</span>`.
    
    
    - 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 `<span class="pre">kill</span> <span class="pre"><id></span>`, where `<span class="pre"><id></span>` is the job number you found with the `<span class="pre">ps</span> <span class="pre">ax</span>`.
6. In the first window, type `<span class="pre">./sample_job</span> <span class="pre">sigterm</span> <span class="pre">sigkill</span>`.
    
    
    - The program will start running.
7. In the second window, type `<span class="pre">ps</span> <span class="pre">ax</span> <span class="pre">|</span> <span class="pre">grep</span> <span class="pre">sample</span>` to get the id of the process.
8. Type `<span class="pre">kill</span> <span class="pre"><id></span>`.
    
    
    - This time, the process will not die.
9. Type `<span class="pre">kill</span> <span class="pre">-SIGKILL</span> <span class="pre"><id></span>`.
    
    
    - This time the process will exit.

</div></div></div>#### Showing Process and Memory usage

<div class="section" id="bkmrk-in-a-terminal%2C-type-"><div class="section"><div class="section" id="bkmrk-in-a-terminal%2C-type--1">1. In a terminal, type `<span class="pre">top</span>`.
    
    
    - 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.

</div></div></div>