Daemon started multiple times and DaemonService's getExecutable() called multiple times

Hello,

I’m working on a URCap and I noticed one of my daemon is started multiple times. The daemon executable is a script. How I check that? I wrote a little script to check the process id with pgrep in loop. What I observe is the PID changed 2-5 times at first and then settle on one. This is an example of pgrep loop:

5444 script.sh
5444 script.sh
5444 script.sh
5444 script.sh
5444 script.sh
5444 script.sh
71212 script.sh
71212 script.sh
71212 script.sh
71212 script.sh
71212 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
9382 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
56712 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
31230 script.sh
...

After seeing this, I logged the getExecutable() method called from the URCapAPI in DaemonService class. What I noticed is the method is called 5 times every time PolyScope starts. The init(...) method is always called once. I’m working on multiple URCaps and this seems to be happening on them as well but not the same amount of times. Sometimes getExecutable() is called twice or even 6 times. Something to note is getExecutable() is always called the same amount of times for a particular DaemonService.

The reason I’ve investigated on this is I have a problem with one of my script doing its job and seeing multiple scripts started made me wondering if that could be caused by 2 scripts trying to start the same process at the same time.

So my questions are:

  1. Why is getExecutable() called multiple times?
  2. What can I do to prevent this?