awk根据父进程的PID获得所有子进程PID
知道某具体进程的PID,和程序名(比如 bash,PID 2971),需要将他的子进程都打印出来。
?
假如所有的bash相关进程如下:
[user@localhost ~]$ ps -ef|grep bash
user ???? 2986? 2971? 0 21:42 pts/0??? 00:00:00 bash
user????? 3368? 2971? 0 21:59 pts/1??? 00:00:00 bash
root???? 15083? 2165? 0 23:13 ???????? 00:00:00 /bin/bash /usr/bin/run-parts /etc/cron.monthly
root???? 15087 15083? 0 23:13 ???????? 00:00:00 /bin/bash /etc/cron.monthly/0anacron
?
?
保存文件./subpid
3. 在awk表达式中使用'$extvar'
4. 模式引用(在正则表达式中引用外部变量) '"$extvar"'
5. 遍历外部数组(用于BEGIN段处理) awk -f 'BEGIN{for(i=1;i<ARGC;i++)print ARGV[i]}' ${extarr[@]}
6. 引用环境变量 ENVIRON["environment variable"]?