249

How do I kill all processes running by my own non-root account?

I have some spinning smbd processes that I caused from my windows machine and so I telnetted into the linux server and I want to kill those spinning processes. I don't have authority to restart services or reboot the machine.

12 Answers 12

256

To kill all the processes that you have the permission to kill, simply run the command

kill -15 -1 or kill -9 -1 depending on the desired behavior (use man kill for details)

To kill a specific process, say, firefox, simply run

pkill firefox or killall firefox depending on the behavior you want: What's the difference between 'killall' and 'pkill'?

If you want to see what processes are running use the command

ps -ef

If you want to look up all processes by user bob, this might help

pgrep -l -u bob

or

ps -ef | grep bob
7
  • 8
    I'd start with kill -15 -1, and only move on to kill -9 -1 if there are stubborn processes and I know what I'm doing. Randomly killing processes that may be in the middle of a database transaction is not something one should do as casually as you suggest. Feb 17, 2012 at 7:38
  • Also, Firefox's process is named firefox-bin. Feb 17, 2012 at 7:39
  • No, you can try running killall firefox and killall firefox-bin and see what works. I agree with your first comment.
    – ste_kwr
    Feb 17, 2012 at 16:06
  • Thanks @ste_kwr, worked with your instructions, after struggling for two days... Feb 11, 2016 at 14:19
  • The advantage to not needing PIDs is in cron jobs. Using names works out cleanly.
    – SDsolar
    Jun 8, 2018 at 0:52
115

Use sudo kill <pid> or sudo killall <process-name>

3
  • 3
    I don't think this is relevant to this question, you are using sudo -- the OP has not such privileges, as mentioned in the question.
    – pl1nk
    Jun 24, 2012 at 23:01
  • The OP doesn't have privileges, please edit your answer or it may be deleted or converted into a comment as "not an answer".
    – ish
    Jun 25, 2012 at 6:28
  • 1
    If he doesn't have privileges he just have to do kill <pid> or killall <process-name> I just used it in my non root account, I wouldn't be able to do it if it wasn't for this Answer. Jan 27, 2018 at 14:45
46

You can use

ps -ax | grep application name 

If your searching for firefox type in terminal like ps -ax | grep firefox, it shows the process id of corresponding application. You can stop that application by kill command if process id=1317,

kill -9 1317
25

Let's try something more:

sudo apt-get install htop 

The top command is the traditional way to view your system’s resource usage and see the processes that are taking up the most system resources. Top displays a list of processes, with the ones using the most CPU at the top.

htop displays the same information with an easier-to-understand layout. It also lets you select processes with the arrow keys and perform actions, such as killing them or changing their priority, with the F keys.

0
17

I would use xkill. Enter xkill in a terminal and click in the window, or enter xkill and the process ID and it will be terminated.

Found out more about xkill on x.org.

5
  • 1
    Use it second in frequency after pkill nd love it. +1 May 3, 2015 at 0:11
  • xkill doesnt work in this case...
    – PythoNic
    Sep 29, 2015 at 12:22
  • @PythoNic in what case is that?
    – Alvar
    Oct 1, 2015 at 17:31
  • 2
    He wants to kill a non-window process which is also not related to the X server as it seems for me... (Anyway a good tool.)
    – PythoNic
    Oct 2, 2015 at 9:30
  • This blocked my mouse cursor and I had to do sudo killall xkill!
    – Danijel
    Apr 29, 2021 at 8:04
11

I'd break your problem into 2 parts:

1) How do I find the processes started by me? Run this:

ps -u `whoami`

The whoami is just in case you don't know the name of the account you are using, otherwise just type the name of the account without the back quotes.

This will list all processes that can be deleted by your account.

2) The ps command will list the process number, the TTY, Time, and CMD. The process ID is the first column. Use that number to kill the process. Be careful while killing the process. You might break something if you kill the wrong process. To kill a process you will use the kill command, which sends a SIGNAL to the process. The signal indicates what the process should do. For example, sending a -1 to the process will ask it to reload the configuration file; sending a -2 is equivalent to pressing the Control+C on that process; -9 will cause the kernel to abandon the process, without communicating it to the process.

