问题描述
我正在一个Shell脚本中运行一个PL / SQL,该脚本从Shell终端接受该过程的IN参数。整个过程大约需要4个小时。我知道我们可以输入ctrl + z来暂停进程,然后使用bg命令将进程发送到后台重新启动。有没有办法我可以通过终端输入输入并将进程发送到后台而不挂起?
解决方法
如果我正确理解了您的要求,那么读取参数的包装脚本似乎就足够了。它可以使用&符号将PL / SQL脚本作为后台进程启动:
me:~/$ cat ./wrapper.sh
#!/bin/bash
read -p "Enter the first parameter: " p1
read -p "Enter the second parameter: " p2
read -p "Enter the third parameter: " p3
read -p "Enter the fourth parameter: " p4
./plsql.sh $p1 $p2 $p3 $p4 &
pid=$!
jobs -l
ps aux | grep -v grep | grep $pid
这是实际效果:
me:~/$ ./wrapper.sh
Enter the first parameter: a
Enter the second parameter: b
Enter the third parameter: c
Enter the fourth parameter: dd
[1]+ 151367 Running ./plsql.sh $p1 $p2 $p3 $p4 &
me 151367 0.0 0.1 6940 3404 pts/2 S+ 06:49 0:00 /bin/bash ./plsql.sh a b c dd
,
如果您希望外壳将自身置于后台,请尝试使用exec
:
if [[ -n "$stuff" ]]
then sleep "$stuff"
else read -p "gimme some input: " stuff
export stuff
exec $0 &
fi