
Read Bpftool Prog, Map and Link Show Documentation
Start with bpftool prog show, bpftool map show, and bpftool link show. Those commands show the kernel’s loaded BPF programs, maps, and active links. Check the installed man pages and kernel documentation for syntax. If the output looks wrong, use logs, strace, and source before trusting an unverified command.
Last updated: 2026-11-05
This bpftool: bpf program inspection and debugging guide keeps the useful parts of the old page, then puts the object inspection commands first. bpftool is not a friendly summary of your source code. It reports what the kernel loaded, which may be less flattering.
What does this guide cover?
bpftool is the reference command-line tool for inspecting, loading, attaching, and debugging BPF objects. It ships in the Linux kernel source tree under tools/bpf/bpftool and uses the same libbpf interface that many BPF loaders use.
When bpftool lists a program or dumps a map, it is asking the kernel the same questions your own code asks through libbpf. Its answers are ground truth, not a friendly approximation. People run bpftool prog show, see something they didn’t expect, and go hunting Stack Overflow for a fix.
The real problem is usually that they never learned to read the output. bpftool shows program IDs, types, names, load times, attachment details, map references, and runtime information when the kernel exposes it. Each field answers a separate debugging question.
I reach for bpftool when a BPF program does something I can’t explain from the source alone. It shows what the kernel actually loaded, which is often different from what you thought you compiled.
Object and command structure
Pick the object first. Then pick the operation.
These are the object categories that matter first:
| Object | Main inspection command | What it shows |
|---|---|---|
| Programs | bpftool prog show | Loaded BPF programs and their metadata |
| Maps | bpftool map show | Loaded maps and their dimensions |
| Links | bpftool link show | Active links and their attachment targets |
| BTF | bpftool btf | Kernel and object type information |
| Features | bpftool feature probe | Supported program types, map types, and helpers |
The command groups are broader than show:
MAP-COMMANDS := { show | list | create | dump | update | lookup | getnext | delete | pin | event_pipe | help }
PROG-COMMANDS := { show | list | dump jited | dump xlated | pin | load | attach | detach | help }
LINK-COMMANDS := { show | list | pin | detach | help }
Use show or list when you need inventory. Use dump when you need instructions or map entries. Use id, name, tag, or pinned selectors when you already know what object you want.
For scripts, use JSON:
sudo bpftool -j prog show
sudo bpftool -j map show
sudo bpftool -j link show
The -j and --json options generate JSON output. The -p and --pretty options generate human-readable JSON and imply -j.
Some commands cannot produce JSON. For those commands, -j has no effect. Check the output before writing a parser around it. A flag that silently changes nothing is a poor foundation for automation.
List loaded BPF programs

