常常管理和監控,須要進行shell編程,直接對進程kill或者重啓操做。咱們須要進行快速定位到每一個進程的pid號
pid默認存儲在/tmp目錄node
pid內容爲進程號shell
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對象ide
咱們直接對pid文件的數字就是咱們對於的進程pidoop
[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 ResourceManagercode
kill -0 cat /tmp/hadoop-hadoop-datanode.pid
---shell經常使用kill pid方式`對象