Welcome Guest | Sign In
LinuxInsider.com

Take Command of Your Linux System's Processes

By Jonathan Terrasi
Apr 5, 2017 10:16 AM PT
linux-operating-system-management

Who's afraid of the Linux terminal? Not you, if you've gotten your feet wet and learned the basics of navigating your system. But how will these newly acquired skills help improve your computing life?

To give you a sense of the terminal's everyday usefulness, here are some examples of tasks the terminal is well-disposed to handle, drawn from my own experience.

Face Your Daemons

To start with, system administration is much more straightforward on the terminal. While you probably don't directly interact with them very much, the operating system manages silent background services, or "daemons," in order to keep your computer's many programs running seamlessly.

The daemons running in the background are managed by systemd, a core Linux program that directs your system's services once it takes over at the end of the boot process. Although there is a graphical user interface (or "GUI") for systemd, the command line tools provide the granular control you want.

Starting and stopping services with the "systemctl" command is way easier than clicking through menus, scrolling through countless services, and confirming your action. With a single "systemctl" command, you can stop, start and restart services, view their configurations, or list them by their operating state.

So why would you ever have to mess with systemd? There are many possible cases, but the one you're most likely to encounter as a desktop user is managing networking (i.e., Internet) services.

Stay Connected

As mature as Linux's networking services are, they're not perfect, and sometimes they lose track of the signal and need to be restarted to pick it back up. For instance, sometimes NetworkManager will drop my connection (especially when the signal is weak) and not reconnect. The service likely needs to restart, but there's no menu item in NetworkManager's GUI to restart it, so instead I pop open a terminal and use "systemctl" to restart the service.

$ systemctl restart NetworkManager

The service then reloads all its configuration files and makes a fresh connection.

Make It Work

Troubleshooting system interfaces or hardware is best handled from the terminal as well. With it, you can access the kernel log using the "dmesg" command and sift through the output for error messages.

$ dmesg

For example, let's say you plugged in an old USB flash drive and it wasn't showing up in your file browser. You don't know whether your operating system just isn't registering it or whether the USB is broken.

Checking the kernel log will provide all the information you need to figure out exactly what went wrong. After running the $ dmesg command, scroll to the bottom. If you see your kernel acknowledge your flash drive, then your operating system or file browser is the culprit -- but if there's no entry, your flash drive's hardware is likely to blame.

End the Freeze

The terminal is the only reliable way to deal with processes, especially frozen ones. Every program running on your computer -- whether initiated by the user or run automatically by the system itself (as root) -- is represented as a process, and each process can be modified individually.

While many modern Linux desktops have a graphical dialog box that appears when processes don't respond, they don't always function properly, leaving the command line as your only recourse.

The safest approach is to look up the process with "ps" and scan the output for the rogue program.

$ ps -aux

The "-aux" here is just a set of useful options for "ps" -- when using multiple single-letter options for a command, you can use one "-" and put them next to each other.

Once you run this command, locate the target process and look in the PID column for the Process ID number. With it, you can kill the process with the aptly named "kill" command by giving the PID as an argument.

$ kill PID

This should work, but if the process is really stubborn, you can pull out the big guns, the "-9" option, sending the strictest termination signal.

$ kill -9 PID

I have had to resort to process killing (though, thankfully, rarely with "-9") more than once when Google Chrome has crashed while trying to display an unwieldy flash video. However, once I execute the kill, the process terminates cleanly, and I can open Chrome with a fresh start.

Check Your DNS

Addressing networking problems is often more effective via the terminal, too. Opening a browser and trying to reach a website is a good enough test sometimes, but it is not very scientific or thorough.

Using "ping" to check with a publicly facing server is the most accurate way to test your connection. Just supply "ping", the "-c" option with "4" for its argument, and a server that acknowledges ping requests (in this case, google.com).

$ ping -c 4 google.com

The above command will send four ICMP packets, a kind of diagnostic message, to Google, and all will be acknowledged as received if your connection is up. If that doesn't work, try using Google's IP address, 8.8.8.8, instead.

$ ping -c 4 8.8.8.8

This sends four packets to Google's public DNS server. If this works when the preceding command failed, it's likely your DNS is not working properly.

In a nutshell, DNS is the Internet's address book, as your computer can access websites only by IP address, and doesn't know which one corresponds to which URL until it consults a DNS server (or resolves it in some other way).

A few months ago, the Internet seemingly went out on the U.S. East Coast, but in reality malicious actors had taken a major ISP's DNS servers out of commission. In a situation like this, the two-step diagnostic outlined above would allow you to confirm DNS as the weak link, rather than a failure of your system, whereas trying out the browser would not.

Choose Your Format

Finally, using the "imagemagick" suite of tools, the terminal is by far the simplest, most versatile image format converter I have ever used. With a single command, you can merge multiple files and change their format simultaneously.

For example, one command I recently used combined separate JPG screenshots into a single PDF, which was as simple as invoking "convert" and giving the original files and the new filename (with the PDF extension) as arguments.

$ convert image1.jpg image2.jpg combined.pdf

I once had to submit income statements for a job that paid me exclusively through PayPal, so I took screenshots of each month's transaction log and ran convert to combine them into a single PDF, creating neat documentation.

This is only a small sampling of the many tasks that the terminal is well-suited for, but I hope that it gives you an idea of the incredible power it affords you. If any of these use cases interest you, go ahead and investigate possibilities for yourself. You'll be amazed not just by what you'll find, but how little you won't!


Jonathan Terrasi has been an ECT News Network columnist since 2017. His main interests are computer security (particularly with the Linux desktop), encryption, and analysis of politics and current affairs. He is a full-time freelance writer and musician. His background includes providing technical commentaries and analyses in articles published by the Chicago Committee to Defend the Bill of Rights.


Facebook Twitter LinkedIn Google+ RSS
What's most likely to cost a company your customer loyalty?
a major product fail
major unethical corporate behavior
public advocacy of social or political views I oppose
a really bad customer service experience
stagnation -- I'm attracted to innovation
none of the above -- I'll stick through thick and thin