Created
August 1, 2024 01:35
-
-
Save gotnix/79b6036cf69bcddc9383b879a20066fa to your computer and use it in GitHub Desktop.
配合 stap --example nettop.stp 使用,stap 脚本只打印了进程名称,awk 负责在 stap 输出的行尾追加完整的命令行信息。
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
# 配合 stap --example nettop.stp 使用 | |
# stap 脚本只打印了进程名称,awk 负责在 stap 输出的行尾追加 | |
# 完整的命令行信息。 | |
# | |
# 例子: | |
# stap --example nettop.stp | awk -f nettop.awk | |
# | |
# !!! awk 脚本过滤了 php 进程。 | |
{ | |
# PID 开头的行在末尾追加进程的完整的命令行 | |
if(match($1,"[0-9]+") && $NF == "php") { | |
cmdline_path = "/proc/" $1 "/cmdline" | |
getline cmdline < cmdline_path | |
close(cmdline_path) | |
# 使用gsub将null字符替换为空格 | |
gsub(/\0/, " ", cmdline) | |
print $0 " " cmdline | |
} | |
# 标题行末尾追加 "ARGS" | |
else if ($1=="PID") { | |
print $0, "ARGS" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment