How do I kill processes in Ubuntu?
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
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
If you want to look up all processes by user bob, this might help
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.
No, you can try running killall firefox and killall firefox-bin and see what works. I agree with your first comment.
Use sudo kill or sudo killall
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.
The OP doesn’t have privileges, please edit your answer or it may be deleted or converted into a comment as «not an answer».
If he doesn’t have privileges he just have to do kill
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
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.
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.
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.)
I’d break your problem into 2 parts:
1) How do I find the processes started by me? Run this:
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:
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
To kill all processes started by your account, enter kill -1 . Same as before: work your way up to -9 .
If you know the name of the process you can simply go killall , where the is what you are trying to kill. For example: killall fish (fish, in this sense, is the Friendly Interactive SHell).
Is there a Linux utility to halt all user processes, including a VM?
I know of the killall5, system V kill command. Is there something similar where I can send a SIGSTOP to all user processes, a Host OS and guest OS included? Possibly killall -SIGSTOP??
@Mark I want to run application X on one machine and application Y on another machine connected via network. I’d like to send a signal to application Y to halt from application X machine. So that both applications hit a breakpoint at the same time.
3 Answers 3
If you really want to do this, the following, executed by root, will send the STOP signal to everything:
This will screw with you system immensely though, so don’t do that.
Specifying -1 as the process ID (from the kill() C library spec in SUSv4):
If pid is -1, sig shall be sent to all processes (excluding an unspecified set of system processes) for which the process has permission to send that signal.
Executed by a user, this will do the same for all processes owned by that user, including the current shell. So don’t do that either.
To stop all processes of a particular user, while not being that user (i.e. you are root):
If you execute this with sudo while logged in as otheruser it will still screw you over, so don’t do that either.
The only reason I can see for sending STOP to all processes of a user is when that user is a daemon user which is running a very limited number of things.
Also, remember to send CONT later..
pkill (see pgrep) is a command-line utility initially written for use with the Solaris 7 operating system. It has since been reimplemented for Linux and some BSDs.
As with the kill and killall commands, pkill is used to send signals to processes. The pkill command allows the use of extended regular expression patterns and other matching criteria.
To signal all the processes of a given user , use:
pkill -signal -u //(by default it will send SIGTERM)
You can use pgrep with this as a test before you run it to see the process name and pid of what will be signaled:
You can use any signal (see kill -l ) with pkill. see man pkill
Info from man page
pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout. All the criteria have to match.
For example, pgrep -u root sshd
will only list the processes called sshd AND owned by root. On the other hand,
will list the processes owned by root OR daemon.
pkill will send the specified signal (by default SIGTERM) to each process instead of listing them on stdout.
-d delimiter Sets the string used to delimit each process ID in the output (by default a newline). (pgrep only.)
-f The pattern is normally only matched against the process name. When -f is set, the full command line is used.
-g pgrp. Only match processes in the process group IDs listed. Process group 0 is translated into pgrep’s or pkill’s own process group.
-G gid. Only match processes whose real group ID is listed. Either the numerical or symbolical value may be used.
-l List the process name as well as the process ID. (pgrep only.)
-n Select only the newest (most recently started) of the matching processes.
-o Select only the oldest (least recently started) of the matching processes. -P ppid. Only match processes whose parent process ID is listed.
-s sid. Only match processes whose process session ID is listed. Session ID 0 is translated into pgrep’s or pkill’s own session ID.
-t term. Only match processes whose controlling terminal is listed. The terminal name should be specified without the «/dev/» prefix.
-u euid. Only match processes whose effective user ID is listed. Either the numerical or symbolical value may be used.
-U uid. Only match processes whose real user ID is listed. Either the numerical or symbolical value may be used.
-v Negates the matching.
-x Only match processes whose name (or command line if -f is specified) exactly match the pattern.
-signal Defines the signal to send to each matched process. Either the numeric or the symbolic signal name can be used. (pkill only.)
kill all processes of a user except a few in linux
I was running some processes under a screen session on a remote server. When I tried to kill all those processes by:
all my processes are killed including those I don’t want to kill (i.e. the screen and ssh connection). Is there a way to kill all my processes except the screen and ssh connection?
6 Answers 6
ps -U tim | egrep -v "ssh|screen" | cut -b11-15 | xargs -t kill
this will kill everything but any ssh or screen processes. Here are the commands explained:
- ps -U tim — will obviously, list every process from the user tim
- egrep -v «ssh|screen» — will remove lines with ssh or screen processes
- cut -b11-15 — will cut the data in columns 11-15 (typically that’s where the PID is located
- xargs -t kill — will pass all the process ID’s to the kill command
You can also use awk, if you’re more used to that.
ps -U tim | egrep -v "ssh|screen" | awk '' | xargs -t kill
Nothing built in that I’m aware of. You could create a script like this:
#!/bin/bash ps ux | sed -e '/bash/d' -e '/screen/d' | awk '' | while read process do kill $process done
If there were any other processes you wanted to avoid killing you would just need to add more
entries to the sed portion. There’s probably a cleaner way to handle it, but this will work.
Yes. You can add -e ‘/login/d’ and remove -e ‘/bash/d’ . Then you even can remount root FS as RO. I mean case, when you are in non-X11 root terminal. P.S.: If you are in X11, then logout first.
If you’re killing all your procs a lot, you might want to investigate why you need to do that. but hey, this is all about doing things, not about not doing things.
One easy solution would be to use two userIDs. one for screen and your SSH connection, and the other one for all the processes you’ll at some point want to kill off.
This is beyond «hackerish» and into just plain «hack» but it has an added advantage in that any OTHER programs you run as the «connect» user won’t get killed when you kill off the other procs. This could include «tails» of error logs and things like that which you might WANT to have left around.
Kill all process of particular user in Ubuntu? [duplicate]
How to kill all process of one user? When I make ps aux I obtain a list of process with several users, and I want to kill all process of user name1 , for example. What’s a command to do that in Ubuntu?
If the users are real persons this probably isn’t a good idea. I also think you want to kill processes to save time. This is a very bad idea. For instance, the services in Ubuntu can be stopped using sudo service the-service-name stop . Killing processes may left corrupted files, databases, etc.
5 Answers 5
In this case, it’s pretty simple, you can use killall to kill, or send any other signal, to a bunch of processes at once. One of the «filtering» options is the owner: killall —user name1
It should be noted that killall in e.g Solaris Unix kills all running processes it can! See: en.wikipedia.org/wiki/Killall
Adding another option because nobody has mentioned it, and I don’t like killall (using it on solaris can cause disaster).
Didn’t see killall on a CentOS machine, but I’ve always seen pkill on the machines I’ve used. This is probably the more portable answer.
Be aware that if you kill off stuff for users you don’t know the purpose for, you may render your machine unusable (until you restart).
If you really don’t want to install slay:
ps -e -o user,pid | grep '^some-user ' | awk '< print $2 >' | xargs kill
ps -e -o user,pid | grep '^some-user ' | awk '< print $2 >' | xargs kill -9
Btw awk can grep something itself. No need to do grep smth | awk , cause you can use just awk ‘/smth/<. >‘ instead.
Identify the user, then killall -user
They will have a bash (or similar) process associated with their login session killing that will kill their session.
To get a potentially better overview of what a user is doing — try pstree
kill -9 -1 Kill all processes you can kill.
To apply it to a different user:
Linked
Related
Hot Network Questions
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.13.43531
Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.