From owner-freebsd-bugs Wed Jul 23 22:20:04 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id WAA09352 for bugs-outgoing; Wed, 23 Jul 1997 22:20:04 -0700 (PDT) Received: (from gnats@localhost) by hub.freebsd.org (8.8.5/8.8.5) id WAA09344; Wed, 23 Jul 1997 22:20:02 -0700 (PDT) Resent-Date: Wed, 23 Jul 1997 22:20:02 -0700 (PDT) Resent-Message-Id: <199707240520.WAA09344@hub.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@FreeBSD.ORG, denny1@home.com Received: (from nobody@localhost) by hub.freebsd.org (8.8.5/8.8.5) id WAA09252; Wed, 23 Jul 1997 22:18:35 -0700 (PDT) Message-Id: <199707240518.WAA09252@hub.freebsd.org> Date: Wed, 23 Jul 1997 22:18:35 -0700 (PDT) From: denny1@home.com To: freebsd-gnats-submit@FreeBSD.ORG X-Send-Pr-Version: www-1.0 Subject: bin/4154: wish /bin/sleep handled fractions of a second. Sender: owner-freebsd-bugs@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk >Number: 4154 >Category: bin >Synopsis: wish /bin/sleep handled fractions of a second. >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Jul 23 22:20:01 PDT 1997 >Last-Modified: >Originator: Denny Gentry >Organization: >Release: N/A >Environment: Fix was developed on OpenBSD. >Description: I have often wished /bin/sleep could sleep for less than one second, in the inner loop of a script which I want to slow down slightly. Such a feature would be an extension to POSIX, which deals only with full seconds. This has been implemented in OpenBSD. The crucial portion of the code I submitted there has been pasted below. It would be nice to get such an extension adopted more widely in *BSD, so portable scripts could use it. >How-To-Repeat: /bin/sleep 0.5 wish it worked the way you want. >Fix: /* $OpenBSD: sleep.c,v 1.6 1997/06/29 08:09:21 denny Exp $ */ cp = *argv; while ((*cp != '\0') && (*cp != '.')) { if (!isdigit(*cp)) usage(); secs = (secs * 10) + (*cp++ - '0'); } /* Handle fractions of a second */ if (*cp == '.') { *cp++ = '\0'; for (i = 100000000; i > 0; i /= 10) { if (*cp == '\0') break; if (!isdigit(*cp)) usage(); nsecs += (*cp++ - '0') * i; } } rqtp.tv_sec = (time_t) secs; rqtp.tv_nsec = nsecs; if ((secs > 0) || (nsecs > 0)) (void)nanosleep(&rqtp, NULL); >Audit-Trail: >Unformatted: