watch -d -n 1 'ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head'
The command first uses the ps
command to list all of the running processes. The -eo
option tells the ps command to only print the following columns:
pid
: The process IDppid
: The parent process IDcmd
: The command that was used to start the process%mem
: The percentage of memory that the process is using%cpu
: The percentage of CPU that the process is usingThe -sort=-%mem
option tells the ps command to sort the output by the percentage of memory that each process is using, in descending order.
The head
command then prints the first 10 lines of the output.
The watch
command then runs the command every second (-n 1
).
The -d
flag makes it highlight the differences between successive updates.
This command can be useful for monitoring the memory usage of your system. If you see a process that is using a lot of memory, you can use the kill
command to terminate the process.
Here is an explanation of the commands:
ps
is a command that lists all of the running processes.-eo
is an option that tells the ps
command to only print the specified columns.-sort=-%mem
is an option that tells the ps command to sort the output by the percentage of memory that each process is using, in descending order.head
is a command that prints the first few lines of a file.watch
is a command that runs a command repeatedly, with a specified interval.