All the following commands create text files in the downloads folder. The file will be a simple file with no color coding and only Process ID, Command, CPU and Memory usage
Memory Usage:
1 - List all processes in descending order of memory usage:
top -l 1 -o mem -stats pid,command,mem,cpu > /Users/Gaurav/Downloads/process_list.txt
2 - Top 20 apps in descending order of memory usage:
echo "PID Command Memory Usage CPU Usage" > /Users/Gaurav/Downloads/process_list.txt && top -l 1 -o mem -stats pid,command,mem,cpu | head -n 21 | tail -n 20 >> /Users/Gaurav/Downloads/process_list.txt
CPU Usage:
1 - List all processes in descending order of CPU usage:
echo "PID Command CPU Usage Memory Usage" > /Users/Gaurav/Downloads/process_list.txt && top -l 1 -o cpu -stats pid,command,cpu,mem | tail -n +2 >> /Users/Gaurav/Downloads/process_list.txt
2 - List of top 20 processes using most CPU, listed in descending order:
echo "PID Command CPU Usage Memory Usage" > /Users/Gaurav/Downloads/process_list.txt && top -l 1 -o cpu -stats pid,command,cpu,mem | head -n 21 | tail -n 20 >> /Users/Gaurav/Downloads/process_list.txt