inb*_*aly 3 shell erlang operating-system localhost httpserver
我正在使用 http-server 来将http://localhost:8484加载到特定文件夹上。(出于测试目的)我在代码中运行的操作系统命令是:
http-server -p 8484 test/
Run Code Online (Sandbox Code Playgroud)
下载完我运行的任何内容后:
http-server stop
Run Code Online (Sandbox Code Playgroud)
然而,测试完成后,我看到端口8484的http服务器仍然存在!
通过跑步ps aux | grep http
我应该运行什么命令才能停止它?
我在 erlang 中的代码:
my_test_() ->
Pid = spawn(fun() ->
Info = os:cmd("http-server -p 8484 test/resources"),
io:format(user,"*** Server: ~p~n",[Info])
end),
%%% Do some job %%%
Pid2 = spawn(fun() ->
Info = os:cmd("http-server stop"),
timer:sleep(200),
io:format(user,"*** Server stop: ~p~n",[Info])
end),
timer:sleep(200),
exit(Pid2, kill),
exit(Pid, kill).
Run Code Online (Sandbox Code Playgroud)
使用:
kill -9 {pid}
Run Code Online (Sandbox Code Playgroud)
另外,出于兴趣,如果您想查看特定端口上运行的所有进程,请使用:
lsof -i :{port}
Run Code Online (Sandbox Code Playgroud)
编辑:使用kill -9 ...有点苛刻,我知道,可能有一种更优雅的方法,但它确实完成了工作;-)
| 归档时间: |
|
| 查看次数: |
18227 次 |
| 最近记录: |