WCC logo

CIS120Linux Fundementals

kill, killall and shutdown Commands

In Linux, controlling processes and managing system shutdowns are crucial for maintaining system stability and performance. The kill, killall, and shutdown commands are essential tools for these tasks. Understanding these commands and their options allows administrators to effectively manage processes and system power states.

The kill Command

The kill command is used to send signals to processes, typically to terminate them. Each process in Linux has a unique process ID (PID), and the kill command uses this PID to target specific processes. While kill can send various signals, it is most commonly used to terminate processes.

Basic usage of kill:

kill [options] <PID>

Commonly Used kill Signals:

Signal Description Example Command
1 SIGHUP - Hangup kill -1 <PID>
2 SIGINT - Interrupt from keyboard kill -2 <PID>
9 SIGKILL - Kill signal kill -9 <PID>
15 SIGTERM - Termination signal kill -15 <PID>
18 SIGCONT - Continue if stopped kill -18 <PID>
19 SIGSTOP - Stop process kill -19 <PID>

Examples:

To gracefully terminate a process with PID 1234:

kill -15 1234

To forcefully terminate a process with PID 1234:

kill -9 1234

To stop a process with PID 1234 without terminating it:

kill -19 1234

To continue a stopped process with PID 1234:

kill -18 1234

The killall Command

The killall command is used to send signals to multiple processes by name rather than by PID. This command is useful when you need to terminate all instances of a specific process.

Basic usage of killall:

killall [options] <process_name>

Examples:

To gracefully terminate all instances of the nano editor:

killall -15 nano

To forcefully terminate all instances of the firefox browser:

killall -9 firefox

The shutdown Command

The shutdown command is used to bring the system down in a safe way. It allows administrators to power off, reboot, or halt the system. The shutdown command can schedule a shutdown for a specified time or immediately.

NOTE: You will not have permissions to shutdown the Cidermill server.

Basic usage of shutdown:

shutdown [options] [time] [message]

Common shutdown Options:

Option Description Example Command
-h Halt the system shutdown -h now
-r Reboot the system shutdown -r now
-c Cancel a scheduled shutdown shutdown -c
+m Schedule shutdown in m minutes shutdown -h +10 "System update"

Examples:

To shut down the system immediately:

shutdown -h now

To reboot the system immediately:

shutdown -r now

To schedule a shutdown in 15 minutes with a message:

shutdown -h +15 "System will shut down in 15 minutes"

To cancel a scheduled shutdown:

shutdown -c

You can also reboot the systerm using reboot

reboot

Summary

The kill, killall, and shutdown commands are essential tools for managing processes and system power states in Linux. The kill command allows for sending various signals to processes using their PIDs, while killall targets processes by name. The shutdown command provides options for halting, rebooting, or scheduling system shutdowns. By mastering these commands and their options, administrators can effectively control processes and manage system shutdowns, ensuring system stability and performance.