2

I have a lot of processes running and I need to kill them all.

enter image description here

How can I do this without restarting a machine?

  • 6
    What do you think will be left of your computer system if you kill all your processes? What is your desired end state? – rickhg12hs Jun 21 '15 at 9:36
2

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:

/sbin/init 3

or, to enable the graphical login manager:

/sbin/init 5
  • Runlevel 2 is multi-user and includes the gui... all higher runlevels are the same, at least on debian based distros. I believe on some other distros, 2 does not include the gui, but 3-5 are still all the same. – psusi Jun 21 '15 at 15:20
  • @psusi These runlevels are from my Gentoo machine man runlevel in fact. Thanks for the hint anyway. – user86969 Jun 21 '15 at 15:49
  • 1
    @terdon Have you got no sense of humour, then? ;-) – user86969 Jun 21 '15 at 15:52
2

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.

0

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.

0

You can kill all processes by following command:

kill -9 -1

From manpage:-

$ 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.

  • i think you may have overlooked a very important detail in the documentation you reference there. – mikeserv Jun 21 '15 at 10:37
  • @mikeserv ok; I've revised post – Pandya Jun 21 '15 at 11:04
0

If your distro uses systemd, you can switch to minimal systemd target:

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.

-4

Just use:

disown -r

It will kill all processes and you don't need to restart your machine.

  • 7
    This assumes that every running process on the machine is child of the current interactive shell. I consider that unlikely. – mikeserv Jun 21 '15 at 7:19
  • @mikeserv: I imagine OP means "jobs" rather than processes. Otherwise, this question doesn't make an ounce of sense. – Kevin Jun 21 '15 at 14:20
  • That does not kill processes; it simply removes them from the shell's job management so they continue to run in the background and will not be killed if you exit the shell. – psusi Jun 21 '15 at 15:14
  • @Kevin - process -> job is a pretty big leap. I likento take people at their word. – mikeserv Jun 21 '15 at 20:32
  • @mikeserv: If it wasn't what they wanted, they wouldn't have accepted. – Kevin Jun 22 '15 at 0:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy