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!

Error: Please check your email address.
Rocket to Success - Your 10 Tips for Smarter ERP System Selection
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

SanDisk MicroSDXC™ for Nintendo® Switch™

Learn more >

Breitling Superocean Heritage Chronographe 44

Learn more >

Toys for Boys

Family Friendly

Panasonic 4K UHD Blu-Ray Player and Full HD Recorder with Netflix - UBT1GL-K

Learn more >

Stocking Stuffer

Razer DeathAdder Expert Ergonomic Gaming Mouse

Learn more >

Christmas Gift Guide

Click for more ›

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

Walid Mikhael

Brother QL-820NWB Professional Label Printer

It’s easy to set up, it’s compact and quiet when printing and to top if off, the print quality is excellent. This is hands down the best printer I’ve used for printing labels.

Ben Ramsden

Sharp PN-40TC1 Huddle Board

Brainstorming, innovation, problem solving, and negotiation have all become much more productive and valuable if people can easily collaborate in real time with minimal friction.

Sarah Ieroianni

Brother QL-820NWB Professional Label Printer

The print quality also does not disappoint, it’s clear, bold, doesn’t smudge and the text is perfectly sized.

Ratchada Dunn

Sharp PN-40TC1 Huddle Board

The Huddle Board’s built in program; Sharp Touch Viewing software allows us to easily manipulate and edit our documents (jpegs and PDFs) all at the same time on the dashboard.

George Khoury

Sharp PN-40TC1 Huddle Board

The biggest perks for me would be that it comes with easy to use and comprehensive programs that make the collaboration process a whole lot more intuitive and organic

David Coyle

Brother PocketJet PJ-773 A4 Portable Thermal Printer

I rate the printer as a 5 out of 5 stars as it has been able to fit seamlessly into my busy and mobile lifestyle.

Featured Content

Product Launch Showcase

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?