SkillPilotAI

nettop

nettop is the built-in macOS tool that shows live network usage per app: one line per process and, under it, that process's TCP and UDP sockets with bytes in, bytes out and RTT, refreshed every second.

72.1 Why is it used?

  • Find which app is eating bandwidth right now when the Mac's internet feels slow.
  • See every connection of one app (remote IP, port, interface, state, RTT).
  • Spot apps using costly mobile data over an iPhone hotspot (-t expensive).
  • Log per-app traffic to a CSV file over hours for later analysis.
  • macOS only (/usr/bin/nettop). Linux: nethogs / iftop (or ss). Windows: Resource Monitor.

72.2 How it works

  • nettop reads per-socket counters from the macOS kernel; it does not capture packets, so it is very light.
  • It groups sockets by process, so you get bytes per app and per connection.
  • Syntax: nettop [-ncdxP] [-m mode] [-t type] [-p name|pid] [-l N].
nettop: traffic per app, from kernel counters
  1. 1.MacBook: Safari sends a request

  2. 2.It goes through the Wi-Fi router (192.168.1.1) and the internet to the Apple server

  3. 3.At the same time Zoom's video packets flow via the router to the Zoom server

  4. 4.The Mac kernel keeps byte counters for every socket

  5. 5.nettop reads them: how many bytes Safari got, how many Zoom got

Counters, not a packet capture: that is why nettop is cheap to run.

72.3 Mode (-m)

Output
nettop            TCP + UDP sockets (default)nettop -m tcp     only TCP socketsnettop -m udp     only UDP socketsnettop -m route   routing table counters

72.4 Reading nettop -m tcp -n

  • Process line: name.PID (Safari.4123) with total bytes in and bytes out.
  • Indented lines: that process's sockets with local<->remote address, interface en0, state, bytes and average RTT.
  • -n shows IP addresses instead of host names.
  • The output below is the documented example (no macOS in the lab).
Terminal
nettop -m tcp -n
Output
$ nettop -m tcp -niface state bytes_in bytes_out rtt_avgSafari.4123 48 MiB 2.1 MiB  tcp4 10.0.0.2:51544<->17.253.144.10:443 en0 Established 31 MiB 1.2 MiB 22.4 ms  tcp4 10.0.0.2:51602<->142.250.183.4:443 en0 Established 17 MiB 0.9 MiB 18.1 mszoom.us.8801 210 MiB 96 MiB  tcp4 10.0.0.2:50210<->170.114.10.80:443 en0 Established 210 MiB 96 MiB 41.0 msmDNSResponder.212 120 KiB 88 KiB

72.5 Interface type (-t)

OptionShows
-t wifiOnly Wi-Fi
-t wiredOnly Ethernet
-t loopbackOnly lo0
-t awdlApple Wireless Direct Link (AirDrop / AirPlay)
-t expensiveCostly link such as an iPhone hotspot
-t undefinedSockets not tied to any interface
-t externalAll non-loopback interfaces
-t wifi -t wiredSeveral types together (repeat -t)
-t wifi vs -t expensive
  1. 1.In the office the MacBook uses Office Wi-Fi (type wifi, en0)

  2. 2.Safari's request goes through the access point to the internet

  3. 3.Wi-Fi goes down; the Mac switches to the iPhone hotspot

  4. 4.Zoom traffic now goes phone -> mobile network -> internet -> Zoom server

  5. 5.macOS marks the hotspot as expensive; nettop -t expensive shows which app burns mobile data

72.6 Display, timing and process selection

OptionEffect
-nShow IPs, not names
-cLess redraw, less CPU
-dDelta: change since last update (current speed)
-xFull numbers, no MiB suffix
-POnly one summary line per process
-s 5Refresh every 5 s (default 1 s)
-p 1234 / -p SafariOnly that PID / all processes with that name (repeatable)
  • Write -p names exactly as nettop shows them: long names get truncated.

72.7 Logging and columns

  • -l N prints N samples as plain text without redrawing; -l 0 runs forever.
  • -L does the same in CSV format.
  • -j adds columns, -J shows only the listed columns, -k hides columns (comma separated).
  • Press j in interactive mode for the full column list.
Terminal
nettop -l 1                         # one sample, plain textnettop -l 0 -s 10                   # forever, every 10 secondsnettop -L 1 > net.csv               # CSV, one samplenettop -L 0 -P -s 60 >> traffic.csv # CSV log every minutenettop -j uuid,rtt_var              # add these columnsnettop -k rcvsize,rtt_avg           # hide these columnsnettop -P -l 1 -J bytes_in,bytes_out  # one-shot snapshot

72.8 Interactive keys

KeyAction
qQuit
Arrow keysScroll
dDelta mode on/off
rRedraw the screen
xHuman-readable numbers on/off
e / cExpand all (connections) / collapse all (one line)
h / j / pHelp / columns menu / processes menu
lLog once and quit

72.9 Lab: a nettop-like view on Linux

  • No Mac in the lab, so a Docker Linux container (192.168.92.10) ran iperf3 (upload) and curl (download).
  • ss -tinpH shows the process, PID, RTT and bytes of every socket, like nettop -m tcp.
  • Filtering on curl is like nettop -p; bytes_received keeps growing on every run.
  • ip -s link shows interface totals (like -t wired); a loop over /sys counters makes a CSV like -L.
Terminal
ss -tinpH | grep -A1 curl \  | grep -oE 'users\S+| rtt:\S+|bytes_[sr]\S+'
Output
users:(("curl",pid=22,fd=5)) rtt:0.128/0.07bytes_sent:88bytes_received:10141559
Terminal
ip -s link show eth0cd /sys/class/net/eth0/statisticsecho time,rx_bytes,tx_bytesfor i in 1 2 3 4; do  r=$(cat rx_bytes); t=$(cat tx_bytes)  echo "$(date +%T),$r,$t"; sleep 1done
Output
$ ip -s link show eth09: eth0@if1167: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500    RX:  bytes packets errors dropped  missed   mcast      10893799     588      0       0       0       0    TX:  bytes packets errors dropped carrier collsns      25213488     718      0       0       0       0time,rx_bytes,tx_bytes21:23:24,11921783,2836482621:23:25,12279639,3033420621:23:26,12975553,3243505421:23:27,13335457,34404566
  • The difference between rows is the delta: tx grows by about 2 MB per second, i.e. an upload of about 16 Mbit/s.

72.10 Common mistakes

  • Reading bytes_in as current speed: by default it is the total since the process started; use -d (or the d key).
  • Looking for nettop on Linux or Windows: it is macOS only.
  • Giving -p a full long name that nettop shows truncated: the filter matches nothing.
  • Expecting packet contents: nettop only has counters; use tcpdump/Wireshark for payloads.

72.11 Interview tips

  • Live per-app usage on macOS: nettop -P -d (one line per app, current speed).
  • Connections of one app: nettop -p Safari -n.
  • Long-term record: nettop -P -L 0 -s 60 > usage.csv.
  • Linux equivalents: nethogs, iftop or ss -tinp; Windows: Resource Monitor.