I think managing processes in Linux is essential for Linux admins because process control equals server control. I decided to put together real-world commands and examples for future reference. First, I had to read some Specialty Coffee news to keep up to date about what’s going on in the coffee world.

Run Jobs in the Foreground and Background

By default, commands run in the foreground (blocking your terminal). For example, if you:

ping yakahu.com

You can’t type anything else until you stop it (Ctrl+C).

Run in background ( & ):

ping google.com > ping.log &

Keeps running in the background. Output saved to ping.log

List background jobs: (cool command)

jobs

Bring job to foreground:

fg %1

Send job to background:

bg %1

Signal a Program to Continue Running After Logout

Normally, background jobs stop when you log out. Use nohup or disown.

nohup ping google.com > ping.log 2>&1 &

nohup = “no hangup,” keeps process alive after logout.

2>&1 meaning:

This one confuses people, but it’s simple.

  • 2 = standard error (stderr)
  • 1 = standard output (stdout)

2>&1 means:

“Send error messages to the same place as normal output.”

So both outputs land in the same file: ping.log.

OR if you already started a job, detach it:

disown %1

Real-life example: Run a backup overnight and disconnect from SSH.

Monitor Active Processes

ps (snapshot of processes):

ps aux | less
  • a = all users
  • u = user-oriented format
  • x = processes without a terminal

How to find a specific process? For example if you want to find all sshd running processes:

ps aux | grep sshd

top (live monitoring):

top or htop(you may need to install it)
  • Press M → sort by memory
  • Press P → sort by CPU

Exit with q.

Sort processes by memory usage:

ps aux --sort=-%mem | head -n 10

Sort by CPU usage:

ps aux --sort=-%cpu | head -n 10

Send Signals to Processes

Every process has a PID (process ID). Use kill to send signals. List signals:

kill -l

You should get a list similar to this:

1) SIGHUP	 2) SIGINT	 3) SIGQUIT	 4) SIGILL
5) SIGTRAP 6) SIGABRT 7) SIGEMT 8) SIGFPE
9) SIGKILL 10) SIGBUS 11) SIGSEGV 12) SIGSYS
13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGURG
17) SIGSTOP 18) SIGTSTP 19) SIGCONT 20) SIGCHLD
21) SIGTTIN 22) SIGTTOU 23) SIGIO 24) SIGXCPU
25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH
29) SIGINFO 30) SIGUSR1 31) SIGUSR2

Most common signals:

  • SIGTERM (15) – ask process to exit gracefully
  • SIGKILL (9) – force kill immediately
  • SIGHUP (1) – reload configuration

Gracefully stop Apache

sudo kill -15 $(pidof apache2)

Force kill a stuck process:

sudo kill -9 1425

(where 1234 is the PID from ps or top)

Reload a service config without restarting:

kill -HUP $(pidof syslogd)

Linux Process Real-Life Scenarios

Run a backup in the background overnight:

nohup rsync -av /home /backup & disown

Find and kill a runaway process eating 100% CPU:

ps aux --sort=-%cpu | head -n 5
kill -9 <PID>

Monitor a webserver process in real time:

top -p $(pidof nginx)

If the above gives you an error, try this one instead:

top -p $(pidof nginx | awk '{print $1}')

Gracefully stop a database server:

kill -15 $(pidof mysqld)

How do i kill the Linux process i started with nohup?

Processes started with nohup don’t automatically tie back to your shell’s job list, so jobs and fg/bg won’t see them.
You’ll need to find the PID (process ID) and kill it manually. So, If you started:

nohup ping google.com > ping.log 2>&1 &

You can check with:

ps aux | grep ping

Example output:

paco   3351  0.0  0.1  12345  678 ?   S   11:35   0:00 ping yakahu.com

In this case 3351 is the PID.

Or you can grab the Linux process more directly using:

pidof ping

Kill the Linux process

Now that you know the process ID you can run:

kill -15 3351

-15 = SIGTERM (ask politely to stop).

If it refuses. Run this one to force it!

kill -9 3351

-9 = SIGKILL (force kill).

Verify the process is NOT running anymore: (Very important!):

ps aux | grep ping

or you can run:

pidof ping

If you want nohup to leave a PID file automatically (useful for cleanup), you can do:

nohup ping yakahu.com > ping.log 2>&1 & echo $! > ping.pid

Later you can kill it with:

kill -15 $(cat ping.pid)

Managing processes in Linux is crucial for daily work as a SysAdmin. If you like my brief tutorial consider supporting me by shopping one of my T-shirt and coffee mugs designs.

Leave a comment

Your email address will not be published. Required fields are marked *