How to terminate programs on Linux using the kill command

Have you ever encountered a situation where you launch an app and suddenly while using the app it becomes unresponsive and crashes all of a sudden? Then you try to start the app again, but nothing happens because the original app’s process doesn’t actually stop completely.

Yes, this happened to all of us, right? The solution is to forcibly stop any running application processes.

Fortunately, there are several utilities in Linux that allow us to stop erroneous processes.

In this tutorial we will show you how to use the utility kill And the killall To terminate operations on Linux. The main difference between these two tools is that killall Stop processes running by name, in the meantime kill Exit existing processes Process ID number (PID).

Regular users can “kill” their own processes, but not other users’ processes, while the root user can terminate all processes.

kill And the killall It can send a specific signal for a specific process or process group. When used without a signal, both devices will send a signal -15 (-TERM).

The most used signals are:

  • 1 (-HUP): To redo the operation.
  • 9 (-Kill): To kill an operation.
  • 15 (-TERM): Stops the process in a different way.

Signals can be identified in three different ways:

  • Using a number (for example, -1)
  • With the prefix “SIG” (for example, -SIGHUP)
  • Without the “SIG” prefix (for example, HUP).

Use the options -l To see a list of all available bookmarks:

kill -l  # atau killall -l

The steps shown below will work for all Linux distributions.

Stop the operation with a kill order

To terminate a process with the kill command, we first need to find the method PID. We can do this with several different commands such as topAnd the psAnd the pidof And the pgrep

Suppose our Firefox browser becomes unresponsive and we have to end the Firefox process. To find the process PID we can use the command pidof:

pidof firefox

The above command will print all Firefox processes:

2551 2514 1963 1856 1771

Now that we know the PID process in Firefox, we can stop everything by:

kill -9 2551 2514 1963 1856 1771

Or, instead of searching for the PIDs and terminating as mentioned above, you can link and combine multiple PIDs into one:

kill -9 $(pidof firefox)

How to stop all processes with the KillAll command

The killall command terminates all programs that match the specified name.

Using the same previous scenario, we can terminate the Firefox process by typing:

killall -9 firefox

The killall command accepts several options such as specifying a process that is running as the user, using regular expressions and killing new or old processes from a specified time. You can get a list of all options by writing killall (Without any arguments).

For example, if we want to stop all user initiated processes jono, We can run the following command:

killall -u jono

Conclusion

In this tutorial, you learned how to stop an unresponsive program using kill and killall tools.

Source link

Leave a Reply

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