Kill Processes in Linux using Fkill


The "Fkill" command is a versatile and user-friendly command-line tool that simplifies the process of managing and terminating processes on the system. Its intuitive interface has made it easier for you to interactively and terminate processes, thus enabling you to efficiently troubleshoot and maintain the system.

One of the unique features of Fkill that we find particularly helpful is its ability to terminate processes either by their name or port number. This feature has helped you to identify and terminate stubborn processes that have refused to close, resulting in smoother system performance.

However, we exercise caution while using Fkill's "force" option as it terminates all running processes. This option is a powerful tool that can help resolve system issues but can also cause data loss and system instability. Hence, we use this option only when necessary and ensure that you back up your important data before using it. If you want to install it then you can use this command in Linux:

sudo npm install -g fkill-cli

By executing this command you will see output like this

[sudo] password for username: 
/usr/bin/fkill -> /usr/lib/node_modules/fkill-cli/index.js
/usr/lib/node_modules/fkill-cli
├── cli-spinners@2.5.0
├── columnify@1.5.4
├── find-process@1.3.2
├── get-stdin@5.0.1
├── inquirer@8.2.0
├── meow@9.0.0
├── object-assign@4.1.1
├── osx-temperature-sensor@2.0.1
├── pify@6.0.0
├── process-exists@1.0.1
├── semver@7.3.5
├── strip-ansi@7.0.1
└── supports-color@8.0.0
+ fkill-cli@7.0.2
updated 1 package in 5.376s

After successfully installing "fkill", if we want to run it in the terminal then write the "fkill" command. This will open a display that shows all the running processes on the system. To select a particular process that we want to terminate, then arrow keys can be used to navigate through the list, while a spacebar can be used to select a process. To select multiple processes, the spacebar can be pressed repeatedly. At last, press the enter key to terminate the selected processes.

Let's explore some examples to gain a better understanding of how to use "fkill" effectively.

Example 1: Kill a Single Process

For instance, we want to terminate a process with a specific name such as "firefox". we can run "fkill" in the terminal, navigate through the list of processes using the arrow keys, and select the "firefox" process by pressing the spacebar. In the end, press the enter key that will terminate the selected process in Linux.

Input Command

$ fkill firefox

Output for this command will kill the particular process 

✔ Killed process with PID 1234 (firefox)

The output will confirm that the process has been terminated successfully. In summary, "fkill" provides an easy way to terminate a single process running on a Linux system. This can be particularly useful when dealing with insensitive or difficult processes.

Example 2: Kill Multiple Processes

"Fkill" can be used to terminate multiple processes by selecting them from the list of all running processes. We can navigate through the list using arrow keys and select the ones we want to terminate using the spacebar. Once we have selected all the processes we want to kill, we can press the enter key to terminate them all at once. Moreover, we should be careful when terminating multiple processes, especially if they are essential system processes. It's important to be selective and careful when choosing which processes to kill. "Fkill" provides an efficient and easy way to manage and terminate multiple processes on a Linux system.

Input command for killing multiple processes

fkill chrome firefox

Output for killing multiple processes command

? Process to kill:  (Use arrow keys)
❯ chrome
firefox
[pid: 1234] node /path/to/script.js
Killed 2 processes

As "chrome" and "firefox" are the names of processes that need to be terminated, running the command "fkill chrome firefox" in the terminal will select and terminate both processes at once, assuming they are both running. The command line output will display the names and process IDs of the terminated processes. It is important to note that using the name of a process to terminate it can also terminate other processes with similar names, so it is recommended to use port numbers when terminating specific processes.

Example 3: Kill Processes by Port Number

Using "Fkill" to kill processes by port number is an efficient and targeted way to manage processes on a Linux system. It's especially useful when dealing with multiple instances of a process with different names or freeing up ports for other applications.

Input command to kill a process by port number

fkill -p 3000

This command will kill the process running on port 3000. If multiple processes are running on the same port, "Fkill" will display a list of all the processes and prompt us to select which process we want to terminate.

Output may look like this 

✔ Select processes to kill with spacebar (a=all, i=invert, o=select by pid, p=select by port number)
p
Enter port number (e.g. 80) or range (e.g. 3000-3030): 3000

● [1] node  (PID: 2259)
   /home/user/project/app.js
   port: 3000
✔ Confirm kill signal for [1] node (PID: 2259) with SIGTERM signal? (y/n)
y
Success: Killed 1 process(es) on port(s) 3000.

The output of the command confirms that the process has been terminated successfully. This feature can be useful in situations where multiple instances of a process are running with different names or when we need to free up a specific port for another application.

In summary, "fkill" simplifies the process of killing processes running on a specific port, making it a valuable tool for Linux users dealing with multiple instances of a process or trying to free up a specific port.

Example 4: Kill all Processes

With "Fkill", Linux users can terminate all running processes with just one command. Using the "force" option ("-f") with the "fkill" command, you can quickly and efficiently terminate all running processes on my system. Moreover, you should exercise caution while using this option, as it terminates all processes without any confirmation, potentially leading to data loss.

Input Command

$ fkill -f

Output 

Are you sure you want to kill all processes? (y/N) y
✔ Killed 472 processes.

It's important to exercise caution when using the "force" option with "fkill" to terminate all running processes on the system. In this example, we used the "-f" flag to force terminate all running processes and confirmed the prompt to kill all processes by entering "y". As a result, fkill terminated 472 processes successfully. It's crucial to remember that the "force" option can terminate critical system processes, so it's recommended to save important work and close critical applications before using this option.

Conclusion

In summary, "fkill" is an excellent tool for terminating processes in a Linux environment. It provides various options for targeting specific processes, and its ability to terminate all running processes using the "force" option can be useful in certain situations. It's essential to exercise caution while using the "force" option to prevent data loss or system instability. We would recommend Linux users give "fkill" a try for managing their processes and ensure that they are familiar with its various options to use it effectively. Overall, "fkill" is a reliable and efficient tool for managing processes in a Linux environment, and it can undoubtedly make a Linux user's life more comfortable.

Updated on: 28-Jul-2023

592 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements