Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #12494 > unrolled thread

HOW2 capture time of power-failure?

Started bynot.socialnetwork@gmail.com
First post2014-10-26 17:38 +0000
Last post2014-11-08 03:32 +0000
Articles 12 on this page of 32 — 13 participants

Back to article view | Back to comp.os.linux.misc


Contents

  HOW2 capture time of power-failure? not.socialnetwork@gmail.com - 2014-10-26 17:38 +0000
    Re: HOW2 capture time of power-failure? Ian Malcolm <See.My.Sig.for.email@totally.invalid> - 2014-10-26 18:26 +0000
      Re: HOW2 capture time of power-failure? not.socialnetwork@gmail.com - 2014-10-27 18:10 +0000
        Re: HOW2 capture time of power-failure? Gordon Henderson <gordon+usenet@drogon.net> - 2014-10-27 18:29 +0000
          Re: HOW2 capture time of power-failure? not.socialnetwork@gmail.com - 2014-10-28 21:26 +0000
        Re: HOW2 capture time of power-failure? William Unruh <unruh@invalid.ca> - 2014-10-28 04:56 +0000
          Re: HOW2 capture time of power-failure? Dom <domafp@blueyonder.co.uk> - 2014-10-28 06:29 +0000
            Re: HOW2 capture time of power-failure? William Unruh <unruh@invalid.ca> - 2014-10-28 06:41 +0000
              Re: HOW2 capture time of power-failure? not.socialnetwork@gmail.com - 2014-10-29 00:12 +0000
    Re: HOW2 capture time of power-failure? William Unruh <unruh@invalid.ca> - 2014-10-26 19:23 +0000
      Re: HOW2 capture time of power-failure? spam-no-spam@Freeola.net.invalid (Windmill) - 2014-11-04 13:19 +0000
        Re: HOW2 capture time of power-failure? William Unruh <unruh@invalid.ca> - 2014-11-05 21:56 +0000
          Re: HOW2 capture time of power-failure? Joe Beanfish <joebeanfish@nospam.duh> - 2014-11-06 14:12 +0000
          Re: HOW2 capture time of power-failure? nba@users.sourceforge.net (Niels Baggesen) - 2014-11-06 16:15 +0100
            Re: HOW2 capture time of power-failure? William Unruh <unruh@invalid.ca> - 2014-11-06 16:00 +0000
          Re: HOW2 capture time of power-failure? spam-no-spam@Freeola.net.invalid (Windmill) - 2014-11-06 20:37 +0000
        Re: HOW2 capture time of power-failure? Joe Beanfish <joebeanfish@nospam.duh> - 2014-11-06 14:13 +0000
    Re: HOW2 capture time of power-failure? andrew@cucumber.demon.co.uk (Andrew Gabriel) - 2014-10-26 20:28 +0000
    Re: HOW2 capture time of power-failure? Joe Beanfish <joebeanfish@nospam.duh> - 2014-10-27 13:17 +0000
    Re: HOW2 capture time of power-failure? Jean-David Beyer <jeandavid8@verizon.net> - 2014-10-28 13:43 -0400
      Re: HOW2 capture time of power-failure? Ant <ant@zimage.comANT> - 2014-10-29 08:18 -0700
    Re: HOW2 capture time of power-failure? Joe Beanfish <joebeanfish@nospam.duh> - 2014-10-29 13:28 +0000
      Re: HOW2 capture time of power-failure? not.socialnetwork@gmail.com - 2014-10-30 08:32 +0000
        background processes (was HOW2 capture time of power-failure?) Joe Beanfish <joebeanfish@nospam.duh> - 2014-10-30 13:16 +0000
          Re: background processes (was HOW2 capture time of power-failure?) not.socialnetwork@gmail.com - 2014-11-03 03:25 +0000
            Re: background processes (was HOW2 capture time of power-failure?) "David W. Hodgins" <dwhodgins@nomail.afraid.org> - 2014-11-02 23:34 -0500
            Re: background processes (was HOW2 capture time of power-failure?) William Unruh <unruh@invalid.ca> - 2014-11-03 08:25 +0000
            Re: background processes (was HOW2 capture time of power-failure?) Martin Gregorie <martin@address-in-sig.invalid> - 2014-11-03 12:56 +0000
              Re: background processes (was HOW2 capture time of power-failure?) not.socialnetwork@gmail.com - 2014-11-06 19:19 +0000
                Re: background processes (was HOW2 capture time of power-failure?) Martin Gregorie <martin@address-in-sig.invalid> - 2014-11-07 02:36 +0000
                Re: background processes (was HOW2 capture time of power-failure?) Joe Beanfish <joebeanfish@nospam.duh> - 2014-11-07 14:28 +0000
                  Re: background processes (was HOW2 capture time of power-failure?) not.socialnetwork@gmail.com - 2014-11-08 03:32 +0000

Page 2 of 2 — ← Prev page 1 [2]


#12554

FromAnt <ant@zimage.comANT>
Date2014-10-29 08:18 -0700
Message-ID<8JednQqK-vTPmMzJnZ2dnUU7-YmdnZ2d@earthlink.com>
In reply to#12543
On 10/28/2014 10:43 AM PT, Jean-David Beyer typed:

 > I have an APC SMART-2200 UPS on my machine and I run apcupsd on it. So
> when the power fails, it logs that (to the second) and when it comes
> back, it logs that too after the reboot is complete.

Ditto on my Linux/Debian boxes too. :) Just remember to tell BIOS to 
automatically turn on power after a power loss. :/
-- 
"He who storms in like a whirlwind returns like an ant." --Borneo
    /\___/\         Ant(Dude) @ http://antfarm.ma.cx (Personal Web Site)
   / /\ /\ \                Ant's Quality Foraged Links: http://aqfl.net
  | |o   o| |
     \ _ /        If crediting, then use Ant nickname and AQFL URL/link.
      ( )         If e-mailing, then axe ANT from its address if needed.
Ant is currently not listening to any songs on this computer.

[toc] | [prev] | [next] | [standalone]


#12553

FromJoe Beanfish <joebeanfish@nospam.duh>
Date2014-10-29 13:28 +0000
Message-ID<m2qq1o$4ms$1@dont-email.me>
In reply to#12494
On Sun, 26 Oct 2014 17:38:12 +0000, not.socialnetwork wrote:

> I need to capture the time-after-a-sound-file-starts-playing until the
> power is cut, with a resolution of 30 secs., over a period of 30
> minutes.
> 
> While `ogg123  SoundFie.ogg` is playing, could the play-time be updated
> every 30 secs?  How?
> 
> == TIA.
> 
> PS. power-cuts without `umount` are no problem for rPi's SD nor USBstik.

A different take on this...

ogg123 prints it's progress. You could start a frequent sync in the
background (if the default system sync isn't frequent enough). Then
redirect stderr of ogg123 to a file. Later you can examine the last
timestamp in that file to see how far you got. Looking back farther
in the file you can also find which file was being played.

$ ogg123 TheBrightestStar.ogg 2>oggtime
$ tr '\015' '\012' <oggtime


Audio Device:   PulseAudio Output





Playing: TheBrightestStar.ogg


Ogg Vorbis stream: 2 channel, 22050 Hz


Time: 00:00.34 [00:04.65] of 00:04.99  (133.0 kbps)  Output Buffer 100.0% 

                                                                           
Time: 00:01.03 [00:03.96] of 00:04.99  ( 96.8 kbps)  Output Buffer  77.8% 

                                                                           
Time: 00:01.71 [00:03.28] of 00:04.99  (109.5 kbps)  Output Buffer 100.0% 

                                                                           
Time: 00:02.40 [00:02.59] of 00:04.99  (100.5 kbps)  Output Buffer  88.9% 

                                                                           
Time: 00:03.09 [00:01.91] of 00:04.99  ( 97.9 kbps)  Output Buffer  77.8% 

                                                                     

[toc] | [prev] | [next] | [standalone]


#12557

Fromnot.socialnetwork@gmail.com
Date2014-10-30 08:32 +0000
Message-ID<m2st2a$af2$1@dont-email.me>
In reply to#12553
In article <m2qq1o$4ms$1@dont-email.me>, Joe Beanfish <joebeanfish@nospam.duh> wrote: 

> On Sun, 26 Oct 2014 17:38:12 +0000, not.socialnetwork wrote:
> 
> > I need to capture the time-after-a-sound-file-starts-playing until the
> > power is cut, with a resolution of 30 secs., over a period of 30
> > minutes.
> > 
> > While `ogg123  SoundFie.ogg` is playing, could the play-time be updated
> > every 30 secs?  How?
> > 
> > == TIA.
> > 
> > PS. power-cuts without `umount` are no problem for rPi's SD nor USBstik.
> 
> A different take on this...
> 
> ogg123 prints it's progress. You could start a frequent sync in the
> background (if the default system sync isn't frequent enough). Then
> redirect stderr of ogg123 to a file. Later you can examine the last
> timestamp in that file to see how far you got. Looking back farther
> in the file you can also find which file was being played.
> 
> $ ogg123 TheBrightestStar.ogg 2>oggtime
> $ tr '\015' '\012' <oggtime
> 
> Audio Device:   PulseAudio Output
> 
> Playing: TheBrightestStar.ogg
> 
> Ogg Vorbis stream: 2 channel, 22050 Hz
> 
> Time: 00:00.34 [00:04.65] of 00:04.99  (133.0 kbps)  Output Buffer 100.0% 
>                                                                            
> Time: 00:01.03 [00:03.96] of 00:04.99  ( 96.8 kbps)  Output Buffer  77.8% 
>                                                                            
> Time: 00:01.71 [00:03.28] of 00:04.99  (109.5 kbps)  Output Buffer 100.0% 
>                                                                            
> Time: 00:02.40 [00:02.59] of 00:04.99  (100.5 kbps)  Output Buffer  88.9% 
>                                                                            
> Time: 00:03.09 [00:01.91] of 00:04.99  ( 97.9 kbps)  Output Buffer  77.8% 
> 
Yes!!  That's a better/direct way, which I've partially confirmed.

But I want to also test/confirm the general method, for apps which don't
have the special facilities of ogg123, that you were able to use.

I need to read-up on 'starting/stopping background/foreground' processes,
after I've cleared some other chaos here.

Thanks.



[toc] | [prev] | [next] | [standalone]


#12558 — background processes (was HOW2 capture time of power-failure?)

FromJoe Beanfish <joebeanfish@nospam.duh>
Date2014-10-30 13:16 +0000
Subjectbackground processes (was HOW2 capture time of power-failure?)
Message-ID<m2tdmr$hi8$1@dont-email.me>
In reply to#12557
On Thu, 30 Oct 2014 08:32:11 +0000, not.socialnetwork wrote:
> But I want to also test/confirm the general method, for apps which don't
> have the special facilities of ogg123, that you were able to use.
> 
> I need to read-up on 'starting/stopping background/foreground'
> processes,
> after I've cleared some other chaos here.

Use "&" to start something in the background.
Use "$!" to get the pid of the last background process started.
Use "wait" to wait for a (or all) background process(es) to finish.
Use "kill" to stop a background process.
Here's something to start playing with:

#!/bin/sh
echo "foreground pid $$ starting"
(echo "background started";sleep 5;echo "background finished") &
bgpid=$!
sleep 1
# wait around for background process to finish before quitting
#echo "waiting for background pid $bgpid"
#wait $bgpid
# stop background process before quitting
echo "killing background pid $bgpid"
kill $bgpid
echo "foreground pid $$ finished"

[toc] | [prev] | [next] | [standalone]


#12592 — Re: background processes (was HOW2 capture time of power-failure?)

Fromnot.socialnetwork@gmail.com
Date2014-11-03 03:25 +0000
SubjectRe: background processes (was HOW2 capture time of power-failure?)
Message-ID<m36sik$5a9$1@dont-email.me>
In reply to#12558
In article <m2tdmr$hi8$1@dont-email.me>, Joe Beanfish <joebeanfish@nospam.duh> wrote: 

> On Thu, 30 Oct 2014 08:32:11 +0000, not.socialnetwork wrote:
> > But I want to also test/confirm the general method, for apps which don't
> > have the special facilities of ogg123, that you were able to use.
> > 
> > I need to read-up on 'starting/stopping background/foreground'
> > processes,
> > after I've cleared some other chaos here.
> 
> Use "&" to start something in the background.
> Use "$!" to get the pid of the last background process started.
> Use "wait" to wait for a (or all) background process(es) to finish.
> Use "kill" to stop a background process.
> Here's something to start playing with:
> 
> #!/bin/sh
> echo "foreground pid $$ starting"
> (echo "background started";sleep 5;echo "background finished") &
> bgpid=$!
> sleep 1
> # wait around for background process to finish before quitting
> #echo "waiting for background pid $bgpid"
> #wait $bgpid
> # stop background process before quitting
> echo "killing background pid $bgpid"
> kill $bgpid
> echo "foreground pid $$ finished"

--- Nice tutorial. Thanks.

I've spent quite some time trying to analyse your code.
The very 1st line [of linux syntax] is problematic for me:
 apparently the EVALUATION of <pid $$> [what ever that is]
 is embedded in the reporting of <pid $$>.
 
IMO <linux syntax> has too many hidden-hooks to catch you;
like special rules for the 17th Tuesday of a non-leap-year.

After the multics OS failed, from excess complexity, Unix was
a spoof-name, trying to emphasise simplicity.  
Later, the blokes who designed unix abandoned it, for a simpler
design: plan9.

IMO prose is not a suitable substitute notation for a musical-score.

Here's a more graphic notation. Time moves-left-to-right.
  [..(...).]..

timer starts = [  
play starts = ( 
play ends = )
timer detects that play ended and records time and then stops = ]




[toc] | [prev] | [next] | [standalone]


#12593 — Re: background processes (was HOW2 capture time of power-failure?)

From"David W. Hodgins" <dwhodgins@nomail.afraid.org>
Date2014-11-02 23:34 -0500
SubjectRe: background processes (was HOW2 capture time of power-failure?)
Message-ID<op.xoqezub5a3w0dxdave@hodgins.homeip.net>
In reply to#12592
On Sun, 02 Nov 2014 22:25:08 -0500, <not.socialnetwork@gmail.com> wrote:

> In article <m2tdmr$hi8$1@dont-email.me>, Joe Beanfish <joebeanfish@nospam.duh> wrote:

>> echo "foreground pid $$ starting"

> I've spent quite some time trying to analyse your code.
> The very 1st line [of linux syntax] is problematic for me:
>  apparently the EVALUATION of <pid $$> [what ever that is]
>  is embedded in the reporting of <pid $$>.

The string pid is just a string that (like the string foreground),
just gets echoed to the terminal.

The $$ get's replaced by the process id number of the current
shell process.

See http://tldp.org/LDP/abs/html/internalvariables.html in the
section 'Other Special Parameters'.

Also see the page http://tldp.org/LDP/abs/html/quotingvar.html

$ echo "$$"
9569
$ echo '$$'
$$

Regards, Dave Hodgins

-- 
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)

[toc] | [prev] | [next] | [standalone]


#12594 — Re: background processes (was HOW2 capture time of power-failure?)

FromWilliam Unruh <unruh@invalid.ca>
Date2014-11-03 08:25 +0000
SubjectRe: background processes (was HOW2 capture time of power-failure?)
Message-ID<m37e6d$gf6$1@dont-email.me>
In reply to#12592
On 2014-11-03, not.socialnetwork@gmail.com <not.socialnetwork@gmail.com> wrote:
> In article <m2tdmr$hi8$1@dont-email.me>, Joe Beanfish <joebeanfish@nospam.duh> wrote: 
>
>> On Thu, 30 Oct 2014 08:32:11 +0000, not.socialnetwork wrote:
>> > But I want to also test/confirm the general method, for apps which don't
>> > have the special facilities of ogg123, that you were able to use.
>> > 
>> > I need to read-up on 'starting/stopping background/foreground'
>> > processes,
>> > after I've cleared some other chaos here.
>> 
>> Use "&" to start something in the background.
>> Use "$!" to get the pid of the last background process started.
>> Use "wait" to wait for a (or all) background process(es) to finish.
>> Use "kill" to stop a background process.
>> Here's something to start playing with:
>> 
>> #!/bin/sh
>> echo "foreground pid $$ starting"
>> (echo "background started";sleep 5;echo "background finished") &
>> bgpid=$!
>> sleep 1
>> # wait around for background process to finish before quitting
>> #echo "waiting for background pid $bgpid"
>> #wait $bgpid
>> # stop background process before quitting
>> echo "killing background pid $bgpid"
>> kill $bgpid
>> echo "foreground pid $$ finished"
>
> --- Nice tutorial. Thanks.
>
> I've spent quite some time trying to analyse your code.
> The very 1st line [of linux syntax] is problematic for me:
>  apparently the EVALUATION of <pid $$> [what ever that is]
>  is embedded in the reporting of <pid $$>.
Not Linux. bash
man bash
$$ is the pid (program identifier) of the current program ( the script
in this case).
So that line produces the output
foreground pid 783 starting
where 783 is actually the number for the script itself. 

>  
> IMO <linux syntax> has too many hidden-hooks to catch you;
> like special rules for the 17th Tuesday of a non-leap-year.

Not Linux. bash. And not hidden, but you do need to learn it. 

AFter this your comments degenerate.
...
>
>
>
>
>

[toc] | [prev] | [next] | [standalone]


#12595 — Re: background processes (was HOW2 capture time of power-failure?)

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2014-11-03 12:56 +0000
SubjectRe: background processes (was HOW2 capture time of power-failure?)
Message-ID<m37u1s$vl2$1@dont-email.me>
In reply to#12592
On Mon, 03 Nov 2014 03:25:08 +0000, not.socialnetwork wrote:

> After the multics OS failed, from excess complexity, Unix was a
> spoof-name, trying to emphasise simplicity.
> Later, the blokes who designed unix abandoned it, for a simpler design:
> plan9.
>
You've got that backward. Multics was quite successful in its day but, 
being quite a large system, was too expensive to have many installations. 
The project started in 1964, there were 80 Multics installations and the 
last one was decomissioned in 2000. I don't call that failure. The ideas 
behind it had a big influence on many of the later OSes. 

See: https://en.wikipedia.org/wiki/Multics  for details.

Plan 9 is arguably less successful than Unix: I've used several Unix 
flavours but never seen a Plan 9 system. In any case both have been more 
or less totally eclipsed by Linux.

==========
You may find the following script a little easier to follow when it runs 
that the original. I've added a parameter to switch between killing the 
background task: 

	tscript

and waiting for it to end: 

	tscript wait 

I've also changed the echoed output to make the source of the various 
messages a bit clearer:


========================start of tscript=========================
#!/bin/sh 
echo "Foreground: pid $$ starting"
(echo "   Background: started";sleep 5;echo "   Background: finished") &
bgpid=$!
echo "Foreground: background with pid $bgpid is running"
sleep 1 

# wait around for background process to finish before quitting
if [ "$1" == 'wait' ]
then
   echo "Foreground: waiting for background pid $bgpid to end"
   wait $bgpid
else 
   echo "Foreground: stopping background process before quitting" 
   echo "Foreground: killing background pid $bgpid"
   kill -9 $bgpid
fi 
echo "Foreground: pid $$ finished"
======================== end of tscript =========================

The script has 18 lines: if you see fewer, this will be due to some lines 
having been combined by your newsreader, so descramble this version 
before trying to run it.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

[toc] | [prev] | [next] | [standalone]


#12645 — Re: background processes (was HOW2 capture time of power-failure?)

Fromnot.socialnetwork@gmail.com
Date2014-11-06 19:19 +0000
SubjectRe: background processes (was HOW2 capture time of power-failure?)
Message-ID<m3ghj1$p5h$1@dont-email.me>
In reply to#12595
In article <m37u1s$vl2$1@dont-email.me>, Martin Gregorie <martin@address-in-sig.invalid> wrote: 

> On Mon, 03 Nov 2014 03:25:08 +0000, not.socialnetwork wrote:
> 
>...
> I've also changed the echoed output to make the source of the various 
> messages a bit clearer:

========================start of tscript=========================
#!/bin/sh 
echo "Foreground: pid $$ starting"
(echo "   Background: started";sleep 5;echo "   Background: finished") &
bgpid=$!
echo "Foreground: background with pid $bgpid is running"
sleep 1 

# wait around for background process to finish before quitting
if [ "$1" == 'wait' ]
then
   echo "Foreground: waiting for background pid $bgpid to end"
   wait $bgpid
else 
   echo "Foreground: stopping background process before quitting" 
   echo "Foreground: killing background pid $bgpid"
   kill -9 $bgpid
fi 
echo "Foreground: pid $$ finished"
======================== end of tscript ====================

OK thanks, but I don't see your "top" structure.
Is there ONE foreground, and potentially multiple background PIDs,
   hence "the latest background"?
For my application, I want the player to be the boss - to start the timer.
For 'civilised' code, the player would also switch-off the timer, which
would have recorded to LastTimeStamp.
For my application: cutting the power automatically syncronises the
<playEnd>  and last-TimeStamp.

Is this Top-structure valid?
  StartPlay
  (date > TimeStamp; sleep 5) &  <- needs DoForever LOOP ?!
  
!! No !! That's no good, because my existing code doesn't step on
to the 'next instruction', until the `play` is finished.
So the background timer would need to be started before the `play`.

Normal coding methods don't apply.
This is perhaps easier for someone who has no coding experience/habits?
Apparently multiprocessing is a whole new/different theory?




[toc] | [prev] | [next] | [standalone]


#12647 — Re: background processes (was HOW2 capture time of power-failure?)

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2014-11-07 02:36 +0000
SubjectRe: background processes (was HOW2 capture time of power-failure?)
Message-ID<m3hb7m$bj5$2@dont-email.me>
In reply to#12645
On Thu, 06 Nov 2014 19:19:01 +0000, not.socialnetwork wrote:

> In article <m37u1s$vl2$1@dont-email.me>, Martin Gregorie
> <martin@address-in-sig.invalid> wrote:
> 
>> On Mon, 03 Nov 2014 03:25:08 +0000, not.socialnetwork wrote:
>> 
>>...
>> I've also changed the echoed output to make the source of the various
>> messages a bit clearer:
> 
> ========================start of tscript=========================
> #!/bin/sh echo "Foreground: pid $$ starting"
> (echo "   Background: started";sleep 5;echo "   Background: finished") &
> bgpid=$!
> echo "Foreground: background with pid $bgpid is running"
> sleep 1
> 
> # wait around for background process to finish before quitting if [ "$1"
> == 'wait' ]
> then
>    echo "Foreground: waiting for background pid $bgpid to end" wait
>    $bgpid
> else
>    echo "Foreground: stopping background process before quitting"
>    echo "Foreground: killing background pid $bgpid"
>    kill -9 $bgpid
> fi echo "Foreground: pid $$ finished"
> ======================== end of tscript ====================
> 
> OK thanks, but I don't see your "top" structure.
>
Everything in the script is the foreground process except for line 3, 

  (....)&

which is the background process that is controlled by the foreground 
process.

Since you don't seem to have the technical background to understand the 
what we've been saying about interprocess communication, here's some 
advice: get hold of "UNIX Systems Programming for SVR4" and work your way 
through Chapter 11, 'Processes', compiling and running the example code 
and experimenting with it until you understand what's going on. Depending 
on your experience you may find that you need to work through several 
other chapters too. 

If you're serious about your project, you'll do the reading and should be 
able to complete it without further help from here.  
      

-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

[toc] | [prev] | [next] | [standalone]


#12648 — Re: background processes (was HOW2 capture time of power-failure?)

FromJoe Beanfish <joebeanfish@nospam.duh>
Date2014-11-07 14:28 +0000
SubjectRe: background processes (was HOW2 capture time of power-failure?)
Message-ID<m3ikud$dvn$1@dont-email.me>
In reply to#12645
On Thu, 06 Nov 2014 19:19:01 +0000, not.socialnetwork wrote:

> In article <m37u1s$vl2$1@dont-email.me>, Martin Gregorie
> <martin@address-in-sig.invalid> wrote:
...
> For my application, I want the player to be the boss - to start the
> timer.
> For 'civilised' code, the player would also switch-off the timer, which
> would have recorded to LastTimeStamp.
> For my application: cutting the power automatically syncronises the
> <playEnd>  and last-TimeStamp.
> 
> Is this Top-structure valid?
>   StartPlay (date > TimeStamp; sleep 5) &  <- needs DoForever LOOP ?!
>   
> !! No !! That's no good, because my existing code doesn't step on to the
> 'next instruction', until the `play` is finished.
> So the background timer would need to be started before the `play`.

