4
0

iter.bpf.c 530 B

1234567891011121314151617181920212223
  1. // clang-format off
  2. #include <vmlinux.h>
  3. #include <bpf/bpf_helpers.h>
  4. // clang-format on
  5. char _license[] SEC("license") = "GPL";
  6. SEC("iter/task")
  7. int iter_task(struct bpf_iter__task *ctx) {
  8. struct seq_file *seq = ctx->meta->seq;
  9. struct task_struct *task = ctx->task;
  10. // Verifier requires this check.
  11. if (task == NULL) {
  12. return 0;
  13. }
  14. if (ctx->meta->seq_num == 0) {
  15. BPF_SEQ_PRINTF(seq, "tgid pid name\n");
  16. }
  17. BPF_SEQ_PRINTF(seq, "%-8d %-8d %s\n", task->tgid, task->pid, task->comm);
  18. return 0;
  19. }