Process management with Linux

In this column, we examine some tools to assist with process management. Essentially, a process is a program running in a Linux system, and process management is the task of looking after the running processes. Normally a user would not have to worry about process management, but what happens if a program locks up, using all of the CPU, or if your system runs out of memory? This is where process management can help you improve the performance of your system and avoid unnecessary reboots.

The ps and top commands

The ps command displays a list of running processes and some statistics on their use of system resources. A large number of filters can be applied to the ps command to display different information and to set the scope of processes to be listed.

To try out the ps command, open a shell and type the following commands:

$ ps

$ ps aux

The first command will show a list of running processes belonging to the current user (i.e., you). This list will be quite short and only contain the process id (PID) and the process name. The PID is a unique number assigned to each process and is used to control the process with some of the tools we will examine further down.

The second command will show a much more detailed list containing a much larger number of processes. It covers all of the processes currently running in your Linux system and information listings report on system areas such as the current CPU and memory usage. This command is very helpful when looking for programs that hog memory or CPU time.

The top command provides a live interactive interface to the list of running processes, the format of which is very similar to that of ps aux. The top command refreshes statistics on the state of processes in your system every couple of seconds. To try it, in a shell type:

$ top

The screen displayed will show the overall state of your system on the first two lines and a list underneath of processes ordered by highest CPU usage. You can reorder this list by highest memory usage by pressing <M>; to return to ordering by CPU usage, press <C>. With the top command running you can observe the internals of your running system. Try moving your mouse around, or loading a Web page - notice how the X server process will suddenly jump in usage while the task is being carried out and then drop back down when it is completed?

The kill command

Now that you have spent some time observing processes running, it's time to look at the management side of process management. The kill command can be used in conjunction with a process's PID to end a currently running process, which can be very handy if a running program that uses a lot of your CPU suddenly locks up. To free up your system, first look up the process using ps or top, and then kill it using the kill command followed by the PID. For example, if your Web browser has gone haywire and is not responding, type:

$ ps aux | grep mozilla

which outputs:

od 17007 99.9 8.7 82592 56264 ? S 09:35 0:00 mozilla-bin

You can see the CPU usage for mozilla-bin is 99.9 per cent of the CPU. To kill Mozilla, type:

$ kill 17007

The first line pipes the ps output into the grep command, which filters the ps output to only display lines containing "mozilla". This makes it much easier to locate the PID for a process. The second instruction issues a kill command to the mozilla process. Sometimes, however, a process will not respond to the kill command and will refuse to end. To force a program to end, add the "-9" switch to your kill command:

$ kill -9 17007

This command gives the process no choice and forces it to exit immediately - however, it may damage the program as it will not have a chance to exit cleanly, saving configuration files, etc. In most cases, the "-9" switch should only be used as a last resort.

Join the newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Alastair Cousins

PC World
Show Comments

Cool Tech

Toys for Boys

Family Friendly

Stocking Stuffer

SmartLens - Clip on Phone Camera Lens Set of 3

Learn more >

Christmas Gift Guide

Click for more ›

Brand Post

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

Aysha Strobbe

Microsoft Office 365/HP Spectre x360

Microsoft Office continues to make a student’s life that little bit easier by offering reliable, easy to use, time-saving functionality, while continuing to develop new features that further enhance what is already a formidable collection of applications

Michael Hargreaves

Microsoft Office 365/Dell XPS 15 2-in-1

I’d recommend a Dell XPS 15 2-in-1 and the new Windows 10 to anyone who needs to get serious work done (before you kick back on your couch with your favourite Netflix show.)

Maryellen Rose George

Brother PT-P750W

It’s useful for office tasks as well as pragmatic labelling of equipment and storage – just don’t get too excited and label everything in sight!

Cathy Giles

Brother MFC-L8900CDW

The Brother MFC-L8900CDW is an absolute stand out. I struggle to fault it.

Luke Hill

MSI GT75 TITAN

I need power and lots of it. As a Front End Web developer anything less just won’t cut it which is why the MSI GT75 is an outstanding laptop for me. It’s a sleek and futuristic looking, high quality, beast that has a touch of sci-fi flare about it.

Emily Tyson

MSI GE63 Raider

If you’re looking to invest in your next work horse laptop for work or home use, you can’t go wrong with the MSI GE63.

Featured Content

Product Launch Showcase

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?