Pausing/suspending entire Erlang program

余生颓废 提交于 2019-12-13 04:50:52

问题


Is there a simple way to suspend/pause an entire Erlang program without resorting to using OS commands (e.g. sysinternals pssuspend for Windows)?

Ideally I would like to resume the program on return from an external program.


回答1:


As W55tKQbuRu28Q4xv said you can "pause" process.

To perform that and not lose all the messages that were sent to your process while it was paused do selective receive. Assuming that your process is a gen_server it can look like this:

handle_info(pause, State) ->
    receive 
        unpause ->
            {noreply, State}
    end;

Note that all messages will be there, in receiving queue of your process. So if you are processing messages in a way dependant on system clock value, you need to move time sampling to sender process.




回答2:


I think the short answer to my question is 'no'.

You can send a pause message to all processes. However it is difficult to know in what order processes will stop and there could be a relatively large time delay if a lot of processes are used. In the end I did use pssuspend to do this:

In Erlang:

runmyscript() ->
  receive
       updatemodel->
           os:cmd("start myscript.bat"),
...
end.

In myscript.bat

pssuspend werl.exe
mycommands
...
pssuspend -r werl.exe
exit


来源:https://stackoverflow.com/questions/13033527/pausing-suspending-entire-erlang-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!