nicolas / sleepenh (public) (License: GPL-2+) (since 2018-10-19) (hash sha1)
Sleep until a given date with subsecond resolution

`sleepenh` is a sleep program for shell scripts that need to perform
a loop that repeats at a regular time interval, without cumulative errors.

It supports microsecond resolution.

You can also specify the time you need between two calls of `sleepenh`.
List of commits:
Subject Hash Author Date (UTC)
Imported Upstream version 1.3 619a817e508c4b35bd9b67b9b0e4988084bbdac7 Nicolas Schier 2014-10-27 08:20:30
Imported Upstream version 1.2 d5a03f27c08a277bfbb80ca84b408392600f0fe6 Nicolas Schier 2014-10-27 08:20:30
Commit 619a817e508c4b35bd9b67b9b0e4988084bbdac7 - Imported Upstream version 1.3
Author: Nicolas Schier
Author date (UTC): 2014-10-27 08:20
Committer name: Nicolas Schier
Committer date (UTC): 2014-10-27 08:20
Parent(s): d5a03f27c08a277bfbb80ca84b408392600f0fe6
Signing key:
Tree: 14563f499af2b4835e56771eb8778f46c9939abe
File Lines added Lines deleted
copyright 0 19
sleepenh.1 32 35
sleepenh.c 5 3
File copyright deleted (index d45bb87..0000000)
1 /*
2 * sleepenh.c - enhanced sleep command
3 *
4 * Copyright (C) 2003 - Pedro Zorzenon Neto
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
File sleepenh.1 changed (mode: 100644) (index 23d0281..aae1349)
1 1 .\" Hey, EMACS: -*- nroff -*- .\" Hey, EMACS: -*- nroff -*-
2 .TH SLEEPENH 1 "2003/01/22"
2 .TH SLEEPENH 1 "2008/04/20"
3 3 .\" Please adjust this date whenever revising the manpage. .\" Please adjust this date whenever revising the manpage.
4 4 .\" .\"
5 5 .\" Some roff macros, for reference: .\" Some roff macros, for reference:
 
16 16 sleepenh \- an enhanced sleep program. sleepenh \- an enhanced sleep program.
17 17 .SH SYNOPSIS .SH SYNOPSIS
18 18 .B sleepenh .B sleepenh
19 .RI [ initial-time ]
20 .RI sleep-time
19 .RI [ initial\-time ]
20 .RI sleep\-time
21 21 .SH DESCRIPTION .SH DESCRIPTION
22 22 \fBsleepenh\fP is a program that can be used when there is a need \fBsleepenh\fP is a program that can be used when there is a need
23 23 to execute some functions periodically in a shell script. It was to execute some functions periodically in a shell script. It was
24 not designed to be acurate for a single sleep, but to be
25 acurate in a sequence of consecutive sleeps.
24 not designed to be accurate for a single sleep, but to be
25 accurate in a sequence of consecutive sleeps.
26 26 .br .br
27 After a successfull execution, it returns to stdout the timestamp
28 it finished running, that can be used as \fBinitial-time\fP to a
27 After a successful execution, it returns to stdout the timestamp
28 it finished running, that can be used as \fBinitial\-time\fP to a
29 29 successive execution of \fBsleepenh\fP. successive execution of \fBsleepenh\fP.
30 30 .SH OPTIONS .SH OPTIONS
31 31 There are no command line options. Run it without any option to There are no command line options. Run it without any option to
32 32 get a brief help and version. get a brief help and version.
33 33 .SH ARGUMENTS .SH ARGUMENTS
34 \fBsleep-time\fP is a real number in seconds,
34 \fBsleep\-time\fP is a real number in seconds,
35 35 with microseconds resolution (1 minute, 20 seconds and 123456 with microseconds resolution (1 minute, 20 seconds and 123456
36 36 microseconds would be 80.123456). microseconds would be 80.123456).
37 37 .br .br
38 \fBinitial-time\fP is a real number in seconds, with microseconds
38 \fBinitial\-time\fP is a real number in seconds, with microseconds
39 39 resolution. This number is system dependent. In GNU/Linux systems, resolution. This number is system dependent. In GNU/Linux systems,
40 it is the number of seconds since midnight 1970-01-01 GMT. Do not
41 try to get a good value of \fBinitial-time\fP. Use the value suplied
40 it is the number of seconds since midnight 1970\-01\-01 GMT. Do not
41 try to get a good value of \fBinitial\-time\fP. Use the value supplied
42 42 by a previous execution of \fBsleepenh\fP. by a previous execution of \fBsleepenh\fP.
43 43 .br .br
44 If you don't specify \fBinitial-time\fP, it is assumed the current-time.
44 If you don't specify \fBinitial\-time\fP, it is assumed the current\-time.
45 45 .SH EXIT STATUS .SH EXIT STATUS
46 46 An exit status greater or equal to 10 means failure. An exit status greater or equal to 10 means failure.
47 47 Known exit status: Known exit status:
 
... ... Known exit status:
50 50 Success. Success.
51 51 .TP .TP
52 52 .B 1 .B 1
53 Success. There was no need to sleep. (means that initial-time +
54 sleep-time was greater than current-time).
53 Success. There was no need to sleep. (means that initial\-time +
54 sleep\-time was greater than current\-time).
55 55 .TP .TP
56 56 .B 10 .B 10
57 57 Failure. Missing command line arguments. Failure. Missing command line arguments.
 
... ... Failure. Argument is not a number.
65 65 .B 13 .B 13
66 66 Failure. System error, could not get current time. Failure. System error, could not get current time.
67 67 .SH USAGE EXAMPLE .SH USAGE EXAMPLE
68 Supose you need to send the char 'A' to the serial port ttyS0
68 Suppose you need to send the char 'A' to the serial port ttyS0
69 69 every 4 seconds. This will do that: every 4 seconds. This will do that:
70 .Sx
71
72 #!/bin/sh
73 TIMESTAMP=`sleepenh 0`
74 while true; do
75 # send the byte to ttyS0
76 echo -n "A" > /dev/ttyS0;
77
78 # just print a nice message on screen
79 echo -n "I sent 'A' to ttyS0, time now is ";
80 sleepenh 0;
70 .RS
71 #!/bin/sh
72 TIMESTAMP=`sleepenh 0`
73 while true; do
74 # send the byte to ttyS0
75 echo \-n "A" > /dev/ttyS0;
76
77 # just print a nice message on screen
78 echo \-n "I sent 'A' to ttyS0, time now is ";
79 sleepenh 0;
81 80
82 # wait the required time
83 TIMESTAMP=`sleepenh $TIMESTAMP 4.0`;
84 done
85
86 .Ex
81 # wait the required time
82 TIMESTAMP=`sleepenh $TIMESTAMP 4.0`;
83 done
84 .RE
87 85 .SH HINT .SH HINT
88 86 This program can be used to get the current time. Just execute: This program can be used to get the current time. Just execute:
89 87 .TP .TP
90 88 sleepenh 0 sleepenh 0
91 89 .SH BUGS .SH BUGS
92 It is not acurate for a single sleep. Short sleep-times will also not
93 be acurate.
90 It is not accurate for a single sleep. Short sleep\-times will also not
91 be accurate.
94 92 .SH SEE ALSO .SH SEE ALSO
95 93 .BR date (1), .BR date (1),
96 94 .BR sleep (1). .BR sleep (1).
97 95 .br .br
98 96 .SH AUTHOR .SH AUTHOR
99 This manual page was written by Pedro Zorzenon Neto
100 <pzn@autsens.com>.
97 This manual page was written by Pedro Zorzenon Neto.
File sleepenh.c changed (mode: 100644) (index 400d5fb..bee49dd)
14 14 * GNU General Public License for more details. * GNU General Public License for more details.
15 15 * *
16 16 * You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
19 20 * *
20 21 * USAGE INSTRUCTIONS * USAGE INSTRUCTIONS
21 22 * *
 
50 51 #include <signal.h> #include <signal.h>
51 52 #include <unistd.h> #include <unistd.h>
52 53 #include <math.h> #include <math.h>
54 #include <string.h>
53 55
54 56 #define SHORTEST_SLEEP 0.00001 /* 10msec, a timeslice */ #define SHORTEST_SLEEP 0.00001 /* 10msec, a timeslice */
55 57 #define RCSID "$Id: sleepenh.c,v 1.2 2003/02/24 17:17:48 pzn Exp $" #define RCSID "$Id: sleepenh.c,v 1.2 2003/02/24 17:17:48 pzn Exp $"
 
... ... int main(int argc, char *argv[]) {
79 81 " -- " RCSREV "\n" " -- " RCSREV "\n"
80 82 " -- " RCSDATE "\n" " -- " RCSDATE "\n"
81 83 "\n" "\n"
82 "Copyright (C) 2003 - Pedro Zorzenon Neto <pzn@autsens.com>\n"
84 "Copyright (C) 2003 - Pedro Zorzenon Neto\n"
83 85 "Distributed under the conditions of FSF/GPL2 License.\n" "Distributed under the conditions of FSF/GPL2 License.\n"
84 86 "See the source code for more copyright and license information.\n" "See the source code for more copyright and license information.\n"
85 87 "\n" "\n"
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/nicolas/sleepenh

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/nicolas/sleepenh

Clone this repository using git:
git clone git://git.rocketgit.com/user/nicolas/sleepenh

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main