I have a lot of processes running and I need to kill them all.
How can I do this without restarting a machine?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
More seriously, rather than the radical kill'ing, you can switch to maintenance mode (aka Single User):
# as root: /sbin/init 1
Your system will switch to runlevel 1, dedicated to maintenance tasks. [Nearly] All processes will be [nicely] killed, all file systems unmounted and interactive login directed to the console (the
console boot argument).
To later go back to the multi-user runlevel:
or, to enable the graphical login manager:
You cannot do this. Whatever you do, there has to be at least one process running. Or rather, when you can do this, you will cause the kernel to dump core and panic. An immediate reboot will probably follow - or else nothing will happen at all until you power cycle your machine.
There is kernel space and there is user space. The user space is propped up from boot by PID 1 -
init. To kill all of the processes is to kill user space and then what would you do with the computer anyway?
When the system is booted the system's firmware or some intermediate boot-loader executes the kernel in memory. The kernel does some sanity checks and looks for
init. If it finds it, and
init does anything useful, eventually you will be able to use your computer. If it does not then you will not be able to use your computer.
For the rest of the life of that boot cycle the kernel services user space - which is to say,
init's children. Take those away and it has no purpose. And it probably won't be happy about it, either.
If the magic SysRq key is enabled on your system, you can press Alt + Print Scrn/SysRq + E or execute
echo e > /proc/sysrq-trigger
to send SIGTERM to all processes except init (PID 1).
You can also use Alt + Print Scrn/SysRq + I or
echo i > /proc/sysrq-trigger
to send SIGKILL instead.
You can kill all processes by following command:
kill -9 -1
$ man kill | sed -n '5,6p' ; man kill | awk 'NR>=38 && NR<=40' NAME kill - send a signal to a process EXAMPLES kill -9 -1 Kill all processes you can kill.
This will kill all processes and you will be redirected to login screen.
If your distro uses
systemd, you can switch to minimal
systemctl isolate emergency.target
This will kill almost all applications, move your system to single-user root login mode. After this you execute:
systemctl isolate graphical.target
You will be brought back to X. This will accompish almost a reboot.
It will kill all processes and you don't need to restart your machine.