What's new

Defunct cfg_server Zombies

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Here is probably the best and safest option.


Code:
#!/bin/sh

i=1

pid_loc="$(basename "$0")"
procs="cfg_server"
if [ "$(pidof "$pid_loc" | wc -w)" -gt 1 ]; then exit; fi
while [ "$(pidof "$procs" | wc -w)" -le 3 ]; do sleep 1; done
for pid in "$(pidof "$procs")"; do
   if [ "$i" -gt "3" ]; then
      #echo $i
      #echo $pid
      /bin/kill -s 9 $pid
      /usr/bin/logger "Running /jffs/sbin/zomg_cfg_server"
   fi
   i=$((i + 1))
done
 
Last edited:
it does I tested it. You can test it with simple echo inside the terminal. when dealing with numbers that is Pidof returns numbers and we are telling it to execute a legit command.
Hmmm, OK. I'll take your word for it.

However, when I ran the following simple test in my Ubuntu terminal:

Bash:
#!/bin/bash

procs="$(pidof init)"
while [ "$(printf "%s" "$($procs)" | wc -w)" -le 1 ] ; do echo "IDs=[$procs]" ; break ; done

This is the result:

Code:
<MY_PROMPT>$ ./TESTING.sh
./TESTING.sh: line 4: 9: command not found
IDs=[9 8 1]

IOW, with the syntax $($procs) the conditional statement ends up trying to execute the 1st PID value of "9" as a command, which is obviously incorrect and not what it's intended.
 
Hmmm, OK. I'll take your word for it.

However, when I ran the following simple test in my Ubuntu terminal:

Bash:
#!/bin/bash

procs="$(pidof init)"
while [ "$(printf "%s" "$($procs)" | wc -w)" -le 1 ] ; do echo "IDs=[$procs]" ; break ; done

This is the result:

Code:
<MY_PROMPT>$ ./TESTING.sh
./TESTING.sh: line 4: 9: command not found
IDs=[9 8 1]

IOW, with the syntax $($procs) the conditional statement ends up trying to execute the 1st PID value of "9" as a command, which is obviously incorrect and not what it's intended.
Like I said having "pidof someprogram'" is what would be executed and the returned values will be read. Which is intended.

Obviously you can't execute a list of values though. But you can execute pidof in which the numbers get read back.
 
Hmmm, OK. I'll take your word for it.

However, when I ran the following simple test in my Ubuntu terminal:

Bash:
#!/bin/bash

procs="$(pidof init)"
while [ "$(printf "%s" "$($procs)" | wc -w)" -le 1 ] ; do echo "IDs=[$procs]" ; break ; done

This is the result:

Code:
<MY_PROMPT>$ ./TESTING.sh
./TESTING.sh: line 4: 9: command not found
IDs=[9 8 1]

IOW, with the syntax $($procs) the conditional statement ends up trying to execute the 1st PID value of "9" as a command, which is obviously incorrect and not what it's intended.
Look at my original post on the matter https://www.snbforums.com/threads/defunct-cfg_server-zombies.77650/page-2#post-750101


Code:
#!/bin/sh

i=1

pid_loc="pidof $(basename "$0")"
procs="pidof cfg_server"

if [ "$(printf "%s" "$($pid_loc)" | wc -w)" -gt 1 ]; then exit; fi
while [ "$(printf "%s" "$($procs)" | wc -w)" -le 3 ]; do sleep 1; done

for pid in $($procs); do
   if [ "$i" -gt "3" ]; then
      #echo $i
      #echo $pid
      /bin/kill -s 9 $pid
      /usr/bin/logger "Running /jffs/sbin/zomg_cfg_server"
   fi
   i=$((i + 1))
done

syntax is key.

Code:
pid_loc="pidof $(basename "$0")"

procs="pidof cfg_server"
 
Last edited:
Hmmm, OK. I'll take your word for it.

However, when I ran the following simple test in my Ubuntu terminal:

Bash:
#!/bin/bash

procs="$(pidof init)"
while [ "$(printf "%s" "$($procs)" | wc -w)" -le 1 ] ; do echo "IDs=[$procs]" ; break ; done

This is the result:

Code:
<MY_PROMPT>$ ./TESTING.sh
./TESTING.sh: line 4: 9: command not found
IDs=[9 8 1]

IOW, with the syntax $($procs) the conditional statement ends up trying to execute the 1st PID value of "9" as a command, which is obviously incorrect and not what it's intended.
just for giggles

Code:
RT-AX88U-C7C0:/tmp/home/root# it="pidof init"
RT-AX88U-C7C0:/tmp/home/root# echo "$($it)"
1

for the encore

