【发布时间】:2020-08-26 01:11:23
【问题描述】:
我正在一个 shell 脚本中运行一个 PL/SQL,该脚本接受来自 shell 终端的过程的 IN 参数。整个过程大约需要4个小时。我知道我们可以输入 ctrl+z 来暂停进程,然后使用 bg 命令将进程发送到后台重新启动。有没有办法可以通过终端输入输入并将进程发送到后台而不暂停它?
【问题讨论】:
标签: bash shell plsql procedure
我正在一个 shell 脚本中运行一个 PL/SQL,该脚本接受来自 shell 终端的过程的 IN 参数。整个过程大约需要4个小时。我知道我们可以输入 ctrl+z 来暂停进程,然后使用 bg 命令将进程发送到后台重新启动。有没有办法可以通过终端输入输入并将进程发送到后台而不暂停它?
【问题讨论】:
标签: bash shell plsql procedure
如果我正确理解您的要求,那么读取参数的包装脚本似乎就足够了。它可以使用 & 符号将您的 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
【讨论】:
如果你想让 shell 自己进入后台,试试exec:
if [[ -n "$stuff" ]]
then sleep "$stuff"
else read -p "gimme some input: " stuff
export stuff
exec $0 &
fi
【讨论】: