Vijay tames processes without Task Manager
ps, top, kill, nice — process management for Windows engineers
Week 4. A Java application consuming 98% CPU. On Windows: open Task Manager, sort by CPU, right-click End Task. On Linux: command line. And it turned out to be faster.
TASK MANAGER EQUIVALENT - top and ps
Interactive dashboard (like Task Manager refreshing every 2 seconds):
top
# P = sort by CPU (like clicking CPU column header in Task Manager)
# M = sort by memory
# k, type PID, Enter = kill a process
# q = quitSnapshot (like a screenshot of Task Manager):
ps aux # all processes from all users
ps aux --sort=-%cpu # sorted by CPU, highest first
ps aux --sort=-%mem # sorted by memory, highest first
ps aux | grep java # find all java processesReading ps aux output:
USER PID %CPU %MEM VSZ RSS STAT COMMAND
tomcat 4521 97.3 12.1 2.1g 800m Sl java -jar myapp.jarUSER: who owns the process (User column in Task Manager)
PID: process ID (PID column in Task Manager)
%CPU: CPU usage
%MEM: memory percentage
RSS: actual physical RAM used (this is the real number)
STAT: S=sleeping, R=running, Z=zombieKILLING PROCESSES - End Task equivalent
kill 4521 # polite kill (like End Task)
kill -9 4521 # force kill (like End Process Tree)
killall java # kill all processes named java
pkill -f "myapp.jar" # kill by pattern in command nameWhen to use which:
Always try kill PID first. Wait 10 seconds.
If still running, then kill -9 PID.
kill -9 is End Process Tree. No cleanup. Last resort only.PROCESS PRIORITY - Task Manager right-click Set Priority
nice -n 10 command # start a new process at lower priority
nice -n -10 command # start at higher priority
renice +10 -p 4521 # lower priority of running process 4521
renice -5 -p 4521 # higher priority of running processNice values: -20 (highest) to +19 (lowest). Default is 0 (Normal).
Positive = lower priority (nicer to other processes).
Negative = higher priority (needs sudo).FINDING WHICH PROCESS USES A PORT - Resource Monitor Network tab
Windows: Resource Monitor > Network > Listening Ports
Linux: ss -tlnp | grep :8080
Linux: lsof -i :8080 # more detail - process name, PID, userMEMORY DETAILS
cat /proc/4521/status | grep VmRSS # just the RAM usage for process 4521
pmap -x 4521 # memory map (like Sysinternals VMMap)BACKGROUND PROCESSES - no Services wrapper needed
nohup ./myapp.py & # run in background, keep running after logout
nohup ./myapp.py > output.log 2>&1 & # background with output captured to file
jobs # see background jobs in current session
Ctrl+Z # pause current foreground process
Ctrl+C # stop current foreground processPROCESS TREE
pstree # all processes as a tree
pstree -p # include PIDs in the tree
ps -ef --forest # alternate tree viewVijay found the CPU-hogging process in 15 seconds with ps aux --sort=-%cpu. He tried kill, waited 10 seconds, confirmed it was gone, restarted the service. Total time: 3 minutes. He admitted: ps aux was faster than opening Task Manager.
ps aux --sort=-%cpu shows processes sorted by CPU — same as clicking the CPU column in Task Manager
top is interactive Task Manager — press P for CPU sort, M for memory sort, k to kill, q to quit
kill PID is End Task (polite), kill -9 PID is End Process Tree (force) — always try polite first
lsof -i :8080 shows which process owns a port — same as Resource Monitor Network tab
nice and renice change process priority — equivalent to right-click Set Priority in Task Manager