LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-03-2018, 03:11 PM   #1
TrinityMH
LQ Newbie
 
Registered: Oct 2018
Posts: 5

Rep: Reputation: Disabled
Display CPU usage for a given process.


Hi, I have a problem with finding a command that in linux will display a given percentage of CPU usage for a given process.

Mainly wants such information to download to the website. It presents itself like this:
http://prntscr.com/l1uk3r

I found something like:
https://www.booleanworld.com/guide-linux-top-command/

But rather, this package will not be able to get only percentages.

I apologize if something is not understandable because the text is translated by an interpreter. However, please ask.
 
Old 10-03-2018, 07:38 PM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Look into the ps commnad
 
Old 10-03-2018, 09:41 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,147

Rep: Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124
Quote:
Originally Posted by TrinityMH View Post
this package will not be able to get only percentages.
"top" has the data. but it needs to be extracted - it is useful in that it gives you the current (actual) CPU% for whatever interval you choose.
"ps" gives CPU% since the program started, but should suffice for your uses - it accepts parameters to specify the output. For example, checking firefox with no headers so just the number is output:
Code:
ps -C firefox -o %C --no-headers
 2.0
 
Old 10-04-2018, 12:36 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
between ps and top, you probably need to script something.
not sure what your requirements are.

Quote:
Originally Posted by TrinityMH View Post
Mainly wants such information to download to the website. It presents itself like this:
http://prntscr.com/l1uk3r
i cannot see the image.
it's better if you provide a direct link to the image itself.
 
Old 10-04-2018, 02:26 AM   #5
TrinityMH
LQ Newbie
 
Registered: Oct 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Generally, this is needed for the resource monitor for Minecraft servers.
I have already made the disc and I have just had to create a processor and ram usage.

Link directly to the graphic:
https://i.imgur.com/O3v8luf.png

Preview from htop level.
http://prntscr.com/l1zucw

Last edited by TrinityMH; 10-04-2018 at 02:35 AM.
 
Old 10-04-2018, 05:57 AM   #6
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
If you have the PID, then you can do:
Code:
top -p <PID>

If you are looking for resource monitor then there are many out there...
 
1 members found this post helpful.
Old 10-04-2018, 06:10 AM   #7
TrinityMH
LQ Newbie
 
Registered: Oct 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Yes, I need information to return and not to show information interactively because PHP will not process it. Mr. Syg00 told me well, but unfortunately I have several java processes and I have to choose one of the chosen ones. Maybe there is a directive to name the "Java" command and then display it using the ps command?

I will display a view from the "htop" package in the tree version.
https://i.imgur.com/8omjgyI.png

Last edited by TrinityMH; 10-04-2018 at 06:14 AM.
 
Old 10-04-2018, 09:13 PM   #8
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,366
Blog Entries: 28

Rep: Reputation: 6162Reputation: 6162Reputation: 6162Reputation: 6162Reputation: 6162Reputation: 6162Reputation: 6162Reputation: 6162Reputation: 6162Reputation: 6162Reputation: 6162
This article should help: https://alvinalexander.com/linux/uni...ps-command-cpu
 
Old 10-05-2018, 11:23 AM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Code:
top -n1 -p $(pidof given_process)
???
 
Old 10-05-2018, 02:00 PM   #10
TrinityMH
LQ Newbie
 
Registered: Oct 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Done. Thanks to everyone for help.

http://prntscr.com/l2o4am
 
Old 10-06-2018, 06:26 AM   #11
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by TrinityMH View Post
Done.
how?
please share your solution.
others will benefit.
then also mark your thread SOLVED.
thank you.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU usage low in top, even though one process is using 80-90% of the CPU mwburden Linux - Software 6 10-23-2012 04:22 PM
process cpu usage ahmedb72 Linux - General 9 09-07-2010 02:22 PM
How to get %CPU usage of a process devershetty Linux - Newbie 1 08-18-2008 01:52 AM
How to get %CPU usage of a process romydmisc Linux - Newbie 2 05-24-2006 01:02 PM
CPU usage of a process asharma Solaris / OpenSolaris 7 03-29-2003 02:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:15 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