Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何在bash中使用'wait'和'WSTOPPED'?_Git_Bash - Fatal编程技术网

Git 如何在bash中使用'wait'和'WSTOPPED'?

Git 如何在bash中使用'wait'和'WSTOPPED'?,git,bash,Git,Bash,假设一个父进程产生了几个子进程,这些子进程在某个点停止,但尚未终止。我希望家长等待其所有的孩子停止,这样他们就可以步调一致地工作 #collaborate-mergetool.sh BASE=$1 LOCAL=$2 REMOTE=$3 MERGED=$4 # TODO curl POST files to server # When the four files are uploaded: # STOP this process and wait for siblings. kill -

假设一个父进程产生了几个子进程,这些子进程在某个点停止,但尚未终止。我希望家长等待其所有的孩子停止,这样他们就可以步调一致地工作

#collaborate-mergetool.sh
BASE=$1
LOCAL=$2
REMOTE=$3
MERGED=$4

# TODO curl POST files to server

# When the four files are uploaded:
#   STOP this process and wait for siblings.
kill -SIGSTOP $$

# Download patch from server
# TODO curl GET "$filename".patch from server

# TODO apply patch
这可能是XY问题,所以如果有更好的方法,我洗耳恭听

我想为冲突构建一个协作git合并工具

我有一个父进程,它为每个冲突文件生成一个子进程。我缺少的是等待所有的孩子被阻止。我该怎么做

#parent.sh
# For each file in conflicting state
for f in `git ls-files --unmerged | cut -f2 | sort -u`
do
  git mergetool --tool=collaborate --no-prompt "$f" &
done

# Wait for all children to be STOPPED
wait # WSTOPPED? Not sure how to do this.

echo "All files uploaded. Visit www.example.com/abc123 to collaborate."
read -rsp $'Press enter to apply changes.\n'

# Continue all child processes.
kill -SIGCONT childpids? Need a list...

wait
echo "Finished!"
子进程必须同步工作

#collaborate-mergetool.sh
BASE=$1
LOCAL=$2
REMOTE=$3
MERGED=$4

# TODO curl POST files to server

# When the four files are uploaded:
#   STOP this process and wait for siblings.
kill -SIGSTOP $$

# Download patch from server
# TODO curl GET "$filename".patch from server

# TODO apply patch
试试这个:

不要使用等待,而是轮询所有子进程并检测处于停止状态的子进程 虽然真实;做 睡眠1 N|u CHILDREN=`jobs | wc-l` N_STOPPED=`jobs-s | wc-l` [$N_CHILDREN==$N_STOPPED]&&break 完成 使用shell sleep,您只能以1秒的粒度进行轮询

如果您有其他不想等待的子进程,则需要更具创造性并解析内置作业的输出:

STOPPED_JOBS_PIDS=`jobs -sl | awk '{print $2}'`
# Compare to my list, etc...
在某些情况下,这可能会干扰外壳本身的操作

在这种情况下,您可能需要轮询ps的输出:

...
# Get the 'stat' column and look for a T, filter by my child processes of interest
git mergetool ... & PID1=$!
git mergetool ... & PID2=$!  # etc
...
while ...
  N_CHILDREN=2 # number of processes
  N_STOPPED=`ps -o pid -o stat -p PID1 $PID2 | tail -n +2 | awk '{print $2}' | grep T | wc -l`
...

在这里,STAT列指示进程是否正在运行R、休眠S、停止T、僵尸或其他状态。

内置的等待非常有限。特别是,它不允许等待孩子被阻止。看起来您实际上需要构建一个信号量实用程序,我想您可以在bash中使用util linux包中的flock实用程序部分来实现这一点,并且不一定安装在所有发行版中。谢谢,flock看起来是一个很好的开始,但我对发行版的支持不太感兴趣。我看到一些使用mkdir作为锁的建议。我也可以试试。ps的输出是否因操作系统和用户配置而异?要收集我所有的PID,我可以在for循环之前先做pids=,然后再做pids=$pids$!在循环内部。我现在有一个以空格分隔的PID列表。我想我可以做到这一点。在收集了$PID之后,这个很好用:ps-ostat-p$pids | tail-n+2 | grep-v T。谢谢你的帮助。看起来简单的轮询就可以了。flock解决方案需要一些工作。