等待子进程,但得到错误:"pid不是此shell的子进程" [英] wait child process but get error: 'pid is not a child of this shell'

查看:412
本文介绍了等待子进程,但得到错误:"pid不是此shell的子进程"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个脚本来从HDFS并行获取数据,然后在for循环中等待这些子进程,但有时它返回"pid不是此shell的子进程".有时候效果很好.这真令人困惑.我使用"jobs -l"来显示所有在后台运行的作业.我确定这些pid是Shell进程的子进程,并且我使用"ps aux"来确保将这些pid注意分配给其他进程.这是我的脚本.

I write a script to get data from HDFS parrallel,then I wait these child processes in a for loop, but sometimes it returns "pid is not a child of this shell". sometimes, it works well。It's so puzzled. I use "jobs -l" to show all the jobs run in the background. I am sure these pid is the child process of the shell process, and I use "ps aux" to make sure these pids is note assign to other process. Here is my script.

PID=()
FILE=()
let serial=0

while read index_tar
do
        echo $index_tar | grep index > /dev/null 2>&1

        if [[ $? -ne 0 ]]
        then
                continue
        fi

        suffix=`printf '%03d' $serial`
        mkdir input/output_$suffix
        $HADOOP_HOME/bin/hadoop fs -cat $index_tar | tar zxf - -C input/output_$suffix \
                && mv input/output_$suffix/index_* input/output_$suffix/index &

        PID[$serial]=$!
        FILE[$serial]=$index_tar

        let serial++

done < file.list

for((i=0;i<$serial;i++))
do
        wait ${PID[$i]}

        if [[ $? -ne 0 ]]
        then
                LOG "get ${FILE[$i]} failed, PID:${PID[$i]}"
                exit -1
        else
                LOG "get ${FILE[$i]} success, PID:${PID[$i]}"
        fi
done

推荐答案

只需找到您要等待的进程的进程ID,并在下面的脚本中将其替换为12345.可以根据您的要求进行进一步的更改.

Just find the process id of the process you want to wait for and replace that with 12345 in below script. Further changes can be made as per your requirement.

#!/bin/sh
PID=12345
while [ -e /proc/$PID ]
do
    echo "Process: $PID is still running" >> /home/parv/waitAndRun.log
    sleep .6
done
echo "Process $PID has finished" >> /home/parv/waitAndRun.log

/usr/bin/waitingScript.sh

/usr/bin/waitingScript.sh

http://iamparv. blogspot.in/2013/10/unix-wait-for-running-process-not-child.html

这篇关于等待子进程,但得到错误:"pid不是此shell的子进程"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