Code:
RT-AX88U-C7C0:/tmp/home/root# pidof init
1
 
Ah yes, that absolutely works. No question.
The problem with
Code:
procs="$(pidof cfg_server)"

as you pointed out initially is that it is called at the time we establish the variable. so the while loop runs infinitely.

without the $( ) in the initial variable, we don't call it since we don't expand.

putting $( ) only in the while loop means we call each time the loop runs.
 
I bet we can even shorten it.

from
Code:
...
procs="pidof cfg_server"

while [ "$(printf "%s" "$($procs)" | wc -w)" -le 3 ]; do sleep 1; done
...

to

Code:
...
procs="pidof cfg_server"

while [ "$($procs | wc -w)" -le 3 ]; do sleep 1; done
...
 
fully shortened would look like this.

Code:
#!/bin/sh

i=1

pid_loc="pidof $(basename "$0")"
procs="pidof cfg_server"

if [ "$($pid_loc | wc -w)" -gt 1 ]; then exit; fi
while [ "$($procs | wc -w)" -le 3 ]; do sleep 1; done

for pid in $($procs); do
   if [ "$i" -gt "3" ]; then
      #echo $i
      #echo $pid
      /bin/kill -s 9 $pid
      /usr/bin/logger "Running /jffs/sbin/zomg_cfg_server"
   fi
   i=$((i + 1))
done
 
i know this is over a year old and I’m so, so sorry, but

I went so far as to read the BusyBox source code and can confidently report that the XT8 (RT-AX95Q) is cursed. Its implementation of `pidof` appears to actually be an implementation of `pidof -s`. It only returns the highest PID.

Code:
# ps wT | grep cfg_server | wc -l
1013
# pidof cfg_server
25795

and it is killing me. I’ll save the lengthy tirade on the webui being functionally unusable and just focus on needing to deal with tribble cfg_server processes.

My bash skills are middling at best. Implementing the zomg_cfg_server script has been an absolute ride on an XT8 (every line needed one thing or another changed), but I’m absolutely stymied at not having a list of PIDs for the `for` to iterate over. i’ve probably put 20 hours into my webui issues over the past couple of weeks and honestly it feels like i’ve read 80% of the SNB forums for one reason or another. Now that I have discovered/confirmed greedy cfg_server processes are the actual issue, i’m ready to come plead for pointers.
 
i know this is over a year old and I’m so, so sorry, but

I went so far as to read the BusyBox source code and can confidently report that the XT8 (RT-AX95Q) is cursed. Its implementation of `pidof` appears to actually be an implementation of `pidof -s`. It only returns the highest PID.

Code:
# ps wT | grep cfg_server | wc -l
1013
# pidof cfg_server
25795

and it is killing me. I’ll save the lengthy tirade on the webui being functionally unusable and just focus on needing to deal with tribble cfg_server processes.

My bash skills are middling at best. Implementing the zomg_cfg_server script has been an absolute ride on an XT8 (every line needed one thing or another changed), but I’m absolutely stymied at not having a list of PIDs for the `for` to iterate over. i’ve probably put 20 hours into my webui issues over the past couple of weeks and honestly it feels like i’ve read 80% of the SNB forums for one reason or another. Now that I have discovered/confirmed greedy cfg_server processes are the actual issue, i’m ready to come plead for pointers.

@evolempt

If you have Entware installed, you can opkg install pidof for a more robust version.

Otherwise, you'll have to use ps, grep, and for to iterate through the cfg_server pids.

Kind Regards,


Gary
 
i know this is over a year old and I’m so, so sorry, but

I went so far as to read the BusyBox source code and can confidently report that the XT8 (RT-AX95Q) is cursed. Its implementation of `pidof` appears to actually be an implementation of `pidof -s`. It only returns the highest PID.

Code:
# ps wT | grep cfg_server | wc -l
1013
# pidof cfg_server
25795

and it is killing me. I’ll save the lengthy tirade on the webui being functionally unusable and just focus on needing to deal with tribble cfg_server processes.

My bash skills are middling at best. Implementing the zomg_cfg_server script has been an absolute ride on an XT8 (every line needed one thing or another changed), but I’m absolutely stymied at not having a list of PIDs for the `for` to iterate over. i’ve probably put 20 hours into my webui issues over the past couple of weeks and honestly it feels like i’ve read 80% of the SNB forums for one reason or another. Now that I have discovered/confirmed greedy cfg_server processes are the actual issue, i’m ready to come plead for pointers.
if you can't manage to get a working pidof, you could always do:

Code:
#!/bin/sh

i=1

pid_loc="pidof $(basename "$0")"
procs="ps wT | awk '/cfg_server/{if( $0 !~ /awk/)printf "%s ", $1}'"

if [ "$($pid_loc | wc -w)" -gt 1 ]; then exit; fi
while [ "$($procs | wc -w)" -le 3 ]; do sleep 1; done

for pid in $($procs); do
   if [ "$i" -gt "3" ]; then
      #echo $i
      #echo $pid
      /bin/kill -s 9 $pid
      /usr/bin/logger "Running /jffs/sbin/zomg_cfg_server"
   fi
   i=$((i + 1))
done
 
i know this is over a year old and I’m so, so sorry, but

I went so far as to read the BusyBox source code and can confidently report that the XT8 (RT-AX95Q) is cursed. Its implementation of `pidof` appears to actually be an implementation of `pidof -s`. It only returns the highest PID.

Code:
# ps wT | grep cfg_server | wc -l
1013
# pidof cfg_server
25795

and it is killing me. I’ll save the lengthy tirade on the webui being functionally unusable and just focus on needing to deal with tribble cfg_server processes.

My bash skills are middling at best. Implementing the zomg_cfg_server script has been an absolute ride on an XT8 (every line needed one thing or another changed), but I’m absolutely stymied at not having a list of PIDs for the `for` to iterate over. i’ve probably put 20 hours into my webui issues over the past couple of weeks and honestly it feels like i’ve read 80% of the SNB forums for one reason or another. Now that I have discovered/confirmed greedy cfg_server processes are the actual issue, i’m ready to come plead for pointers.
When you get a chance, run this command. I want to see what the output looks like.

ps wT | awk '/cfg_server/{if( $0 !~ /awk/)printf "%s\n", $0}'

I want to see if we can make our script more clever.
 
When you get a chance, run this command. I want to see what the output looks like.

ps wT | awk '/cfg_server/{if( $0 !~ /awk/)printf "%s\n", $0}'

I want to see if we can make our script more clever.

@SomeWhereOverTheRainBow

I was thinking something more along the lines of

Code:
ps wT | grep cfg_server | grep -v grep | grep -ioE "^\s*([0-9]+)\s+"

Great to see you're still around.
 
@evolempt

If you have Entware installed, you can opkg install pidof for a more robust version.

Otherwise, you'll have to use ps, grep, and for to iterate through the cfg_server pids.

Kind Regards,


Gary
🤦🏻‍♀️ never even crossed my mind. I generally avoid replacing packages like that but i’m absolutely not a purist about it.

When you get a chance, run this command. I want to see what the output looks like.

ps wT | awk '/cfg_server/{if( $0 !~ /awk/)printf "%s\n", $0}'

I want to see if we can make our script more clever.
truly my lack of sed/awk skills are my greatest professional shame. This 👆🏻 gets me the same output as ps wT | grep cfg_server does.

this however ps wT | awk '/cfg_server/{if( $0 !~ /awk/)printf "%s ", $1}' produces the output we would expect out of pidof.

I maybe fell down a rabbit hole today, but I have a functional script for my XT8.

Code:
#!/bin/sh


i=1
awk_pidof() { ps wT | awk '/\scfg_server/{if( $0 !~ /awk/)printf "%s ", $1}'; }

if [ "$(ps wT | grep $(basename "$0") | wc -l)" -gt 3 ]; then
  # has to be gt 2 because otherwise grep gets caught in the dragnet
  # gt 3 because… for some reason there are always 2 zomg processes?
  echo "Exiting zombie slayer because it thinks it's a duplicate process"
  exit;
fi

while [ "$(awk_pidof | wc -w)" -le 5 ]; do sleep 1; done

for pid in $(awk_pidof); do
   if [ "$i" -gt "5" ]; then
      # echo $i
      # echo "killing pid $pid"
      /bin/kill -s 9 $pid
      /usr/bin/logger "Zombie slayer killing pid $pid"
   fi
   i=$((i + 1))
done
 
# gt 3 because… for some reason there are always 2 zomg processes?

@evolempt

It has been my observation that there are always 3 good cfg_server processes and anything greater than 3 cfg_server processes have a tendency to want to eat brains.

My router has been rock solid, since implementing the zomg_cfg_server script.

Glad you have a working solution.

Kind Regards,


Gary
 
lol this thing is spawning processes almost faster than i can kill them, this cannot be the best way to deal with this problem.
 
lol this thing is spawning processes almost faster than i can kill them, this cannot be the best way to deal with this problem.

@evolempt

The XT8 might have a higher number of good cfg_server threshold. You might try increasing the greater than to 4, 5, 6, etc, until finding the right good cfg_server balance?

Kind Regards,


Gary
 

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top