LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-02-2017, 08:29 AM   #1
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Rep: Reputation: 51
Question Start *top* command with memory sort? (or any other available field)


Top is a program that I have used for years, even with a few "deep" uses of its features: kill, renice, sort by other fields.

Now I want to start top with other sorting field, not CPU usage. One of the memory related fields is what want.

Even before looking at its documentation, I was planning a natural thing to many other *nix programs: to make an alias for it setting the wanted sort field. Something like:

Code:
alias topmem='top -sortfield n'  # %MEM
alias topswp='top -sortfield p'  # swapped size
alias topvrt='top -sortfield o'  # virtual image
But reading 'man top' did not show anything to do this. Or I missed it.

I do not want to change the behavior of top, it should continue existing. I want to call the normal top in one terminal and "topswp" or others in another one, at (possibly) the same time.

I also do not want to do what I do now:
- start top
- type F
- type the letter for another sort field
- type space to get back to main screen

Is it possible? How?
 
Old 01-02-2017, 09:08 AM   #2
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
I just had a look in man top and it looks like the "-o" option does what you want, and the column names can be found with the "-O" option -- does htat help?
 
Old 01-02-2017, 09:14 AM   #3
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
No. There is no "-o" or "-O" option for the top I use. :(

All options I have, copied from the manpage, are:

Code:
-hv | -bcHisS -d delay -n iterations -p pid [,pid...]
(...)

Code:
$ top --version
	top: procps version 3.2.8
usage:	top -hv | -bcisSH -d delay -n iterations
             [-u user | -U user] -p pid [,pid ...]

Last edited by dedec0; 01-02-2017 at 09:42 AM.
 
Old 01-02-2017, 09:51 AM   #4
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Question Subthread: where would I find the source code for top?

Do you know where would I find the source code for top? Or which package is it part of? (which would help me to find the source code in the app repository)

This computer is with Ubuntu 10.04.

Code:
# partial output of
$ man top
# [...]
7. BUGS
       Send bug reports to:
          Albert D. Cahalan, <albert@...........>

8. HISTORY Former top
       The original top was written  by  Roger  Binns,  based  on  Branko
       Lankester's <lankeste@.................> ps program.

       Robert  Nation <nation@.................> adapted it for
       the proc file system.

       Helmut Geyer  <Helmut.Geyer@...................>  added  support
       for configurable fields.

       Plus many other individuals contributed over the years.

9. AUTHOR
       This entirely new and enhanced replacement was written by:
          Jim / James C. Warner, <warnerjc@................>

       With invaluable help from:
          Albert D. Cahalan, <albert@..............>
          Craig Small, <csmall@....................>

# [...]
No clue to where the project is... :(
 
Old 01-02-2017, 10:17 AM   #5
Timothy Miller
Moderator
 
Registered: Feb 2003
Location: Arizona, USA
Distribution: Debian, EndeavourOS, OpenSUSE, KDE Neon
Posts: 4,005
Blog Entries: 26

Rep: Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521
Quote:
Originally Posted by dedec0 View Post
Do you know where would I find the source code for top? Or which package is it part of? (which would help me to find the source code in the app repository)

This computer is with Ubuntu 10.04.

Code:
# partial output of
$ man top
# [...]
7. BUGS
       Send bug reports to:
          Albert D. Cahalan, <albert@...........>

8. HISTORY Former top
       The original top was written  by  Roger  Binns,  based  on  Branko
       Lankester's <lankeste@.................> ps program.

       Robert  Nation <nation@.................> adapted it for
       the proc file system.

       Helmut Geyer  <Helmut.Geyer@...................>  added  support
       for configurable fields.

       Plus many other individuals contributed over the years.

9. AUTHOR
       This entirely new and enhanced replacement was written by:
          Jim / James C. Warner, <warnerjc@................>

       With invaluable help from:
          Albert D. Cahalan, <albert@..............>
          Craig Small, <csmall@....................>

# [...]
No clue to where the project is...
Wow, you're out of date...10.04 was EOL over a year and a half ago. That's why you're missing the -o option in newer versions.

While you could probably compile the newer version, I'd STRONGLY suggest just backing up all your information, and reinstalling with a newer, supported version like 14.04 or 16.04.
 
Old 01-02-2017, 10:22 AM   #6
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by Timothy Miller View Post
Wow, you're out of date...10.04 was EOL over a year and a half ago. That's why you're missing the -o option in newer versions.

While you could probably compile the newer version, I'd STRONGLY suggest just backing up all your information, and reinstalling with a newer, supported version like 14.04 or 16.04.
That will not happen. And if I ever reinstall the system for this machine, it will be a Mint, not an ugly and much worse to use Ubuntu with Unity Desktop or Gnome 3.

At least, Mate Desktop was born...

Do you know which are the best places to find source code for top? I am guessing that this should be the path I will take here.
 
Old 01-02-2017, 10:29 AM   #7
Timothy Miller
Moderator
 
Registered: Feb 2003
Location: Arizona, USA
Distribution: Debian, EndeavourOS, OpenSUSE, KDE Neon
Posts: 4,005
Blog Entries: 26

Rep: Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521
NO, that shouldn't be the path. You're running an outdated OS with no more security patches or updates. Unless you're going to start compiling every program from source to keep up with security updates, then you should update to an OS that gets security updates. Regardless if it's Ubuntu, Mint, Arch, OpenBSD, Haiku, Windows, MacOS, or what.

Now, CAN you just update that one program, sure. But running an outdated OS is never a good thing, just ask everyone who's still using Windows XP...

Last edited by Timothy Miller; 01-02-2017 at 10:31 AM.
 
1 members found this post helpful.
Old 01-02-2017, 11:59 AM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by dedec0 View Post
Do you know which are the best places to find source code for top?
How about using a ~/.toprc to order what you want?
Here's mine,

Code:
RCfile for "top with windows"		# shameless braggin'
Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=3.000, Curwin=0
Def	fieldscur=AEHIOQTWKNMbcdfgjplrsuvyzX
	winflags=30137, sortindx=13, maxtasks=20
	summclr=1, msgsclr=1, headclr=3, taskclr=1
Job	fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX
	winflags=62777, sortindx=0, maxtasks=0
	summclr=6, msgsclr=6, headclr=7, taskclr=6
Mem	fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX
	winflags=62777, sortindx=13, maxtasks=0
	summclr=5, msgsclr=5, headclr=4, taskclr=5
Usr	fieldscur=ABDECGfhijlopqrstuvyzMKNWX
	winflags=62777, sortindx=4, maxtasks=0
	summclr=3, msgsclr=3, headclr=2, taskclr=3
I stole it. You can too!
I don't understand it except it shows me c-line all my Cores
Hope This "helps" http://unix.stackexchange.com/questi...icular-sorting
 
Old 01-02-2017, 12:10 PM   #9
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Rep: Reputation: 190Reputation: 190
To sort by memory % usage, I believe you can just press shift+m after top is running
 
Old 01-02-2017, 12:26 PM   #10
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by The EzekielProject View Post
To sort by memory % usage, I believe you can just press shift+m after top is running
Yes, shift+m works too, I tested now. How did you find this? It is not written in the manpage... !
 
Old 01-02-2017, 12:29 PM   #11
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by Habitual View Post
How about using a ~/.toprc to order what you want?
Here's mine,

[...]
This is not an option unless I can have two different files with two different settings. It seems that there is not a command line option fot that, as some programs have. As I said above, I want to have the normal top too.
 
Old 01-02-2017, 12:32 PM   #12
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Arrow

Quote:
Originally Posted by Timothy Miller View Post
NO, that shouldn't be the path. You're running an outdated OS with no more security patches or updates. Unless you're going to start compiling every program from source to keep up with security updates, then you should update to an OS that gets security updates. Regardless if it's Ubuntu, Mint, Arch, OpenBSD, Haiku, Windows, MacOS, or what.

Now, CAN you just update that one program, sure. But running an outdated OS is never a good thing, just ask everyone who's still using Windows XP...
I have seen Win XP running in several companies in the last months. But you will also complain about their security, about many other details. They still have it and will keep it for, at least, a few more years.

And I am not planning to change my OS so soon either.

Please, can anyone point me to which package or site top is in? Or show me a path to know for sure?

Last edited by dedec0; 01-02-2017 at 12:38 PM.
 
Old 01-02-2017, 12:37 PM   #13
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Rep: Reputation: 190Reputation: 190
Quote:
Originally Posted by dedec0 View Post
Yes, shift+m works too, I tested now. How did you find this? It is not written in the manpage... !
I saw it in a forum a long time ago! I can't remember where exactly

Last edited by TheEzekielProject; 01-02-2017 at 12:39 PM.
 
Old 01-02-2017, 12:41 PM   #14
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by The EzekielProject View Post
I saw it in a forum a long time ago! I can't remember where exactly :)
I thought you were talking about top source code... sad that this is not in the documentation. It is a good shortcut!

Last edited by dedec0; 01-02-2017 at 12:42 PM.
 
Old 01-02-2017, 12:49 PM   #15
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Rep: Reputation: 190Reputation: 190
Quote:
Originally Posted by dedec0 View Post
I thought you were talking about top source code... sad that this is not in the documentation. It is a good shortcut!
Check here for source code
 
  


Reply

Tags
command-line top



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
system memory info question shown by top command hellolqs Linux - Embedded & Single-board computer 3 06-01-2016 05:43 AM
[SOLVED] Sort certain field but preserve other field data akeka Programming 2 05-21-2012 04:01 PM
Can I use GNU sort to sort one field in order, another in reverse? zombieite Linux - Newbie 4 04-27-2009 12:23 AM
TOP command: calculation of memory usage samiralmousawi Linux - Server 7 07-29-2008 03:16 PM
Sort File by Field - but with a Twist! ;) moo-cow Programming 8 06-12-2006 11:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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