Start with the complete inventory:
sudo bpftool prog show
bpftool prog show displays information about loaded programs. If you omit a program selector, it lists all programs currently loaded on the system.
The output starts with the program ID, followed by the program type and named attributes. The exact attributes depend on the kernel version and the program itself.
The record follows this general shape:
PROG_ID: PROG_TYPE name PROG_NAME tag PROG_TAG
loaded_at LOAD_TIME uid UID
xlated SIZE jited SIZE memlock SIZE map_ids MAP_IDS
btf_id BTF_ID run_time_ns RUN_TIME run_cnt RUN_COUNT
Treat that as a set of fields, not one sentence.
PROG_IDis the program ID. Save it because later commands can target that exact object.PROG_TYPEis the program type, such asxdp.name PROG_NAMEis the program name when one was supplied.tag PROG_TAGidentifies the loaded instruction set.loaded_atrecords the load time when supported.map_idslists maps referenced by the program.btf_ididentifies associated BPF Type Format information.run_time_nsandrun_cntexpose runtime statistics when available.
The first useful move is to save the ID. Every later inspection can target that one program:
sudo bpftool prog show id 123
sudo bpftool prog dump xlated id 123
sudo bpftool prog dump jited id 123
Do not guess from a shortened listing when several programs look alike. Select the program by ID, then inspect the complete record.
Filtering programs by ID, name, type, and attachment context
The program selector supports several forms:
PROG := { id PROG_ID | pinned FILE | tag PROG_TAG | name PROG_NAME }
Inspect one program by ID:
sudo bpftool prog show id 123
Inspect a pinned program:
sudo bpftool prog show pinned /sys/fs/bpf/firewall
Select by tag:
sudo bpftool prog show tag 91f4c2d8a1b7c003
Select by name:
sudo bpftool prog show name firewall
A selector by tag or name may match several programs. bpftool shows all matching programs. That matters after a loader has restarted and created another object with the same name.
Names are useful for a first pass. IDs are better for a precise investigation because they identify one loaded object. Pinned paths are useful when you are tracing a loader’s ownership model.
For attachment context, inspect the subsystem that owns the attachment. For network programs, run:
sudo bpftool net show
That tells you which XDP, traffic control, or related programs are attached to network interfaces. It answers a different question from prog show: the program inventory says what exists, while net show says what the network stack is using.
That is the syntax the man page gives, and it is the one people mistype most. To see what is attached, run bpftool net show or scope it to an interface.
For cgroup attachments, inspect the cgroup path:
sudo bpftool cgroup show /sys/fs/cgroup
Use the object command and the attachment command together. One without the other leaves a gap in the diagnosis.
Reading program metadata and runtime statistics
Read the metadata before dumping instructions. It tells you whether you are investigating the right object.
The useful fields are:
- Program ID: the kernel identifier used by later
bpftoolcommands. This is the field to trust when names collide. - Program type: such as
xdp,tracepoint,kprobe,cgroup_skb, or another supported type. - Name: the loader-provided name, if present. Treat it as a label, not a unique key.
- Tag: a fingerprint of the loaded program instructions.
- Load time: useful when a loader may have replaced an older object.
- Map IDs: maps referenced by the program.
- BTF ID: associated type information.
- Instruction sizes: translated and JITed program sizes.
- Run count: how many times the program ran.
- Runtime: total execution time or sampled runtime fields, depending on kernel support.
- Attachment fields: the target or attachment information exposed for that program type.
Since Linux 5.1, the kernel can collect BPF program statistics, including total running time and the number of runs. Those fields are not guaranteed to appear in every output. The kernel must support the statistics, and the relevant runtime setting must allow their collection.
If runtime fields are missing, check the kernel configuration and the command output first. Do not conclude that the program never ran. A missing counter can mean statistics are disabled or unsupported.
The count and runtime also need context. A program with a large run count may be attached to a busy hook. A program with a small count may be correct but attached to a rarely used event. Runtime totals show work accumulated over the object’s lifetime, not a clean per-request latency measurement.
Dumping translated and JITed BPF instructions
Dump the translated program first:
sudo bpftool prog dump xlated id 123
The command form is:
bpftool prog dump xlated PROG [{ file FILE | [ opcodes ] [ linum ] [ visual ] }]
The translated dump shows the instructions after the verifier and loader have processed them. This is the code the kernel accepted as BPF bytecode.
Add line information when the object contains the needed debug data:
sudo bpftool prog dump xlated id 123 linum
Show opcodes as well:
sudo bpftool prog dump xlated id 123 opcodes
Write the dump to a file:
sudo bpftool prog dump xlated id 123 file /tmp/program.xlated
The JIT dump shows native instructions generated for the machine:
sudo bpftool prog dump jited id 123
Use the two views for different failures.
- The translated dump explains verifier rewrites, map access handling, helper calls, and CO-RE relocation results.
- The JITed dump is for code generation, architecture-specific behavior, and differences between accepted BPF and native execution.
- The line-number output connects kernel instructions to compiled source when debug information survived the build.
When the translated dump does not match your C source, do not blame bpftool. The verifier rewrites map accesses, resolves relocations, and changes the instruction stream as part of loading. Read the dump against the verifier behavior and the object’s BTF data.
The translated program is the useful starting point. The JIT dump is where you go after you have proved the BPF logic and still need to explain machine-level behavior.
List loaded BPF maps
List all loaded maps:
sudo bpftool map show
bpftool map show displays information about loaded maps. If you omit a map selector, it lists all maps currently loaded on the system.
A map entry commonly includes its ID, type, key size, value size, maximum entry count, flags, name, and references to programs or processes when the kernel exposes them.
The selector forms are:
MAP := { id MAP_ID | pinned FILE | name MAP_NAME }
Inspect one map by ID:
sudo bpftool map show id 17
Inspect a pinned map:
sudo bpftool map show pinned /sys/fs/bpf/firewall/counters
Inspect a named map:
sudo bpftool map show name counters
Use bpftool map dump to read entries:
sudo bpftool map dump id 17
The map dump command reads all entries from the selected map. Values appear as raw bytes, so interpret them using the key and value types from the BPF source or BTF. A byte sequence that looks wrong in a terminal may be a valid little-endian integer or a packed structure.
Map type matters before you update anything. A per-CPU map has separate value storage for each CPU. A hash map, array map, ring buffer, and queue each have different lookup and update behavior. Run map show first, then choose the operation that fits the type.
A map that is not visible in your expected listing may still exist through a pinned path or an open file descriptor. Loaded object inventory and filesystem inventory are related, but they are not the same thing.
Map ownership, identifiers, names, and pinned paths
A map ID identifies the kernel object. A name helps humans find it. A pinned path gives user space a durable handle.
Start with the map listing:
sudo bpftool map show
Then follow the references:
sudo bpftool prog show id 123
sudo bpftool map show id 17
sudo bpftool map dump id 17
If a program lists map ID 17, inspect that map directly. This connects the program’s metadata to the map’s type, dimensions, and contents.
Pinned paths matter when a loader shares maps between processes or restarts. Check the BPF filesystem:
sudo find /sys/fs/bpf -type f -print
Then inspect the object through its pinned path:
sudo bpftool map show pinned /sys/fs/bpf/firewall/counters
The process that created a map may no longer be running. The map can remain alive through a pin, a program reference, or an open file descriptor held by another process. That is why “the loader exited” does not prove the map disappeared.
If the map is not where you expect, inspect the loader’s source and its pin calls. Do not create another map with the same name and assume it replaces the first one. Names are labels. IDs and pinned paths are how you prove which object you have.
For a persistent loader, the portable CO-RE eBPF loader article covers the user-space side of this ownership model.
List active BPF links
List active BPF links:
sudo bpftool link show
bpftool link show reports active links. If you omit a link selector, it lists all links currently active on the system.
The output starts with the link ID, followed by the link type and named attributes. Some attributes depend on the link type.
A link record may look like this:
42: cgroup prog 123
cgroup_id 812 attach_type cgroup_skb/ingress
Use the link ID for a focused inspection:
sudo bpftool link show id 42
A link answers the attachment question more directly than a program record. prog show tells you that program 123 exists. link show helps establish how program 123 is attached and which link owns that relationship.
Since Linux 5.8, bpftool can discover processes holding open file descriptors against BPF links. If the output includes process information, use it to find the loader or supervisor that still owns the link.
If prog show finds the program but link show does not, the program may be attached through an older mechanism, through a subsystem-specific attachment, or not attached at all. Check bpftool net show, bpftool cgroup show, and the loader’s attach path before changing anything.
Read the local program manual
Use the installed manual for the exact syntax supported by your build:
man bpftool-prog
For a quick command summary:
bpftool prog help
bpftool help
The prog manual is the right reference for:
showandlistoperands- ID, tag, name, and pinned selectors
dump xlateddump jited- opcode and line-number modifiers
- JSON behavior
- kernel-dependent output fields
- program pin, load, attach, and detach commands
The local manual matters because bpftool and the kernel evolve together. A command copied from a different distribution may accept a different operand or expose a field your system does not have.
The safe sequence is:
bpftool version
bpftool prog help
sudo bpftool prog show
That tells you which tool you are running, what its parser accepts, and what the kernel actually returns.
Read the kernel documentation
The authoritative documentation lives with the kernel source in linux/tools/bpf/bpftool/Documentation/bpftool.rst. Read the Linux kernel bpftool documentation when the installed manual and command output disagree.
The source tree also shows how the command is implemented. That matters when a field is present but undocumented, or when a selector behaves differently across versions.
Use the local command help for syntax. Use the kernel documentation for command meaning. Use the source when you need to know why a field exists or why a version does not print it.
The same rule applies to maps and links. Their output is shaped by kernel support, bpftool support, and the object type. There is no universal output record that every kernel must print.
Read the link documentation
The link command is defined by the same bpftool documentation and source tree, but link fields need extra care. A link can represent different attachment types, and each type exposes different attributes.
Start with:
bpftool link help
sudo bpftool link show
Then inspect the related program and subsystem:
sudo bpftool link show id 42
sudo bpftool prog show id 123
sudo bpftool net show
The link ID comes first in the output, followed by its link type and named attributes. The attributes depend on that link type. Do not build a parser that assumes every link has the same fields.
When the link output is incomplete, check the kernel and bpftool versions together. A newer command can understand fields that an older kernel never reports. A newer kernel can expose link behavior that an older bpftool does not print cleanly.
For network attachment problems, the XDP attach syntax guide covers the interface-side commands. Still inspect the resulting link and network state. A command that returned successfully is not proof that the intended interface now owns the program.
Keep these related commands
The inspection commands come first, but several related commands solve common setup problems.
Check kernel feature support:
sudo bpftool feature probe
This reports available program types, map types, and helper functions. Run it when a program loads on one machine and fails on another.
Generate a C header from the running kernel’s BTF:
sudo bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
The file /sys/kernel/btf/vmlinux must exist. If it does not, the kernel was built without the needed BTF support. Repeating the command will not create kernel type information that the kernel never exposed.
Generate a skeleton after compiling the BPF object:
bpftool gen skeleton prog.o > prog.skel.h
The generated header contains the libbpf calls and typed handles for the object. Read it when a skeleton build fails. A missing section or renamed map usually shows up there faster than it does in a large loader.
If bpftool is missing on Ubuntu, the bpftool installation guide covers the package split and the version matching problem. Match the tool to the kernel you are investigating. A newer binary can advertise features the running kernel cannot provide.
Diagnose misleading or incomplete output
Do not fix a listing problem by hiding fields or installing random packages. Work from the exact output.
- Record the command and exit code.
sudo bpftool prog show
echo $?
A nonzero exit code means the command failed. An empty result with a zero exit code means something different, so do not diagnose both cases as “no programs.”
- Check the tool and kernel versions.
bpftool version
uname -a
A version mismatch can explain missing selectors, output fields, or object types. Record both values before changing packages.
- Run the JSON form.
sudo bpftool -j prog show
sudo bpftool -j map show
sudo bpftool -j link show
Compare the structured output with the human-readable form. If both omit a field, the issue is probably kernel support or object state.
- Check permissions.
id
sudo bpftool prog show
BPF inspection can require privileges. Test with sudo before rewriting the loader. Reworking correct code around an EPERM is wasted effort.
- Check the kernel log.
sudo dmesg -T | tail -50
sudo journalctl -k -b
The kernel ring buffer may show verifier errors, rejected attachments, missing helpers, or permission failures. Read those lines before trusting a thin user-space error message.
- Trace the failing command.
sudo strace -f -o /tmp/bpftool.strace bpftool prog show
grep -E 'BPF|EPERM|ENOENT|EINVAL' /tmp/bpftool.strace
This shows which bpf() requests failed and which error code came back. EPERM, ENOENT, and EINVAL point to different problems.
- Inspect the source when behavior still disagrees.
Read the bpftool command implementation and the kernel BPF code for the operation involved. Forums usually explain the common case. Source explains the case you actually have.
The most common mistake is treating missing output as missing objects. Check the command’s permissions, the object’s lifetime, the kernel’s feature support, and the attachment mechanism before changing the program.
FAQ
Does bpftool prog show list every BPF program?
It lists programs currently loaded on the system when you provide no selector. It cannot show a program that was unloaded or never loaded. Permissions can also hide objects, so rerun the command with the required privileges before deciding the program is gone.
Can I inspect a BPF program after its loader exits?
Yes, if another reference keeps the program alive. Check for a pin, attachment, link, or reference from another kernel object. The loader’s process ID disappearing tells you only that the loader exited; it says nothing conclusive about the objects it created.
Why does bpftool prog show name NAME return several programs?
Names are labels and may collide. A loader restart can leave several loaded programs with the same name, and bpftool correctly returns every match. Use the returned ID or tag to select the exact object before dumping instructions or following map references.
Why is the JIT dump empty or missing?
Check the translated dump first. The kernel may lack JIT support, or the program may have no native image for that architecture and configuration. An empty JIT view does not prove the BPF program is unloaded, so inspect kernel settings and logs before changing the program.
Where should I look when the local man page disagrees with bpftool?
Trust the running binary’s parser first. Run bpftool prog help and bpftool version, then read the kernel’s bpftool documentation. If those still disagree, compare the installed tool and running kernel rather than forcing syntax from another build.
