[comp.sources.misc] v04i128: Simple nap

zeeff@b-tech.ann-arbor.mi.us.UUCP (Jon Zeeff) (10/22/88)

Posting-number: Volume 4, Issue 128
Submitted-by: "Jon Zeeff" <zeeff@b-tech.ann-arbor.mi.us.UUCP>
Archive-name: s5nap

The kernel has a method for < 1 sleeps - allow user process to do so also.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  ft.c nap.c test.c
# Wrapped by zeeff@b-tech on Mon Oct 17 10:17:48 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f ft.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"ft.c\"
else
echo shar: Extracting \"ft.c\" \(1082 characters\)
sed "s/^X//" >ft.c <<'END_OF_ft.c'
X
X/*
X   Written by Jon Zeeff umix!b-tech!zeeff
X
X   This "device driver" uses the kernel delay() call to allow calls
X   to nap() from user processes.  Nap() is like sleep, but with finer
X   resolution.
X 
X   Compile with cc -O  -c ft.c 
X
X   Written for a Sys V.3 system, but should work on others.
X
X   For Sys V.3:
X   
X   Make a new kernel according to the instructions and then:
X   mknod /dev/ft c 28 0 
X
X   modules/ft/config:
X       character(28)
X       prefix = ft 
X       functions = open, close, read
X   
X   Edit systems/system.std and add ft.
X   Copy ft.o to modules/ft/config
X
X*/
X
X#include <sys/signal.h>
X#include <sys/types.h>
X#include <sys/sysmacros.h>
X#include <sys/param.h>
X#include <sys/systm.h>
X#include <sys/buf.h>
X#include <sys/iobuf.h>
X#include <sys/conf.h>
X#include <sys/dir.h>
X#include <sys/user.h>
X#include <sys/utsname.h>
X#include <sys/elog.h>
X#include <sys/errno.h>
X#include <sys/trap.h>
X#include <sys/seg.h>
X#include <sys/map.h>
X
X/* use a raw device interface */
X
Xftopen() {}
X
Xftread(dev)
Xint dev;
X{
Xdelay(u.u_count);
Xu.u_count = 0;
X}
X
Xftwrite() {}
Xftclose() {}
X
END_OF_ft.c
if test 1082 -ne `wc -c <ft.c`; then
    echo shar: \"ft.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f nap.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"nap.c\"
else
echo shar: Extracting \"nap.c\" \(115 characters\)
sed "s/^X//" >nap.c <<'END_OF_nap.c'
X
Xnap(ticks)
Xunsigned ticks;
X{
Xstatic int fd=0;
X
Xif (fd == 0) fd = open("/dev/ft",0);
Xread(fd,(char *)0,ticks);
X
X}
X
END_OF_nap.c
if test 115 -ne `wc -c <nap.c`; then
    echo shar: \"nap.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f test.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"test.c\"
else
echo shar: Extracting \"test.c\" \(26 characters\)
sed "s/^X//" >test.c <<'END_OF_test.c'
X
Xmain()
X{
X
Xnap(1000);
X
X}
X
END_OF_test.c
if test 26 -ne `wc -c <test.c`; then
    echo shar: \"test.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
Jon Zeeff      			Branch Technology,
umix!b-tech!zeeff  		zeeff@b-tech.ann-arbor.mi.us