We discussed what a process is when we introduced Operating Systems concepts. Below you will see a reference to PID - Process ID. This is an integer that uniquely identifies the process to the OS. As a user, you use the PID to specify which process you are talking about.
Run the following:
ps
top # (Mac/Linux only) hit q or Control+C to quit the program.
ps
- Report a snapshot of current processestop
- (Mac/Linux only) Display processes and how much memory or CPU they are using. Similar to the Activity Monitor on Mac and the Task Manager on Windows. Hit q
to exit.Control+C
to kill/quit the current process.kill
- Send a signal to a processWe are going to install Python and create a wild task.
Open a second Termina by clicking the +
button next to the tab in the menu of the current Terminal. You should see a second “fresh” terminal pane.
Now run python3
or python
and create the following infinite loop. You can also do this in IDLE or other editor if having trouble running python from the command line.
while True:
print("hello there")
We should now have an out of control Python process gobbling up CPU cycles.
Switch back to the other Terminal tab and run the following commands.
ps
top # (Mac/Linux only) find the PID of the python process that is gobbling all the CPU
# If using Windows, open the Task Manager program
kill <PID> # Replace <PID> with the actual process ID
The terminal will not say anything, but run top
again. The runaway Python process should be gone. Switch back to the Terminal tab where you had that Python process and it should say terminated
or something similar.
Anything you can do with your OS’s GUI, you can do on the command line. It just looks different. Become comfortable with the CLI – you will find that it can be MUCH faster for certain tasks, and will be indispensable to you as a software engineer.
less
.