在 Ubuntu 中“启动进程”有多种方式,取决于你想启动的是临时命令、后台服务、开机自启程序还是系统服务。下面按常见场景说明:
./your_program
或
python3 app.py
关闭终端会结束进程。
./your_program &
或
nohup python3 app.py &
&:后台运行nohup:终端关闭也不退出ps aux | grep your_program
或
top
htop
kill PID
kill -9 PID
sudo nano /etc/systemd/system/myservice.service
示例:
[Unit]
Description=My Service
After=network.target
[Service]
ExecStart=/usr/bin/python3 /home/user/app.py
WorkingDirectory=/home/user
Restart=always
User=user
[Install]
WantedBy=multi-user.target
sudo systemctl start myservice
sudo systemctl enable myservice
systemctl status myservice
sudo systemctl stop myservice
sudo systemctl restart myservice
crontabcrontab -e
添加:
@reboot /home/user/start.sh
nohup python3 app.py &
docker run -d image_name
sudo systemctl start nginx
如果你能说明:
我可以给你更精确的启动方式。