linux如何运⾏r脚本,从linuxshell脚本调⽤Rscript
以下似乎适⽤于我的Ubuntu机器:
#!/bin/bash
setsid Rscript example.R > &
tail -
以下是将SIGINT发送到wrapper.sh之前的⼀些相关过程:
linuxshell脚本怎么运行
5361 pts/10 00:00:00 bash
6994 ? 00:00:02 update-notifier
8519 pts/4 00:00:00 wrapper.sh
8520 ? 00:00:00 R
8521 pts/4 00:00:00 tail
在Ctrl C之后,您可以看到R仍然在运⾏,但是wrapper.sh和tail已被杀死:
5361 pts/10 00:00:00 bash
6994 ? 00:00:02 update-notifier
8520 ? 00:00:00 R
虽然附上你的Rscript […]命令&将它发送到后台,它仍然是同⼀个进程组的⼀部分,因此也接收SIGINT.
我不确定这是不是你的意图,但是因为你正在调⽤tail -f,如果没有⽤Ctrl c中断,运⾏wrapper.sh的shell即使在R进程完成后也会继续挂起.如果你想避免这种情况,以下应该可⾏,
#!/bin/bash
setsid Rscript example.R > &
tail --pid="$!" -
“$!”是执⾏的最后⼀个后台进程的进程ID(Rscript […]调⽤).