Closed smallst closed 4 years ago
Can I just use ps -ef
only?
pid:
ps -ef |grep openclash_watchdog.sh |grep -v grep |awk '{print $1}' 2>/dev/null
@vernesong $1
of ps -ef
returns the UID
instead of PID
, so just using ps -ef
would break the kill_watchdog
logic which needs the PID
to kill process. so i use a cut
to cut the first column of ps -ef
output.
Or you should change the awk print $1
to print $2
when using full ps. that's not friendly i think
verify the latest commit
@vernesong oh, i think maybe i didn't express myself clearly. but the ps from busybox cannot accept the -ef
option:
that's why i use a unify_ps
function to handle different ps
and unify them into one behavior
by the way, little update for unfiy_ps
because busybox-ps also not accept --version
function unify_ps() {
if [ $(ps --version 2>&1|grep -c procps-ng) -eq 1 ];
then
ps -ef|cut -d ' ' -f 2-
else
ps
fi
}
maybe use the ps without -ef is simply. So, I should try to verify the ps version first
@vernesong yeah , with busybox-ps only ps
is fine. but for procps-ng need the ps -ef
. don't know why procps-ng's ps don't show all process...
and busybox-ps is default for openwrt, while many distribution replace it with procps-ng, which is default for linux. what a pity
actually i want to create a pr for this, but i'm not familiar with luci-app develop. so i will post my opinion to support the procps-ng ps.
the key problem now for watchdog not running and cannot be killed is some openwrt has procps-ng version of ps command. mentioned in https://github.com/vernesong/OpenClash/issues/588. so they need use
ps -ef
and the pid of output is$2
. i think following code will help that:then if we replace the
ps
command withunify_ps
, i think both version of ps can work normally to check watchdog and kill watchdog.the key problem i met is how to define this function to all of scripts(.lua, .sh) in luci-app. the force way to do that is define the function in each scripts. i think is not a good idea. maybe you know how to achive that.