Supposing that ps -u whoami returned something like

  PID TTY          TIME CMD
 4333 pts/1    00:00:00 fish
 4335 ?        00:00:00 fishd
 4816 ?        00:00:00 intellij
 4868 ?        00:50:42 java
 4939 ?        00:00:19 fsnotifier64
 7667 ?        02:49:08 firefox
 7698 ?        00:00:00 unity-webapps-s

And you wanted to kill the firefox process by its process id, then you'd do:

kill -1 7667

Then you'd re-run the same ps command and check if the process was still running. If it is still running, then do a

kill -2 7667

working your way up to -9.

To kill all processes started by your account, enter kill <level> -1. Same as before: work your way up to -9.

If you know the name of the process you can simply go killall <processname>, where the is what you are trying to kill. For example: killall fish (fish, in this sense, is the Friendly Interactive SHell).

Documentation for killall can be found here: http://manpages.ubuntu.com/manpages/hardy/man1/killall.1.html

9

To try to kill all processes owned by a user username, run:

pkill -U username
4

With this application you can view program listings

install htop

sudo apt-get install htop

for see process and kill process You can install it and simply delete

enter image description here

3

I wrote a little script I wrote to kill (in my case) Skype:

kill -s 9 `ps aux | grep skype | head -n 1 | cut -f4 -d" "`

But I found that as much as that worked then, it didn't work the next day because the pid was a different length and there for the amount of spaces was different

Then I came across this site and tried

pgrep -l -u justin

which conveniently outputs processes in the format

[pid] [name]

So I adjusted my code in the script to this:

kill -s 9 `pgrep -l -u justin | grep skype | cut -f1 -d" "`

What this does is pipes all of the processes justin is running (that can be changed to any user name) to grep which looks for skype (this can be changed to your process) and then pipes that line to cut which then reads only the PID and finally uses that PID in the kill command to kill it.

2
  • You could have dropped the -l, and ran pgrep -u justin skype, and to kill: pkill -u justin skype (or pkill -KILL -u justin skype to send SIGKILL).
    – muru
    Feb 12, 2016 at 21:07
  • This is definitely the Unix Way. Well done both of you. I will use this one.
    – SDsolar
    Jun 8, 2018 at 0:58
2

...All processes in Linux respond to signals. Signals are an os-level way of telling programs to terminate or modify their behavior.

How To Send Processes Signals by PID

The most common way of passing signals to a program is with the kill command.

As you might expect, the default functionality of this utility is to attempt to kill a process:

kill PID_of_target_process

This sends the TERM signal to the process. The TERM signal tells the process to please terminate. This allows the program to perform clean-up operations and exit smoothly.

If the program is misbehaving and does not exit when given the TERM signal, we can escalate the signal by passing the KILL signal:

kill -KILL PID_of_target_process

This is a special signal that is not sent to the program.

Instead, it is given to the operating system kernel, which shuts down the process. This is used to bypass programs that ignore the signals sent to them...

0
0

I used following procedure to kill a process in Ubuntu ::

Step 1 : Get the pid of the process by using grep or you can use -C also ::

ps aux | -C 'filename'

or

ps -ef | -C 'filename'

or

ps aux | grep 'filename'

or

ps -ef | grep 'filename' 

Step 2 : Note the pid number .

Step 3 : Use 'kill' command alongwith the pid number as :

kill pidnumber
0

Ctrl+Alt+Delete can be set to give you access to the task manager, from where it's easy to kill processes with a couple clicks, and for me, less requirement for remembering commands that could be damaging if done wrong:

http://ubuntuhandbook.org/index.php/2013/07/use-ctrl-alt-del-task-manager-ubuntu/

https://www.itsmarttricks.com/a-guide-to-kill-pkill-and-killall-commands-to-stop-the-process-in-linux-kill-process-linux/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .