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)
Fix variable descriptions and time warp c6125d87147ca8c5e0814413fe077f7975876ef5 Nicolas Schier 2016-01-07 06:20:35
Release version 1.5 994531a35f868f4d45785071f05abc0e07713094 Nicolas Schier 2015-11-23 06:32:11
Add initial package changelog dbd7982fd79a543ef667fbba85e9bd68fa0dcfed Nicolas Schier 2014-12-01 06:45:06
Fix time warp option e167817bf449025d6735fcdc766a18ce6dd413b7 Nicolas Schier 2015-11-23 06:28:25
Add time warp option daabd47ed7dead927c73f86138e7142526225938 Nicolas Schier 2014-11-13 06:58:37
Split and update version/license and usage info 88e3f4ebca1538e5a8591fd63489d94af0df1592 Nicolas Schier 2014-11-13 06:58:37
Generate version from git during build ceb670bb1634adeb8fe16d33135fd5695dec35fe Nicolas Schier 2014-11-13 06:58:37
Add initial .gitignore fa29b20af8707188f441053912e6940946ee3824 Nicolas Schier 2014-11-13 06:58:37
Makefile: update and allow compile flag changes via command line dc6d56da99351bb8e51cb219b5224c81ea473788 Nicolas Schier 2014-11-13 06:58:37
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 c6125d87147ca8c5e0814413fe077f7975876ef5 - Fix variable descriptions and time warp
Signed-off-by: Nicolas Schier <nicolas@hjem.rpa.no>
Author: Nicolas Schier
Author date (UTC): 2016-01-07 06:20
Committer name: Nicolas Schier
Committer date (UTC): 2016-01-07 06:20
Parent(s): 994531a35f868f4d45785071f05abc0e07713094
Signing key:
Tree: c3a90bf856270218fd1aab2bbfc1c6b35c7024ce
File Lines added Lines deleted
sleepenh.c 9 10
File sleepenh.c changed (mode: 100644) (index 1d8e7c9..4039e7f)
... ... int main(int argc, char *argv[]) {
102 102 struct timezone tz; struct timezone tz;
103 103 struct itimerval itv; struct itimerval itv;
104 104 struct sigaction sigact; struct sigaction sigact;
105 double st; /* start time */
105 double st; /* sleep time */
106 106 double et; /* end time */ double et; /* end time */
107 107 double now; /* now */ double now; /* now */
108 double it; /* interval */
108 double it; /* initial time */
109 double sleep_time; /* effective time to sleep */
109 110 int warp = 0; int warp = 0;
110 111
111 112 if ((argc > 1) && if ((argc > 1) &&
 
... ... int main(int argc, char *argv[]) {
161 162 } }
162 163
163 164 et=it+st; et=it+st;
164 it=et-now;
165 sleep_time = et - now;
165 166
166 if ( it < SHORTEST_SLEEP )
167 if (sleep_time < SHORTEST_SLEEP)
167 168 { {
168 169 if (warp) { if (warp) {
169 170 /* warp in time -> loose events, but keep event regularity */ /* warp in time -> loose events, but keep event regularity */
170 171 int tmp; int tmp;
171 double interval;
172 172
173 interval = et - st;
174 tmp = (now - st) / interval;
175 et = st + tmp * interval;
173 tmp = (now - it) / st;
174 et = it + tmp * st;
176 175 } }
177 176 /* has already timed out, shorted than a timeslice */ /* has already timed out, shorted than a timeslice */
178 177 printf("%f\n",et); printf("%f\n",et);
 
... ... int main(int argc, char *argv[]) {
185 184 sigaction (SIGALRM, &sigact, NULL); sigaction (SIGALRM, &sigact, NULL);
186 185
187 186 /* set timer */ /* set timer */
188 itv.it_value.tv_sec=(long int) it;
189 itv.it_value.tv_usec=((long int) (it*1000000)) % 1000000;
187 itv.it_value.tv_sec=(long int) sleep_time;
188 itv.it_value.tv_usec=((long int) (sleep_time*1000000)) % 1000000;
190 189 itv.it_interval.tv_sec=0; itv.it_interval.tv_sec=0;
191 190 itv.it_interval.tv_usec=0; itv.it_interval.tv_usec=0;
192 191 setitimer(ITIMER_REAL,&itv,NULL); setitimer(ITIMER_REAL,&itv,NULL);
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