Join Scott Simpson for an in-depth discussion in this video Process management: ps, part of Linux Tips Weekly.
- [Instructor] On a Linux system, programs run within a process. A process allows us to keep track of a program that's running, and programs can start up sub-processes, or child processes, as they need to. The processes for a particular program are all related and can be managed individually or as a group. A common tool for finding out some information about processes that are running is called PS. If I run PS by itself, I can see the processes that are running inside the shell. Here's the shell, and here's PS. Because when it was running, it had a process of its own.
The columns here start out with the PID, or process ID, the number that the system assigns to new processes. When a process ends, the number it was using is released, and the system can reuse it. Depending on your system, there's different limits for the number of processes that a particular user can start, though the user is generally not constrained within a limit. Every process takes resources though, so there are practical, not just theoretical, limits to how much stuff you can run. The next column is the terminal where a process is running. These are all in PTS one, because that's my pseudo-terminal that I'm running here.
Time is how much time each command has taken so far. And CMD is the command that invoked the process. There's quite a few different options for changing the output and the scope of what's displayed. And I encourage you to take a look through the PS man page for more details. Let's look at a few options here though. I'll start up a series of nested bash shells. PS dash C and a command name will show you the processes that have that command name. I'll use bash, because I know I have a few of those running. And here they are. Combining that with the F option gives a more full listing.
I'll write PS dash F capital C bash. This shows the user ID that started a command and the time that it was started up in addition to the parent process ID. And following through these, I can see that this process is the parent of this one. This process is the parent of this one, and so on. Modifying this can make it a little more helpful, like with the J and H options to make a tree format. I'll write PS dash J capital H C and bash.
Capital H shows a hierarchical listing, and J shows output in the jobs format where we get process group ID and session ID values as well. You can see how that lines up with the groups of processes that are running under other processes or session leaders. The SID, or session ID, is the process ID of the session leader, which is responsible for all the processes, or jobs, underneath it in the tree. We can also take a look at what a particular user is running with the dash U or dash capital U option. Lowercase U shows the effective user, and capital U shows the real user.
Let's see what my user has started here outside of just this shell. Alright, that's a lot of stuff, mostly from my desktop manager and the VirtualBox software. We can make this a little more readable, again, with F for full output, capital H for a hierarchical view, and U and the username. And that gives us a bit more of a picture of what processes are going on for this particular user. I can see all of the processes on a system with PS dash E for everything, which is kind of useful, especially in conjunction with some of the other options we saw earlier, like H for hierarchical view.
PS is often used in conjunction with the kill command which sends interrupt signals to processes. There are various signals that kill can send to a process, some of which request that a process do whatever cleanup it needs to do before exiting or simply requesting that the process do whatever it's designed to do in response to an interrupt signal, which in some cases, doesn't end the process at all. The default signal is called sig term, which asks the process it's sent to to exit. Usually that will work to end a running process unless that process is stuck or, for some other reason, doesn't respond to this polite request.
In that case, we can send a much more forceful signal called sig kill to the process instead, which immediately ends the process without waiting for it to respond. We can take a look at all of the signals available with kill dash lowercase L. Here's sig term, and here's sig kill. To specify the signal to use, we use dash and then the number. So dash nine is sig kill. Let's see what process my shell is here with PS dash capital C bash. Let's go for 2858. That's the parent process for these processes below it.
I'll use kill dash nine to end that process, which will end all of the processes underneath it as well. And there goes my terminal. Using PS to track down a process is a great skill to have, and it can help you gain more insight as to what a system is doing.
Author
Updated
3/2/2021Released
10/3/2017Skill Level Intermediate
Duration
Views
Related Courses
-
Linux: Bash Shell and Scripts
with Kevin Dankwardt2h 46m Intermediate -
Linux: Files and Permissions
with Grant McWilliams1h 49m Intermediate -
Linux: Multitasking at the Command Line
with Scott Simpson39m 1s Intermediate
-
New this Week:
-
Docker on Linux5m 24s
-
-
Introduction
-
Welcome1m 4s
-
-
Foundations
-
Foundations: What's Linux?5m 26s
-
Foundations: Distros10m 50s
-
Foundations: USB installer7m 46s
-
Linux on Azure7m 21s
-
Google Cloud Platform3m 37s
-
Linux on DigitalOcean6m 39s
-
-
System Basics
-
Bash operators6m 55s
-
Logs5m 4s
-
Grub3m 19s
-
SysV init4m 43s
-
Systemd5m 29s
-
Cron8m 7s
-
Understanding chroot3m 16s
-
Backing up data with rsync5m 35s
-
Working with dotfiles1m 43s
-
Exploring the PATH variable3m 51s
-
Finding or locating files3m 52s
-
Working with swap4m 29s
-
Read and write caches3m 5s
-
Filesystem Basics
-
Files on Linux4m 10s
-
File system basics: Archives6m 22s
-
Loop devices4m 35s
-
Overlay file systems4m 17s
-
Bind mounts2m
-
-
Working with Text
-
Working with text: Vim 1015m 15s
-
Working with text: Emacs 1015m 42s
-
Working with text: nano 1015m 29s
-
Working with text: grep4m 23s
-
Working with text: sed7m 24s
-
Working with text: AWK2m 51s
-
Working with text: ed 1016m 17s
-
-
Package Management
-
Package management: Basics6m 59s
-
aptitude5m 43s
-
dpkg2m 20s
-
yum and DNF4m 58s
-
RPM3m 24s
-
Creating your own packages3m 12s
-
Zypper4m 17s
-
Using Flatpak4m 11s
-
Using snaps3m 15s
-
-
Working Remotely
-
Remote files: curl and wget4m 42s
-
SSH: Secure access8m 8s
-
SSH: Tunnels3m 46s
-
X11 forwarding2m 52s
-
Using a SOCKS proxy4m 53s
-
Using a Squid proxy8m 43s
-
-
Process Management
-
Process management: ps4m 30s
-
Process management: top4m 53s
-
Process management: htop6m 11s
-
Customizing tmux3m 32s
-
-
Security
-
Firewall basics4m 5s
-
Understanding iptables6m 41s
-
File checksums3m 48s
-
Encrypting files7m 14s
-
Encrypted filesystems6m 58s
-
AppArmor4m 2s
-
Security systems: SELinux4m 33s
-
-
System Administration
-
Disks and partitions6m 42s
-
Logical volume management9m 59s
-
Create a RAID array9m 10s
-
Repairing a RAID array4m 44s
-
Local IP address5m 15s
-
DNS5m 40s
-
VPN1m 43s
-
Drivers and modules4m 16s
-
Understanding QEMU and KVM2m 49s
-
Private networking6m 37s
-
Routing and forwarding4m 26s
-
DHCP4m 55s
-
Network troubleshooting7m 42s
-
Wi-Fi on Linux4m 14s
-
-
Desktops and Displays
-
Desktops: Basics3m 8s
-
Desktops: GNOME4m 41s
-
Desktops: Xfce4m 5s
-
Desktops: KDE Plasma Desktop2m 28s
-
Desktops: LXQt3m 42s
-
-
Exploration Topics
-
Windows Subsystem for Linux7m 20s
-
Exploring virtualization5m 28s
-
Exploring containers5m 19s
-
Exploring Fedora3m 8s
-
Changing the default shell3m 30s
-
Exploring other shells2m 5s
-
Exploring CentOS2m 6s
-
Exploring Zsh5m 41s
-
Osquery4m 28s
-
Exploring fish5m 21s
-
Exploring csh and tcsh2m 34s
-
Using diff to compare files3m 54s
-
Using xargs3m 41s
-
Job control3m 59s
-
Using watch and time3m 5s
-
Recording a terminal session3m 14s
-
Exploring Debian1m 49s
-
Exploring SUSE Linux7m 33s
-
Exploring Arch Linux16m 44s
-
Exploring Alpine Linux6m 18s
-
Exploring Linux Mint5m 14s
-
Exploring Amazon Linux5m 8s
-
Terminal on the go5m 1s
-
FUSE and SSHFS3m 54s
-
Removing Linux4m 44s
-
WSL distros on Windows 103m 13s
-
Embedded Linux4m 25s
-
Exploring Netboot2m 43s
-
Exploring ZFS3m 53s
-
Troubleshooting Topics
-
Projects
-
Linux on an old PC6m 7s
-
Hosting email services3m 7s
-
Create a network PDF printer4m 37s
-
Remote logging with Rsyslog7m 12s
-
Set up a Git server4m 16s
-
NGINX web server4m 11s
-
Set up an NFS server3m 58s
-
Monitoring your server2m 49s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Process management: ps