Answer the question
In order to leave comments, you need to log in
How to know if a process is running?
To track file changes on the disk I use:
https://github.com/gregghz/Watcher
When I run it, everything works, but over time, it stops working.
I restart it and it works again
How to check that it is working at the current moment?
1) I check pid, it exists:
[email protected]:~$ll /root/.watcher/watcher.pid
-rw-rw-rw- 1 root root 5 июн 3 08:38 /root/.watcher/watcher.pid
[email protected]:~$ps ax | grep watcher
1980 ? Sl 0:01 python /usr/bin/watcher.py start
3198 pts/0 S+ 0:00 grep watcher
/etc/rc.local#!/bin/sh -e
watcher.py stop
watcher.py start
exit 0
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
chmod +x /etc/rc.local
systemctl enable rc-local
systemctl start rc-local
Answer the question
In order to leave comments, you need to log in
why crowns and other crutches, if there is a systemd ??
write the appropriate unit and systemd itself will start the process and restart in case of a crash.
You can use the universal cross-platform solution - psutil (pip install psutil).
import psutil
for proc in psutil.process_iter():
name = proc.name()
print(name)
if name == "program.exe":
pass
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question