Working with Processes
As a developer, you are already intuitively familiar with processes. They are the fruits of your labor: after writing and debugging code, your program finally executes, transforming into a beautiful operating system process!
A process on Linux can be a long-running application, a quick shell command like ls
, or anything that the kernel spawns to do some work on the system. If something is getting done in Linux, a process is doing it. Your web browser, text editor, vulnerability scanner, and even things like reading files and the commands you’ve learned so far all spawn a process.
Linux’s process model is important to understand because the abstraction it gives you – the Linux process – is what all the commands and tools you’ll use to manage processes depend on. Gone are the details you’re used to seeing from a developer’s perspective: variables, functions, and threads have all been encapsulated as “a process.” You’re left with a different, external set of knobs to manipulate and gauges to check: process ID, status, resource usage, and all the other process attributes we’ll be covering in this chapter.
First, we’ll take a close look at the process abstraction itself, and then we’ll dive into useful, practical things you can do with Linux processes. While we’re covering the practical aspects, we’ll pause to add detail to a few aspects that are a common source of problems, like permissions, and give you some heuristics for troubleshooting processes.
In this chapter, you’ll learn about the following topics:
- What a Linux process is, and how to see the processes currently running on your system
- The attributes a process has, so you know what information you can gather while troubleshooting
- Common commands for viewing and finding processes
- More advanced topics that can come in handy for a developer actually writing programs that execute as Linux processes: Signals and inter-process communication, the
/proc
virtual filesystem, seeing open file handles with thelsof
command, and how processes are created in Linux
You’ll also get a practical review of everything you’ve learned in an example troubleshooting session that uses the theory and commands we cover in this chapter. Now, let’s dive into what exactly a Linux process is.