Copyright

Practical Application for Operating Systems: Managing Processes in Linux

Instructor: Sebastian Garces

Sebastian has taught programming and computational thinking for University students and has Master's degree in Computer and Information Technology

In this lesson, you will learn some basic commands along with their associated flags in the Linux terminal to list running processes and how to manage them.

Lesson Description

In this lesson, you will learn some basic commands along with their associated flags in the Linux terminal to list running processes and how to manage them.

Lesson Overview & Knowledge Required

In this lesson, you will execute different Linux terminal commands to check running processes, identify the resources that are being used, and learn how to handle these processes. The knowledge and skills required to complete this lesson are:

  • Bash terminal
  • Computer resources
  • Command Flags

Program Code

To begin, it is important you know that the Linux terminal is equipped with manuals for every command you need to use. To understand what a command does or what the possible combination of flags are (e.g. -f -h), you can refer to these manuals. To access a manual, you can type man and the command you need to check. For example, let's check the manual for 'Process Status' (ps):

man ps

Note: You can press the Q key to leave the manual.

This will print the complete instruction manual and all the flags that can be used with the command.

The first thing you need to do is list all the different processes running on the machine. To do so, you can use the following command (case sensitive):

ps -A

This command will print all the processes running at the moment, giving you the process ID (PID), the active command terminal that is running the process (TTY), the time the process has been using the CPU (TIME), and the command that is running in the process (CMD).

To get more details of the running processes, you can always use the -f flag (full detail). This can be done in one of these two ways:

ps -A -f

or

ps -Af

Either way you run it, the result is the same. This should list:

  • The user who started the process (UID)
  • The process ID (PID)
  • The ID of the parent process (PPID)
  • The number of children processes (C)
  • The time the process was started (STIME)
  • The active command terminal that is running the process (TTY)
  • The time the process has been using the CPU (TIME)
  • The command that is running in the process (CMD)

Another command that will help with process management is pstree. This command, similar to 'ps', will print the running processes but in a tree structure, making it easier to identify parents and children. This is helpful when you need to stop a whole bunch of related processes. Before you can stop these processes, you need to identify the parent process first. To do this, execute the following command:

pstree

If you want a more comprehensive view of how processes are using machine resources, you can access the interactive resources monitor by executing the top command.

Since top is interactive, you can execute several options from that screen like searching and signaling processes. You can use the top command, for example, to identify a process that is taking too much memory and send a terminate signal to it (press ? while in top for help).

Open the interactive resource monitor by typing the command:

top

Code Application

So far, we have identified different ways to list and monitor system processes. Now that we can get this information, we can start signaling them. Signals are a way to manage processes, some of the most common being quit, abort, terminate or kill. When you want to force a process to end, always use the kill command, also known as signal 9.

To do this, first open any program of your preference in the computer. Identify the PID of that program and send a kill signal using the command the 'kill' command. For usage of the kill command, you can check the on-line manual (man from the console) for kill.

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support