Correct. Something like this perhaps:

#!/bin/sh
while :;do date > TimeStamp;sleep 5;done &
bgpid=$!
StartPlay
kill $bgpid
rm -f TimeStamp

Or, you could flip it on it's head and run player in background with
stamper in fore.

#!/bin/sh
StartPlay &
bgpid=$!
# run forever until StartPlay finishes (process no longer exists)
while kill -s 0 $bgpid 2>/dev/null;do
	date >TimeStamp
done
rm -f TimeStamp

[toc] | [prev] | [next] | [standalone]


#12649 — Re: background processes (was HOW2 capture time of power-failure?)

Fromnot.socialnetwork@gmail.com
Date2014-11-08 03:32 +0000
SubjectRe: background processes (was HOW2 capture time of power-failure?)
Message-ID<m3k2rn$nlu$1@dont-email.me>
In reply to#12648
In article <m3ikud$dvn$1@dont-email.me>, Joe Beanfish <joebeanfish@nospam.duh> wrote: 

> On Thu, 06 Nov 2014 19:19:01 +0000, not.socialnetwork wrote:
> > For my application, I want the player to be the boss - to start the
> > timer.
> > For 'civilised' code, the player would also switch-off the timer, which
> > would have recorded to LastTimeStamp.
> > For my application: cutting the power automatically syncronises the
> > <playEnd>  and last-TimeStamp.
> > ...
> > So the background timer would need to be started before the `play`.
> 
> Correct. Something like this perhaps:
> 
> #!/bin/sh
> while :;do date > TimeStamp;sleep 5;done &
> bgpid=$!
> StartPlay
> kill $bgpid
> rm -f TimeStamp
> ---
That seems to test GOOD on the live-PC.
I'll test by power-cut on rPi later.
 
