<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 12, 2019 at 7:30 AM Allen Edwards <<a href="mailto:allen.p.edwards@gmail.com">allen.p.edwards@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 12, 2019 at 3:53 AM Stephen Worthington <<a href="mailto:stephen_agent@jsw.gen.nz" target="_blank">stephen_agent@jsw.gen.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, 11 Mar 2019 09:41:08 -0700, you wrote:<br>
<br>
>On Sun, Mar 10, 2019 at 7:31 PM Stephen Worthington <<br>
><a href="mailto:stephen_agent@jsw.gen.nz" target="_blank">stephen_agent@jsw.gen.nz</a>> wrote:<br>
><br>
>> On Sun, 10 Mar 2019 14:59:19 -0700, you wrote:<br>
>><br>
>> >I added a 10 second delay and the problem is gone, no duplicate instances<br>
>> >of myth. Maybe 3 seconds would work but definitely a race condition.<br>
>> Other<br>
>> >than the delay, the code is the same as original.<br>
>> ><br>
>> >In fairness to the code, my test is not real life. Typically if I were to<br>
>> >do a CTRL-ALT-BS it would be because myth was frozen or missing. I don't<br>
>> >know that I ever did a CTRL-ALT-BS just as a test with Myth running. The<br>
>> >timing might be different and the service might be killed faster if it is<br>
>> >actually frozen. Or maybe I am wrong and this really is an issue. Either<br>
>> >way, it should not keep piling on instances of mythfrontend. But at least<br>
>> >I think we know what is going on now.<br>
>> ><br>
>> >Allen<br>
>><br>
>> Using a delay to fix a race condition is usually a bad idea -<br>
>> something happens which changes the timing, such as a bit of swapping<br>
>> going on, and then the problem is back again.<br>
>><br>
>> Unfortunately, mythfrontend does die quite often for me. The usual<br>
>> cause is playing a downloaded video file. I have quite a few that it<br>
>> can not handle, and either it dies, or locks up and I have to kill it.<br>
>> Some of the deaths leave behind "assert failed" messages. But if you<br>
>> do not normally play such files, then mythfrontend can be very<br>
>> reliable and not need the wrapper script.<br>
>><br>
>> It looks like the wrapper script needs to be able to detect that the<br>
>> script itself is still running and to exit if it can see another copy<br>
>> of itself. This should work to do that:<br>
>><br>
>> pid=$(ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep<br>
>> -v grep | awk '{print $2}')<br>
>> if [ ${#pid} -ne 0 ]; then<br>
>> exit 0<br>
>> fi<br>
>> _______________________________________________<br>
>><br>
>> I do not understand why this does not work but I am no script expert so I<br>
>am not sure what exactly is going on with ${#pid} and how that relates to<br>
>the initial pid. Perhaps there is a $ missing or misplaced on the first<br>
>line? I did run some tests.<br>
><br>
>*dad@NewMyth:~$ ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' |<br>
>grep -v grep*<br>
>*dad 2310 1 0 09:17 ? 00:00:00 /bin/sh<br>
>/usr/bin/mythfrontend --service*<br>
>*dad 2605 1 0 09:17 ? 00:00:00 /bin/sh<br>
>/usr/bin/mythfrontend --service*<br>
>*dad 2961 2939 0 09:17 ? 00:00:00 /bin/sh<br>
>/usr/bin/mythfrontend --service*<br>
><br>
>And<br>
><br>
>*dad@NewMyth:~$ ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' |<br>
>grep -v grep | awk '{print $2}'*<br>
>*2310*<br>
>*2605*<br>
>*2961*<br>
><br>
>For now I will just run mythfrontend without the --service option. That<br>
>should be fine for my needs. I am still willing to troubleshoot this if you<br>
>think that would be useful so let me know.<br>
><br>
>I wish to thank both Stephen and Ian for your help.<br>
><br>
>Allen<br>
<br>
$(#pid} is the number of characters in the $pid string. If there are<br>
any copies of mythfrontend running, then the $pid string should be a<br>
list of the PIDs for those copies (actually, a list of the PIDs of the<br>
bash tasks running those copies of the scripts). So if there are no<br>
other copies of mythfrontend running, $pid should be an empty string,<br>
and ${#pid} should be 0. I tested it using this script (t1.sh):<br>
<br>
#!/bin/bash<br>
pid=$(ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep<br>
-v grep | awk '{print $2}')<br>
echo $pid<br>
echo ${#pid}<br>
if [ ${#pid} -ne 0 ]; then<br>
echo "pid != 0"<br>
fi<br>
<br>
On my MythTV box, it displays the "pid != 0" string whenever it finds<br>
a copy of the mythfrontend script running. If I add an extraneous<br>
character to the grep string (eg an extra d on the end of<br>
"mythfrontend", it gets no matches and continues on to the end of the<br>
script without doing the echo.<br>
_______________________________________________<br><br></blockquote><div>I have not tested it yet but I think the problem I had was I copied and pasted the script you wrote without changes and the word wrap that put a return between grep and -v grep would generate an error. I tested the components of it but put it all on one line when I did that and did not realize that the script would not run as posted. Pretty stupid mistake on my part. </div><div><br></div><div>Your script as it came across the email</div><div>pid=$(ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep<br>-v grep | awk '{print $2}')<br>if [ ${#pid} -ne 0 ]; then<br> exit 0<br>fi </div><div><br></div><div>A corrected version</div>pid=$(ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep -v grep | awk '{print $2}')<br>if [ ${#pid} -ne 0 ]; then<br> exit 0<br><div>fi <br></div><div><br></div><div>I would be shocked if this did not work but can't test it now.</div><div><br></div><div>Allen</div><div><div><br></div></div><div><br></div></div></div></blockquote><div><br></div><div>I put these lines in the beginning of /usr/share/mythtv/mythfrontend.sh</div><div><br></div><div><div><b>pid=$(ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep -v grep | awk '{print $2}')</b></div><div><b>if [ ${#pid} -ne 0 ]; then</b></div><div><b> exit 0</b></div><div><b>fi</b></div></div><div><br></div><div>Myth would not start at power up or on a CTRL-ALT-BS. I cannot find my error.</div><div><br></div><div>Back to no <b>--service</b> option</div><div><br></div><div>Allen</div><div><br></div></div></div></div></div>