linux/tools/testing/selftests/bpf/progs/bpf_iter_task.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright (c) 2020 Facebook */
   3#include "bpf_iter.h"
   4#include <bpf/bpf_helpers.h>
   5#include <bpf/bpf_tracing.h>
   6
   7char _license[] SEC("license") = "GPL";
   8
   9SEC("iter/task")
  10int dump_task(struct bpf_iter__task *ctx)
  11{
  12        struct seq_file *seq = ctx->meta->seq;
  13        struct task_struct *task = ctx->task;
  14        static char info[] = "    === END ===";
  15
  16        if (task == (void *)0) {
  17                BPF_SEQ_PRINTF(seq, "%s\n", info);
  18                return 0;
  19        }
  20
  21        if (ctx->meta->seq_num == 0)
  22                BPF_SEQ_PRINTF(seq, "    tgid      gid\n");
  23
  24        BPF_SEQ_PRINTF(seq, "%8d %8d\n", task->tgid, task->pid);
  25        return 0;
  26}
  27