CIS120 Linux Fundamentals by Scott Shaper

kill, killall and shutdown Commands

Think of these commands like different ways to turn things off in your home. The kill command is like pressing the power button on a specific device, killall is like using a universal remote to turn off all TVs of the same brand at once, and shutdown is like flipping the main breaker switch for your entire house. Understanding these commands helps you manage programs and your system with precision and control.

Quick Reference

Command What It Does Common Use
kill Sends signals to specific processes using PID Stopping individual misbehaving programs
killall Sends signals to processes by name Stopping all instances of a program at once
shutdown Powers off, reboots, or halts the system Safely shutting down or restarting your computer

When to Use These Commands

The kill Command

Think of the kill command like a remote control that can send different types of signals to a specific program. Although its name suggests termination, kill can actually send various signals to processes, from a gentle request to close to a forceful shutdown.

Each program running on your system has a unique ID number called a PID (Process ID). The kill command uses this ID to target a specific program. It's like having a unique code for each device in your home that lets you control them individually.

Signal What It Does When to Use
-1 (SIGHUP) Hangup signal, can reload configuration When you've changed a program's config file and want it to reload
-2 (SIGINT) Interrupt signal (same as Ctrl+C) When you want to terminate a program normally
-9 (SIGKILL) Kill signal, forces immediate termination When a program is completely frozen and won't respond to other signals
-15 (SIGTERM) Termination signal, requests graceful exit When you want a program to close properly (the default)
-18 (SIGCONT) Continue signal, resumes a stopped process When you want to resume a process you previously paused
-19 (SIGSTOP) Stop signal, pauses the process When you want to temporarily freeze a program without killing it

Practical Examples

# First, find the PID of a process
ps aux | grep firefox

# Gracefully terminate a process (recommended first attempt)
kill -15 1234    # Asks Firefox (PID 1234) to close properly

# If a process won't respond to a normal termination
kill -9 1234     # Forces Firefox to close immediately, may lose unsaved data

# Temporarily pause a process
kill -19 1234    # Freezes Firefox without closing it

# Resume a paused process
kill -18 1234    # Continues a previously paused Firefox

# Reload a process configuration without restarting
kill -1 1234     # Tells Firefox to reload its configuration

The killall Command

Think of the killall command like having a remote that can control all devices of the same type at once. Instead of needing to know each process's ID number, you can simply specify the program name, and killall will affect all running instances of that program.

This is particularly useful when you have multiple copies of the same program running, or when you don't want to look up the specific PID. It's like saying "turn off all the lights" instead of turning off each light individually.

Option What It Does When to Use
-i Interactive mode, asks for confirmation When you want to be extra careful about what you're closing
-I Case-insensitive process matching When you're not sure about the exact capitalization of the process name
-u user Only kill processes owned by specific user When you want to target only a specific user's programs
-w Wait for processes to die When you need to make sure processes have actually terminated

Practical Examples

# Close all Firefox windows at once
killall firefox   # Gracefully closes all Firefox processes

# Force close all instances of a program that's not responding
killall -9 firefox   # Force closes all Firefox processes immediately

# Close all instances of a program for a specific user
killall -u username firefox   # Closes Firefox only for a specific user

# Kill processes with confirmation
killall -i firefox   # Asks before closing each Firefox process

# Kill all processes matching a name, regardless of case
killall -I firefox   # Matches firefox, Firefox, FIREFOX, etc.

The shutdown Command

Think of the shutdown command like the master power controls for your entire computer. It allows you to turn off, restart, or halt your system safely, making sure all programs have a chance to save their data and close properly before the power goes off.

The shutdown command can also schedule a shutdown for later, which is like setting a timer on your home's main power. This gives you and other users time to save work and exit programs before the system turns off.

Note: You will not have permissions to shutdown the Cidermill server in your class environment.

Option What It Does When to Use
-h Halts or powers off the system When you're done using the computer and want to turn it off
-r Reboots the system When you need to restart the computer, like after updates
-c Cancels a scheduled shutdown When you no longer need to shut down at the scheduled time
+m Schedules shutdown in m minutes When you want to give users time to save work and log out
now Executes shutdown immediately When you need to shut down without delay

Practical Examples

# Shut down the system immediately
shutdown -h now   # Turns off computer right away

# Reboot the system immediately
shutdown -r now   # Restarts computer right away

# Schedule a shutdown in 15 minutes with a warning message
shutdown -h +15 "System maintenance scheduled. Please save your work."   # Notifies all users

# Cancel a previously scheduled shutdown
shutdown -c   # Stops the countdown to shutdown

# Schedule a reboot at a specific time
shutdown -r 23:00   # Restarts the computer at 11:00 PM

# Alternate way to reboot
reboot   # Same as shutdown -r now

Tips for Success

Common Mistakes to Avoid

Best Practices