经常管理和监控,需要进行shell编程,直接对进程kill或者重启操作。我们需要进行快速定位到每个进程的pid号
pid默认存储在/tmp目录
pid内容为进程号
ps -ef|grep hadoop 出现PID A,B,C 可能误杀B,C
[hadoop@hadoop000 sbin]$ cat hadoop-daemon.sh |grep pid
#HADOOPPIDDIR The pid files are stored. /tmp by default.
pid=$HADOOP_PID_DIR/hadoop-$HADOOP_IDENT_STRING-$command.pid
if [ -f $pid ]; then
if kill -0 cat $pid
> /dev/null 2>&1; then
echo $command running as process cat $pid
. Stop it first.
echo $! > $pid
if [ -f $pid ]; then
TARGET_PID=cat $pid
rm -f $pid
官方给的sh脚本中,也是通过读取pid文件内容作为进程kill对象
我们直接对pid文件的数字就是我们对于的进程pid
[hadoop@hadoop01 tmp]$ ls *.pid
hadoop-hadoop-datanode.pid yarn-hadoop-nodemanager.pid
hadoop-hadoop-namenode.pid yarn-hadoop-resourcemanager.pid
hadoop-hadoop-secondarynamenode.pid yarn-hdfs-resourcemanager.pid
[hadoop@hadoop01 tmp]$
[hadoop@hadoop01 tmp]$ cat hadoop-hadoop-datanode.pid
8990
[hadoop@hadoop01 tmp]$ jps
12060 Jps
9193 SecondaryNameNode
9566 NodeManager
8990 DataNode
9450 ResourceManager
kill -0 cat /tmp/hadoop-hadoop-datanode.pid
—shell常用kill pid方式`
原创文章,作者:carmelaweatherly,如若转载,请注明出处:https://blog.ytso.com/196185.html