Created
April 29, 2016 14:10
-
-
Save masami256/8b389ecfe671ba5eb5904542c7c82fb1 to your computer and use it in GitHub Desktop.
Show pid in each pid namespaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stap | |
%{ | |
#include <linux/sched.h> | |
#include <linux/thread_info.h> | |
#include <linux/pid_namespace.h> | |
%} | |
function show_pidtree:long(pn:long) %{ | |
struct task_struct *task; | |
int pid_nr = STAP_ARG_pn; | |
struct pid_namespace *pid_ns; | |
int indent_level = 0, i; | |
struct pid *pid = find_get_pid(pid_nr); | |
if (!pid) { | |
STAP_PRINTF("Could not find pid %d\n", pid_nr); | |
STAP_RETURN(-1); | |
} | |
task = pid_task(pid, PIDTYPE_PID); | |
if (!task) { | |
STAP_PRINTF("Cannot find task by pid %d\n", pid_nr); | |
STAP_RETURN(-1); | |
} | |
pid_ns = task->nsproxy->pid_ns_for_children; | |
do { | |
pid_nr = __task_pid_nr_ns(task, PIDTYPE_PID, pid_ns); | |
for (i = 0; i < indent_level; i++) | |
STAP_PRINTF(" "); | |
STAP_PRINTF("pid %d\n", pid_nr); | |
pid_ns = pid_ns->parent; | |
indent_level++; | |
} while (pid_ns); | |
STAP_RETURN(0); | |
%} | |
probe begin { | |
/* pass pid that is command line argument */ | |
show_pidtree($1) | |
exit() | |
} | |
probe end { | |
printf("Done\n") | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment