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

Brand Post

Bitdefender 2018

Secure and Save before time runs out with Bitdefender Exclusive Clearance Offer! Get Bitdefender Total Security 2018 Now!

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

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.

Laura Johnston

MSI GS65 Stealth Thin

If you can afford the price tag, it is well worth the money. It out performs any other laptop I have tried for gaming, and the transportable design and incredible display also make it ideal for work.

Andrew Teoh

Brother MFC-L9570CDW Multifunction Printer

Touch screen visibility and operation was great and easy to navigate. Each menu and sub-menu was in an understandable order and category

Louise Coady

Brother MFC-L9570CDW Multifunction Printer

The printer was convenient, produced clear and vibrant images and was very easy to use

Edwina Hargreaves

WD My Cloud Home

I would recommend this device for families and small businesses who want one safe place to store all their important digital content and a way to easily share it with friends, family, business partners, or customers.

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.

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?