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 PC World newsletter!

Error: Please check your email address.

Our Back to Business guide highlights the best products for you to boost your productivity at home, on the road, at the office, or in the classroom.

Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Alastair Cousins

PC World
Show Comments

Most Popular Reviews

Latest News Articles

Resources

PCW Evaluation Team

Azadeh Williams

HP OfficeJet Pro 8730

A smarter way to print for busy small business owners, combining speedy printing with scanning and copying, making it easier to produce high quality documents and images at a touch of a button.

Andrew Grant

HP OfficeJet Pro 8730

I've had a multifunction printer in the office going on 10 years now. It was a neat bit of kit back in the day -- print, copy, scan, fax -- when printing over WiFi felt a bit like magic. It’s seen better days though and an upgrade’s well overdue. This HP OfficeJet Pro 8730 looks like it ticks all the same boxes: print, copy, scan, and fax. (Really? Does anyone fax anything any more? I guess it's good to know the facility’s there, just in case.) Printing over WiFi is more-or- less standard these days.

Ed Dawson

HP OfficeJet Pro 8730

As a freelance writer who is always on the go, I like my technology to be both efficient and effective so I can do my job well. The HP OfficeJet Pro 8730 Inkjet Printer ticks all the boxes in terms of form factor, performance and user interface.

Michael Hargreaves

Windows 10 for Business / Dell XPS 13

I’d happily recommend this touchscreen laptop and Windows 10 as a great way to get serious work done at a desk or on the road.

Aysha Strobbe

Windows 10 / HP Spectre x360

Ultimately, I think the Windows 10 environment is excellent for me as it caters for so many different uses. The inclusion of the Xbox app is also great for when you need some downtime too!

Mark Escubio

Windows 10 / Lenovo Yoga 910

For me, the Xbox Play Anywhere is a great new feature as it allows you to play your current Xbox games with higher resolutions and better graphics without forking out extra cash for another copy. Although available titles are still scarce, but I’m sure it will grow in time.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?