[英]How to make a process run on AWS EC2 even after closing the local machine?
I have a script that will take around 10-15 hours to complete. 我有一个脚本大约需要10-15个小时才能完成。 I want to run it on EC2 instance and after say 10 hours stop the process forever.
我想在EC2实例上运行它,然后说10个小时后永远停止进程。
Approaches-- Approaches--
CRONTAB
-if I make a cronjob for the process . CRONTAB
如果我为这个过程做了一个cronjob。 How to ensure it runs only once in lifetime and delete after 10 hour? 如何确保它在生命周期中只运行一次并在10小时后删除?
You need to open a screen session. 您需要打开一个屏幕会话。 You can do this by typing
screen
in the bash prompt. 您可以通过在bash提示符下键入
screen
来执行此操作。 Once you have fired in your command, type Ctrl-a
followed by d
. 触发命令后,键入
Ctrl-a
然后键入d
。 This will detach your screen session. 这将分离您的屏幕会话。 However the script that you run will continue to run.
但是,您运行的脚本将继续运行。
Now, you can disconnect from your ssh session. 现在,您可以断开与ssh会话的连接。 And once you log back in, you can
resume
your session by typing in screen -r
. 一旦您重新登录,您可以通过键入
screen -r
来resume
会话。 This is assuming that you have only one detached
session. 这假设您只有一个
detached
会话。 In case you have more than one, you will have to type in the pid of the session you want to attach back to. 如果您有多个,则必须输入要附加回的会话的pid。
To check the pid
of the session, you can do: 要检查会话的
pid
,您可以执行以下操作:
ps aux | grep screen
This will list out the currently running screen processes. 这将列出当前正在运行的屏幕进程。 A sample output is:
示例输出是:
dhanush 1327 0.0 0.0 2443312 56 s000 S+ 3Sep15 0:00.99 screen -r server -p server
dhanush 79037 0.0 0.0 2432784 600 s008 S+ 5:03PM 0:00.00 grep screen
Here the pid
for the relevant screen process is 1327
. 这里相关屏幕过程的
pid
是1327
。 The second line belongs to the grep
command that searched for the keyword screen
itself. 第二行属于搜索关键字
screen
本身的grep
命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.