Ending a running go process from command line

agolangf · · 650 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>How would you go about coding a command line go process that you can exit gracefully from the command line if it is already running? This isn&#39;t something I&#39;ve ever done and not sure if there are practices in go to do this or if you do this as a daemon manager.</p> <hr/>**评论:**<br/><br/>boxyburn: <pre><p><a href="http://stackoverflow.com/questions/11268943/golang-is-it-possible-to-capture-a-ctrlc-signal-and-run-a-cleanup-function-in">http://stackoverflow.com/questions/11268943/golang-is-it-possible-to-capture-a-ctrlc-signal-and-run-a-cleanup-function-in</a></p></pre>kurin: <pre><p>Handling SIGINT or SIGTERM are the most common ways on Linux, but they might give you trouble on Windows.</p> <p>Depending on your setup, you can give the user some other way of signalling the application. For example, in a goroutine you could start a web server and listen for network connections. If the user goes to <code>host:port/diediedie</code>, the application quits. You could have whatever authn/authz you like on top of that, so that jerks can&#39;t kill your jobs.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

650 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传