2013-12-11 29 views
2

我遇到了一个奇怪的场景,正在困扰着我。当在后台启动脚本时,我得到两个运行的进程

我有我的背景与&
例如启动一个脚本:

[email protected]# some_script.sh & 

它运行后,我做了PS -ef | grep some_script,我看到两个进程正在运行,第二个进程持续获得不同的PID,但是Parent是我开始的进程(就像父进程产生的子进程一样 - 但从未写入代码中)。 示例:

[email protected]# ps -ef | grep some_script.sh 
root  4696 17882 0 13:30 pts/2 00:00:00 /bin/bash ./some_script.sh 
root  4778 4696 0 13:30 pts/2 00:00:00 /bin/bash ./some_script.sh 
[email protected]# ps -ef | grep some_script.sh 
root  4696 17882 0 13:30 pts/2 00:00:00 /bin/bash ./some_script.sh 
root  4989 4696 0 13:30 pts/2 00:00:00 /bin/bash ./some_script.sh 

这里给出了什么?它似乎也搞乱了脚本的输出和功能,并且基本上使它成为一个永无止境的过程(当我在脚本中定义了启动和停止时)。

剧本: ` #! /斌/庆典

# Set Global Variables 
LOGDIR="/srv/script_logs" 
OUTDIR="/srv/audits" 
BUCKET_LS=$OUTDIR"/LSOUT_"$i"_"$(date +%d%b%Y)".TXT" 
MYCMD1="aws s3api list-objects --bucket viddler-flvs" 
MYCMD2="--starting-token" 
MAX_ITEMS="--max-items 10000" 
MYSTARTING_TOKEN='""' 
rm tokenlog.txt flv_out.txt 

while [[ $MYSTARTING_TOKEN != "null" ]] 
do 
# First - Get the token for the next batch 
CMD_PRE="$MYCMD1 $MAX_ITEMS $MYCMD2 $MYSTARTING_TOKEN" 
MYSTARTING_TOKEN=($($CMD_PRE | jq -r .NextToken)) 
echo $MYSTARTING_TOKEN >> tokenlog.txt 
# Now - get the values of the files for the existing batch 
# First - re-run the batch and get the file values we want 
MYOUT2=$($CMD_PRE | (jq ".Contents[] | {Key, Size, LastModified,StorageClass }")) 
echo $MYOUT2 | sed 's/[{},"]//g;s/ /\n/g;s/StorageClass://g;s/LastModified://g;s/Size://g;s/Key://g;s/^ *//g;s/ *$//g' >> flv_out.txt 
#echo $STARTING_TOKEN 
done 

`

+2

你的脚本是怎么看的? – devnull

+1

我需要看到some_script.sh中的代码才能解决这个问题。 – Donovan

+1

“工作”报告是什么? – cdarke

回答

3

我猜你有

(
some shell instructions 
) 

您.SH
内这句法执行新进程的命令(但命令行是相同的)。

+0

这或管道中的shell代码(例如'somecommand | while read; do ... done');这也将运行在一个子shell中。 –

+0

我看到它更像是我命令中的管道 - 有时它是基本知识,让你;)谢谢大家! – user3091317

相关问题