LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Start *top* command with memory sort? (or any other available field) (https://www.linuxquestions.org/questions/linux-software-2/start-%2Atop%2A-command-with-memory-sort-or-any-other-available-field-4175596615/)

dedec0 01-02-2017 08:29 AM

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?

273 01-02-2017 09:08 AM

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?

dedec0 01-02-2017 09:14 AM

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 ...]


dedec0 01-02-2017 09:51 AM

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... :(

Timothy Miller 01-02-2017 10:17 AM

Quote:

Originally Posted by dedec0 (Post 5649158)
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.

dedec0 01-02-2017 10:22 AM

Quote:

Originally Posted by Timothy Miller (Post 5649171)
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.

Timothy Miller 01-02-2017 10:29 AM

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...

Habitual 01-02-2017 11:59 AM

Quote:

Originally Posted by dedec0 (Post 5649177)
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

TheEzekielProject 01-02-2017 12:10 PM

To sort by memory % usage, I believe you can just press shift+m after top is running :D

dedec0 01-02-2017 12:26 PM

Quote:

Originally Posted by The EzekielProject (Post 5649237)
To sort by memory % usage, I believe you can just press shift+m after top is running :D

Yes, shift+m works too, I tested now. How did you find this? It is not written in the manpage... !

dedec0 01-02-2017 12:29 PM

Quote:

Originally Posted by Habitual (Post 5649233)
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.

dedec0 01-02-2017 12:32 PM

Quote:

Originally Posted by Timothy Miller (Post 5649184)
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?

TheEzekielProject 01-02-2017 12:37 PM

Quote:

Originally Posted by dedec0 (Post 5649244)
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 :)

dedec0 01-02-2017 12:41 PM

Quote:

Originally Posted by The EzekielProject (Post 5649251)
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!

TheEzekielProject 01-02-2017 12:49 PM

Quote:

Originally Posted by dedec0 (Post 5649256)
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


All times are GMT -5. The time now is 11:34 AM.