问题
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