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 ID
ppid: The parent process ID
cmd: 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 using
-sort=-%mem option tells the ps command to sort the output by the percentage of memory that each process is using, in descending order.
head command then prints the first 10 lines of the output.
watch command then runs the command every second (
-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:
psis a command that lists all of the running processes.
-eois an option that tells the
pscommand to only print the specified columns.
-sort=-%memis an option that tells the ps command to sort the output by the percentage of memory that each process is using, in descending order.
headis a command that prints the first few lines of a file.
watchis a command that runs a command repeatedly, with a specified interval.