Linux terminate all processes

How to kill all processes in Linux

@Stephen — then s/he’d just end up with all the processes restarting and that’s the last thing you want when you want them all DEAD!

11 Answers 11

The command killall5 -9 will forcefully terminate all running processes except your login shell, init, and kernel-specific processes.

OK I did this, and now my machine is on a continuous loop where it asks me the password, goes to desktop, goes back to login shell and asks password again. How do I come out of this?

Ok, the processes have stopped, and so has the computer. This answer is like answering «how to stop worrying so much» with «suicide».

You can kill all of a given user’s processes using one of these:

or you can use the numeric UID instead of the username.

Beware that killall functions differently (similarly to killall5 ) on some systems such as Solaris.

The easiest way is to use the Magic SysRq key : Alt + SysRq + i . This will kill all processes except for init .

Alt + SysRq + o will shut down the system (killing init also).

Note that you may need to set the keyboard to XLATE mode first : Alt + SysRq + r

Also note that on some modern keyboards, you have to use PrtSc rather than SysRq .

In some Linux distros, you can switch to Run Level 0 — which I think is halted, but still switched on:

I’ve actually heard of this being used for dedicated firewall servers since it keeps some of the needed low-level kernel stuff loaded like iptables. weird eh? See here for more info.

To see which distros do what at each runlevel, have a look here.

Источник

Kill Command

[#quick-reference]Quick Reference[#quick-reference]

# kill process $ kill # hangup process $ kill -1 # terminate process $ kill -15

[#which-version-of-kill]Determining which version of [.inline-code]kill[.inline-code] your shell is using[#which-version-of-kill]

When working with [.inline-code]kill[.inline-code], the first step is to make sure your shell is running the code you think it is. Both Bash and Zsh shells have their own built-in version of [.inline-code]kill[.inline-code] that may take precedence over the Linux binary [.inline-code]kill[.inline-code]. So you may need to run [.inline-code]/bin/kill[.inline-code] instead of [.inline-code]kill[.inline-code] in order to utilize the standard-library Linux binary [.inline-code]kill[.inline-code]; however, the functionality of the shell built-in [.inline-code]kill[.inline-code] will likely be largely the same.

Читайте также:  Открыть приложение через консоль linux

For the rest of this article we will use the syntax [.inline-code]kill …[.inline-code], and assume that we are referring to Linux [.inline-code]kill[.inline-code]. To see which one will be run when you run a [.inline-code]kill[.inline-code] command, you can run [.inline-code]which kill[.inline-code] as follows:

[#structure-of-kill]Structure of a [.inline-code]kill[.inline-code] command[#structure-of-kill]

The Linux [.inline-code]kill[.inline-code] command has the following structure:

[#kill-signals-available][.inline-code]kill[.inline-code] signals available[#kill-signals-available]

“Options” in the structure above has a number of components, with the most commonly used option being the [.inline-code]signal[.inline-code] flag. To see a list of the signals available we can run the following in our shell:

Each of these signals is also associated with a given number, as again defined in the Linux docs. Depending on the configuration of your shell, you may also be able to run [.inline-code]kill -L[.inline-code] to see both the signal names and numbers.

Either the signal name or the signal number can be combined with the [.inline-code]kill[.inline-code] command as follows:

$ kill -9 $ kill -s SIGKILL $ kill -SIGKILL $ kill

The signal here ([.inline-code]SIGKILL[.inline-code]) happens to be the default signal, and will also be used if no specific signal is passed.

[#kill-to-check-user-access-to-process][.inline-code]kill[.inline-code] to check user access to a specific process[#kill-to-check-user-access-to-process]

[.inline-code]SIGNULL (0)[.inline-code], checks user access to or validity of a pid without sending an action signal.

$ kill -0 $ kill -s SIGNULL $ kill -SIGNULL

[#terminate-process-gently][.inline-code]kill[.inline-code] to terminate a process gently[#terminate-process-gently]

[.inline-code]SIGTERM[.inline-code] is the “normal” kill signal. The application will be given time to shut down cleanly (save its state, free resources such as temporary files, etc.), and an application that is programmed to not immediately terminate upon a [.inline-code]SIGTERM[.inline-code] signal may take a moment to be terminated.

$ kill -15 $ kill -s SIGTERM $ kill -SIGTERM

[#kill-force-termination][.inline-code]kill[.inline-code] to force termination[#kill-force-termination]

[.inline-code]SIGKILL[.inline-code] can be used to force termination and the application is not given a chance to respond.

$ kill -9 $ kill -s SIGKILL $ kill -SIGKILL

[#determine-pid-of-process]Determining the PID of a process[#determine-pid-of-process]

The second part of the [.inline-code]kill[.inline-code] command is the process ID, or “pid”. There are a number of ways we can determine which processes are running and their pid’s, including [.inline-code]ps[.inline-code], [.inline-code]pidof[.inline-code], and [.inline-code]pgrep[.inline-code] and [.inline-code]top[.inline-code]. Which to use will depend on exactly what you are trying to do.

Читайте также:  Truncate log file linux

For example, to get the [.inline-code]pid[.inline-code] of all processes related to Google Chrome you can run the following:

Alternatively, to list all processes running on your machine, consider [.inline-code]ps aux[.inline-code] or [.inline-code]top[.inline-code]:

[#kill-9-1][.inline-code]kill -9 -1[.inline-code] terminates all running processes[#kill-9-1]

However, this should be done very carefully; this can cause damage to your kernel depending on what is running on your machine at the time.

[#kill-with-pidof]Combining [.inline-code]kill[.inline-code] with [.inline-code]pidof[.inline-code][#kill-with-pidof]

[.inline-code]kill[.inline-code] is most powerful when combined with other terminal commands. For example, to identify and kill all processes related to Google Chrome we can run the following command:

[#kill-with-sudo]Overcoming [.inline-code]kill[.inline-code] permission issues with [.inline-code]sudo[.inline-code][#kill-with-sudo]

If any of [.inline-code]kill[.inline-code] commands fail one reason might be lack of permissions. Simply re-run the command using [.inline-code]sudo[.inline-code] and enter your password in order to proceed:

 # Careful! Using `sudo` can be dangerous when # dealing with system processes sudo kill $(pidof chrome)

Источник

How to Kill all Processes for a User in Linux

There is nothing more frustrating than logging into your Linux system only to have many processes slowing down your machine. Although Linux is very good at process management, you may need to terminate some processes manually.

In this tutorial, we shall discuss how to find and kill processes from a specific user. We will use tools such as pkill and killall.

NOTE: Ensure you have access to an administrative account or the root account because regular users can only kill their processes, not processes belonging to other users. On the other hand, the root user can kill all processes.

Understanding System Signals

To kill a specific process, the command sends a signal to the process. By default, kill commands such as killall send a TERM signal that gracefully stops the specified process.

Before we proceed to kill command, let us take a brief overview of the process signals.

The common types of kill signals include:

  • SIGHUP – This signal reloads a process. It has an integer value of 1.
  • SIGINT – Interrupt from the keyboard such as CTRL + C. It has an integer value of 2.
  • SIGKILL – Kill a process. It has an integer value of 9.
  • SIGTERM – This is a termination signal, which, as stated, gracefully stops a process. It has an integer value of 15.
  • SIGSTOP – Stops a process. It has an integer value of either 17, 19, or 23.
Читайте также:  Install proxychains kali linux

NOTE: When terminating processes, it is good to start with the least aggressive signal, such as TERM. Using a signal such as TERM will allow the program to shut down correctly and use the set measures when the program receives the TERM signal.

A KILL signal can also be helpful, especially if a process has encountered an error, fails to exit or does not respond to the INT signal.

To view all the available signals, use a command such as a kill -l

Method #1 – The Killall Command

The first command you can use to kill Linux processes is the killall command. For this, you need the PID value or the name of the process you wish to terminate.

You can use a tool such as pgrep to get the PID of a specific process.

Once you have the PID value of the process, you can terminate using the kill command as:

The command above will send a graceful termination signal.

To send a KILL signal, use the -9 integer as:

How to kill all user processes with killall

Killall command allows you to terminate all the processes owned by a specific user. To do this, use the -u flag.

For example, to terminate all processes spawned by the ubuntu user.

CAUTION: Depending on the user specified in the command, terminating the processes can cause the system to crash or stop critical system processes. Therefore, before applying this command, ensure the user in question is not running processes you do not wish to terminate.

Method #2: The Pkill Command

Another great tool you can use to terminate Linux processes is the pkill command. This command works similarly to killall.

For example, to terminate the bash process with pkill, use the command:

To kill all processes owned by the ubuntu user, we can use the command:

Conclusion

In this guide, we quickly discussed ways to terminate processes in Linux and various types of kill signals. As seen, killing a single process or multiple processes owned by a specific Linux user is easy.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list

Источник

Оцените статью
Adblock
detector