Domanda

i want to run a command and then "tell" the command line to press the letter "M"

but i cant use tools like xdtool or extra software.

example: top -n 1 and then M (press)

anyone knows?

thanks

È stato utile?

Soluzione

There's no simple, built-in way to script an interactive tool like top; in particular top -n 1 exits immediately, so it wouldn't listen to the "M" command anyway.

However, if what you want is a list of which programs are using the most memory, you can use the non-interactive ps tool to generate a list in whatever order you like. For example, here's a command that will show you the top-5 programs by memory-usage:

ps -A -o %mem,args --sort -%mem | head -6

-A means ps will examine all running processes.

-o %mem,args means that ps will print the %mem (memory used as a percentage of total memory) and args (full command-line including arguments) of each process it examines.

--sort -%mem means that ps will sort the results by the %mem column in descending order (ascending order would be --sort %mem).

| head -6 means the output will be piped through the head command, configured to show the first 6 lines of output (a line of headers, plus the first five processes in the list).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top