LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-30-2006, 03:16 PM   #1
jsfritz
LQ Newbie
 
Registered: Oct 2006
Distribution: Ubuntu Edgy Eft
Posts: 2

Rep: Reputation: 0
viewing CPU usage by thread


Hello,

I'm looking to view a list of threads/processes and how much CPU usage they're each taking up. My screen saver has recently turned choppy for some strange reason and I'm wondering if a running thread hogging CPU time is the culprit. Similar to process list in task manager in windows.

How would I view this in linux? I guess the ps command, but I can't figure out how to format the output.

Thanks,
Jeff
 
Old 11-30-2006, 03:43 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
If you're using kde, you can press control-escape which should start up ksysguard (or you can press alt-f2 and type in ksysguard). Gnome has a similar app called gnome-system-monitor.

If you're comfortable with the terminal, try using top. top is usually installed by default on most non-minimal distros. top refreshes the list of processes every few seconds, and sorts them by CPU usage. You can press h to get help on what the various keys do, H will show threads, or you can press q to quit back to the prompt.

There's a nicer version of top called htop, which I only discovered yesterday. It's slightly prettier and has a few extra options. It's top on steroids I guess.

ps can of course be used. Here's my attempt at a useful set of command line options:
Code:
ps axm -o pid,lwp,%cpu,time,command k -%cpu |head -n 20
The command line arguments to ps are a bit of a nightmare because it tries to be compatibile with several different standards and old implementations of ps in different unixes...
The options mean:
  • axm : all process (ax), show thread details (m)
  • -o pid,lwp,%cpu,time,command : show columns as specified.
  • k -%cpu : sort by %cpu column, descending.[/i]

The output of ps is sent to head -n 20, which just passes through the first 20 lines, and junks the rest - just so you can see the top CPU users... you probably won't want to see the whole list of processes on the system.
 
Old 11-30-2006, 03:46 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Oh, by the way, LWP stands for "light weight process". That's a thread to you and I.
 
Old 11-30-2006, 04:11 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Must admit I prefer top. It accepts a configuration file that enables you to tailor it for a particular situation.
I run it in batch mode, and also use "head" to trim the output, then write it to a file. It'll take a delay and iteration count as well.

As usual, multiple solutions available to suit everybody.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
How to assign CPU usage with Thread wangru Programming 5 08-25-2004 10:14 AM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Viewing webpage cranks up X's CPU usage slackist Linux - General 1 04-24-2004 08:28 AM
%CPU , Memory Usage, Thread count srinivasar Programming 0 09-20-2003 03:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration