Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to kill a process that is using all CPU
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
cyildiz
n00b
n00b


Joined: 13 Dec 2009
Posts: 34

PostPosted: Sun Oct 09, 2011 12:00 am    Post subject: How to kill a process that is using all CPU Reply with quote

Hi,

I've recently had this problem few times in my AMD64 Gentoo PC.

1) I had a python script running and plotting with matplotlib. Because of my fault, it was trying to plot a lot(!) of points. When it started making the plot, PC got stuck.

2) I wanted to open a txt file with vim. Later, I realized that the file was 2GB (due to continuous flow of debugging output of a program). Again computer got stuck.

In both cases PC was not actually stuck, but I couldn't do anything. Whole CPU power was being used. I did ctrl+alt+F1 with a huge lag. But I never even manage to log in to kill the programs that cause the problem. Finally I had to reboot both times.

In this cases what should I do? Is there a way to limit CPU usage of programs, to reserve some for killing them at least?
Back to top
View user's profile Send private message
Hypnos
Advocate
Advocate


Joined: 18 Jul 2002
Posts: 2889
Location: Omnipresent

PostPosted: Sun Oct 09, 2011 12:35 am    Post subject: Reply with quote

First on your second question, if you are using bash, consider the ulimit command. To find out how to use it, type

Code:
help ulimit


Now, to your first question. it is useful to have the "magic sysrq" key option enabled in your kernel. You can read more about it in

Code:
/usr/src/linux/Documentation/sysrq.txt


For this application, sysrq+k can be used to kill everything on the current console, useful for killing your X session and all daughter process. Also, sysrq+s then sysrq+u then sysrq+b can be used to reboot more safely than just holding down the power button.

There is a nice Wikipedia page about it.
_________________
Personal overlay | Simple backup scheme
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Sun Oct 09, 2011 1:05 am    Post subject: Reply with quote

In fact, when it comes to X apps xkill does real good job. While success of kill command depends on whether the program is listening or not xkill just terminates the client.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
Hypnos
Advocate
Advocate


Joined: 18 Jul 2002
Posts: 2889
Location: Omnipresent

PostPosted: Sun Oct 09, 2011 1:15 am    Post subject: Reply with quote

Jaglover wrote:
In fact, when it comes to X apps xkill does real good job. While success of kill command depends on whether the program is listening or not xkill just terminates the client.

Only if the window manager or a virtual terminal can be manipulated by the user in order to invoke xkill ... this is doubtful if you can't even switch to a text console.
_________________
Personal overlay | Simple backup scheme
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Sun Oct 09, 2011 1:22 am    Post subject: Reply with quote

Right ...
Quote:
I did ctrl+alt+F1 with a huge lag. But I never even manage to log in to kill the programs that cause the problem. Finally I had to reboot both times.

but usually you get some delayed response, as OP stated.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
cyildiz
n00b
n00b


Joined: 13 Dec 2009
Posts: 34

PostPosted: Tue Oct 11, 2011 7:41 am    Post subject: sysrq for a single process Reply with quote

Hi, thanks for all replies.

ulimit seems nice, I should try it.

I did not know sysrq either, it may be useful.

But my main problem is that, I want to kill the cpu eating process and continue working.

Would it be possible to add a new key combination that gets the highest cpu using process and kills it? This would be great. I looked up in the internet but did not come across such thing.
Back to top
View user's profile Send private message
Hypnos
Advocate
Advocate


Joined: 18 Jul 2002
Posts: 2889
Location: Omnipresent

PostPosted: Tue Oct 11, 2011 7:46 am    Post subject: Re: sysrq for a single process Reply with quote

cyildiz wrote:
But my main problem is that, I want to kill the cpu eating process and continue working.

Would it be possible to add a new key combination that gets the highest cpu using process and kills it? This would be great. I looked up in the internet but did not come across such thing.

I don't know of one either. If it just runs in a terminal (i.e., no GUI), you can run it on a non-X console. Then you can switch to that console and use SysRq-k to kill that process (and all the other processes on that console).

EDIT: You might somehow get monit to do what you want (in Portage).
_________________
Personal overlay | Simple backup scheme
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Tue Oct 11, 2011 8:22 am    Post subject: Re: How to kill a process that is using all CPU Reply with quote

cyildiz wrote:
Hi,

I've recently had this problem few times in my AMD64 Gentoo PC.

1) I had a python script running and plotting with matplotlib. Because of my fault, it was trying to plot a lot(!) of points. When it started making the plot, PC got stuck.
Try to place some limits on the oom killer. The modifications can be done to /etc/sysctl.conf and can be applied to the live system by running sysctl -p after you have done the modifications. The configuration options you would want to look at are:
Code:
vm.overcommit_ratio
vm.overcommit_memory
The latter is probably better left unset. However, it should be set to 2 if you want to be very strict about restricting memory usage. This option restricts the total Virtual Memory size to the restrictions set above. For any program it comes up under the VIRT column when you look at top. Look at the documentation in /usr/src/linux/Documentation for the meaning of these parameters. I don't remember the exact file, but if you grep for overcommit_ratio you should be able to locate the file.
Quote:
2) I wanted to open a txt file with vim. Later, I realized that the file was 2GB (due to continuous flow of debugging output of a program). Again computer got stuck.
I am pretty sure by "stuck" it was actually heavily swapping. I have never seen a Linux system lock up because it was taking too much cpu. In this case, you could try Alt-SysRq-f to kill the process that is taking the most memory.
In the case of vim, use vim -n if you are opening a huge file. This is to prevent vim from trying to create a .swp backup file. This backup file creation is the one which eats up memory and cpu. Alternatively, use less to view huge files.
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum