68.查看子进程脚本
16lz
2021-01-22
思路: ps -elf查看进程ppid根据ppid赛选pid进程#!/bin/bash#The script is used to print child processes.#Date 2021-01-16file=/tmp/pid.txt #定义文本路径while :doread -p "please input a pid: " pidif [ -z $pid ];then#判断是否为空 echo "The input can not be empty (input q or quit to exit)." continueelif [ $pid == "q" ]||[ $pid == "quit" ];then#退出循环 echo "exit." exitfips -elf| awk -v pid2=$pid '$5==pid2 {print $0}'>$file#筛选pidif ! grep -qw "$pid" $file;then#过滤pid echo "The input pid does not exist (input q or quit to exit)." continuefibreakdonechild_pid() { ps -elf|awk -v pid_new=$1 '$5==pid_new {print $4}' >$1.txt #将进程id写入文本 n=`wc -l $1.txt| awk '{print $1}'` if [ $n -eq 0 ];then echo "There are no subprocess under the pid $1" elif [ $n -ne 0 ];then echo "The pid $1 subprocess according to following:" cat $1.txt fi}#定义筛选函数child_pid $pidfor i in `cat $pid.txt`#for循环将每个子进程包含的子进程筛选出do child_pid $idonefor i in `cat $pid.txt`#for循环遍历删除文本do [ -f $i.txt ] && rm $i.txtdone[ -f $pid.txt ] && rm $pid.txt#删除文本
更多相关文章
- 使用后台进程和 Shutdown Hook 友好地关闭 Tomcat
- jQuery——将title属性用作悬停的文本,但只在同一父类中使用。
- 如何在java脚本中获取节点内部文本?
- jquery 监控文本框键盘事件(回车事件),附常用keycode值。
- 使用jQuery更新textarea值更改的文本
- 输入-文本对齐:用jQuery右填充输入
- 如何使用javascript/jquery获取文本框数组值
- 解析PHP的基本文本输出
- 在体html中搜索文本的最佳方法是什么?