vbit-pi
Posts: 11
Joined: Sat Jun 11, 2016 11:25 pm

Stop Program after so long?

Sat Jun 11, 2016 11:41 pm

Hi,
I've recently been experimenting with Peter Kwan's Vbit-Pi, but noticed that the program (./go) often gets stuck or freezes after an hour or two of running. So I was wondering how I could modify the code so that every half hour or hour the program restarts?
Thanks in advance.

epoch1970
Posts: 3346
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Stop Program after so long?

Wed Jun 15, 2016 9:09 am

You could try to restart the program from a cron.d command running every 30 mins.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
RaTTuS
Posts: 10378
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Stop Program after so long?

Wed Jun 15, 2016 9:42 am

sudo kill -HUP pid
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

vbit-pi
Posts: 11
Joined: Sat Jun 11, 2016 11:25 pm

Re: Stop Program after so long?

Wed Jun 15, 2016 6:48 pm

epoch1970 wrote:You could try to restart the program from a cron.d command running every 30 mins.
How? The pid is always Changing.

epoch1970
Posts: 3346
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Stop Program after so long?

Wed Jun 15, 2016 8:46 pm

With pidof or pgrep, maybe?
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

swampdog
Posts: 221
Joined: Fri Dec 04, 2015 11:22 am

Re: Stop Program after so long?

Thu Jun 16, 2016 12:25 am

How? The pid is always Changing.
There's a myriad of ways to achieve that. The key is to obtain the correct PID. The bash shell variable "$!" will contain it. Wrap the 'go' command inside some shell script. Here's a generic example..

Code: Select all

$ cat z-app
#!/bin/bash

##
f_exit ()
{
 echo "cleanup here"
}

f_trap ()
{
 echo "*** signal ***" 1>&2
}

trap 'f_exit'		0
trap 'f_trap;exit'	1 2 3 15
##

echo "Child BEG"
sleep 10
echo "Child END"
The above equates to the 'go' app. It's just a bit of shell script which gives you a hint as to what will be happening inside 'go' when 'z-foo', your wrapper script (below), is executed..

Code: Select all

$ cat z-foo
#!/bin/bash

echo "Parent BEG"
E="z-app"
./"$E" &
P="$!"

fcp_ps ()
{
 ps -ef | grep -v grep | grep "$P" | grep "$E"
}

fcp_ps
sleep 5
R=`fcp_ps`
[ -z "$R" ] || {
	echo "Kill $P"
	kill "$P"
	sleep 1
}
echo "Parent END"
Simply..

$ ./z-foo

..to see the effect. Just for fun, I've left a bug in "fcp_ps". ie: what happens if 'go/z-app' spawns another copy of itself?

vbit-pi
Posts: 11
Joined: Sat Jun 11, 2016 11:25 pm

Re: Stop Program after so long?

Thu Jun 16, 2016 5:11 pm

Thanks, that's all I need. I've got it going now and the script no longer freezes!

Return to “General programming discussion”