运行命令作为后台进程/服务 [英] Running a command as a background process/service

查看:177
本文介绍了运行命令作为后台进程/服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Shell命令,我想在后台运行,并且我被后面添加,这是可以做到的&安培; 来的命令,它使其作为后台进程运行,但我需要一些更多的功能,不知道如何去它:

I have a Shell command that I'd like to run in the background and I've read that this can be done by suffixing an & to the command which causes it to run as a background process but I need some more functionality and was wondering how to go about it:


  1. 我想的命令来启动并在后台每次运行系统重新启动。

  2. 我希望能够能够启动和停止的,必要时,就像人能做到服务的Apache2启动

  1. I'd like the command to start and run in the background every time the system restarts.
  2. I'd like to be able to able to start and stop it as and when needed just like one can do service apache2 start.

我怎么能去呢?是否有一个工具,可以让我运行一个命令作为服务?

How can I go about this? Is there a tool that allows me to run a command as a service?

我有点这个丢失。

感谢

推荐答案

看看在守护的命令,它可以打开任意进程为守护进程。这将使你的脚本作为一个守护进程,而不需要你做很多额外的工作。下一步是在系统启动时自动调用它。要知道正确的方式来做到这一点,你需要提供你的操作系统(或者,对于Linux,您的分布)。

Take a look at the daemon command, which can turn arbitrary processes into daemons. This will allow your script to act as a daemon without requiring you to do a lot of extra work. The next step is to invoke it automatically at boot. To know the correct way to do that, you'll need to provide your OS (or, for Linux, your distribution).

这篇关于运行命令作为后台进程/服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