JB.sh ==
#!/bin/sh
echo "IF State=Skip THEN PlayFrom(TimeStamp)"
echo -n "Previous TimeStamp="; cat TimeStamp

while :;do date > TimeStamp;sleep 5;done &
bgpid=$!
echo StartPlay;sleep 25
echo StillPlaying;sleep 25
echo "After Play stop: kill BakPID"
kill $bgpid
echo "TimeStamp is used by next Start/PowerUp:" 
echo -n "Currently="
cat TimeStamp 

exit 0

log of 2 consecutive runs ==
IF State=Skip THEN PlayFrom(TimeStamp)
Previous TimeStamp=Sat Nov  8 05:08:19 SAST 2014
StartPlay
StillPlaying
After Play stop: kill BakPID
TimeStamp is used by next Start/PowerUp:
Currently=Sat Nov  8 05:12:19 SAST 2014
./JB.sh: line 13: 20334 Terminated              while :; do
    date >TimeStamp; sleep 5;
done
===
IF State=Skip THEN PlayFrom(TimeStamp)
Previous TimeStamp=Sat Nov  8 05:12:19 SAST 2014
StartPlay
StillPlaying
After Play stop: kill BakPID
TimeStamp is used by next Start/PowerUp:
Currently=Sat Nov  8 05:13:57 SAST 2014
./JB.sh: line 13: 20360 Terminated              while :; do
    date >TimeStamp; sleep 5;
done
===

Thanks, I'll report the rPi live-test-results.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.os.linux.misc


csiph-web