From: udo@umunk.GUN.de (Udo Munk)
Newsgroups: comp.os.coherent
Subject: Re: Coherent Job Control
Date: 14 Apr 92 13:26:39 GMT
Organization: none

root@fusion.cuc.ab.ca (Superuser) writes:
> Here's some code I hacked up to try to implement job control under Coherent
> with ptrace().  Applications?  See the notes at the end of the listing.  You
> may use this code in your own works, but please read the restrictions in the
> header.

Hm, you try to write a nice for Coherent? I've done it and posted it to
MWC. In 1990, just installed Coherent 3.0, i missed nice and nohup for
it, which i use frequently on other UNIX machines. Because MWC says,
the kernel is compatibel to System 7, i looked for the function nice in
libc.a, and really, there is one! But there is no documentation of this
kernel call. So i sit down, and hack my own nice and nohup. The code
runs fine, but i don't know, what it does whith Coherent's scheduler.
So if one of the developers of Coherent at MWC read this, please let
us know. Ok, here follows the code for all:
----- cut here -----
# /bin/sh
# This is a shell archive, to unbundle sh this file
echo nice.c 1>&2
cat >nice.c <<'@@@ End of nice.c @@@'
/*
 *	nice command for COHERENT
 *	Copyright (C) 1990 by Udo Munk
 *	This code is PUBLIC DOMAIN, permission is granted
 *	for unlimited personal, non-commercial use.
 */

#include <stdio.h>
#include <ctype.h>

main(argc, argv)
int argc;
char *argv[];
{
	int nicval = 10;
	extern int errno;
	extern char *sys_errlist[];
	register char *p;

	if (argc > 1 && argv[1][0] == '-') {
		p = argv[1];

		if (*++p != '-') {
			--p;
		}
		while (*++p)
			if (!isdigit(*p)) {
				fprintf(stderr, "nice: argument must be numeric.\n");
				exit(2);
			}
		nicval = atoi(&argv[1][1]);
		argc--;
		argv++;
	}
	if (argc < 2) {
		fprintf(stderr, "nice: usage: nice [-num] command\n");
		exit(2);
	}
	nice(nicval);
	execvp(argv[1], &argv[1]);
	fprintf(stderr, "%s: %s\n", sys_errlist[errno], argv[1]);
	exit(2);
}
@@@ End of nice.c @@@
echo nicec.man 1>&2
cat >nicec.man <<'@@@ End of nicec.man @@@'
.TH nice "" "Extension" Command
nice \- run a command at lower priority
.PP
.B "nice [ \-increment ] command [ arguments ]"
.PP
.I Nice
executes
.I command
with lower CPU scheduling priority. If the
.I increment
argument (in range 1\-19) is given, it is used;
if not, an increment of 10 is assumed.
.sp 1
The super\-user may run commands with priority higher than
normal by using a negative increment, e.g., \-\-10.
.SH "See Also"
.PP
nohup, nice
.SH Diagnostics
.PP
.I Nice
returns the exit status of the subject command.
.SH Notes
.PP
An
.I increment
larger than 19 is equivalent to 19.
@@@ End of nicec.man @@@
echo nices.man 1>&2
cat >nices.man <<'@@@ End of nices.man @@@'
.TH nice "" "" "COHERENT system call"
nice \- change priority of a process
.PP
int nice (incr)
.br
int incr;
.PP
.I Nice
adds the value of
.I incr
to the nice value of the calling process. A process's
.I "nice value"
is a positive number for which a more positive value results
in lower CPU priority.
.sp 1
A maximum nice value of 39 and a minimum nice value of 0 are
imposed by the system. Requests for values above or below
these limits result in the nice value being set to the
corresponding limit.
.sp 1
.I Nice
will fail [EACCES] and not change the nice value if
.I incr
is negative and the effective user ID of the calling
process is not super\-user.
.SH "See Also"
.PP
nice, exec
.SH Diagnostics
.PP
Upon successful completion,
.I nice
returns the new nice value minus 20. Otherwise, a value of
\-1 is returned and
.I errno
is set to indicate the error.
@@@ End of nices.man @@@
echo nohup.man 1>&2
cat >nohup.man <<'@@@ End of nohup.man @@@'
.TH nohup "" "Extension" Command
nohup \- run a command immune to hangup and quits
.PP
.B "nohup command [ arguments ]"
.PP
.I Nohup
executes command with hangups and quits ignored. If output
is not re\-directed by the user, both standard output and
standard error are sent to nohup.out.
.SH Example
.PP
It is frequently desirable to apply
.I nohup
to pipelines or lists of commands. This can be done only by
placing pipelines and command lists in a single file, called
a shell procedure. One can then issue:
.DS
	nohup sh file
.DE
and the
.I nohup
applies to everything in file. If the shell procedure file is
to be executed often, then the need to type sh can be eliminated
by giving file execute permission. Add a ampersand and the contents
of file are run in the background with interrupts also ignored.
.DS
	nohup file &
.DE
An example of what the contents of file could be is:
.DS
	tbl ofile | eqn | nroff > nfile
.DE
.SH "See also"
.PP
chmod, sh, signal
.SH Diagnostics
.PP
.DS
nohup command1; command2	nohup applies only to command1
nohup (command1; command2)	is syntactical incorrect
.DE
Be careful of where standard error is redirected. The following
command may put error messages on tape, making it unreadable:
.DS
	nohup cpio \-o <list >/dev/rmt/1m &
while
	nohup cpio \-o <list >/dev/rmt/1m 2>errors &
.DE
puts the error messages in file errors.
@@@ End of nohup.man @@@
echo nohup.sh 1>&2
cat >nohup.sh <<'@@@ End of nohup.sh @@@'
# run a command immune to hangup and quits
# Copyright 1990 Udo Munk
# This code is PUBLIC DOMAIN, permission is granted
# for unlimited personal, non-commercial use.
trap "" 1 15
if test -t 2>&1
then
	echo "Sending output to 'nohup.out'"
	exec nice -5 $* >>nohup.out 2>&1
else
	exec nice -5 $* 2>&1
fi
@@@ End of nohup.sh @@@
----- cut here -----

Have fun and give me some response.
---------------------------------------------------------------------------
Udo Munk                voice:      +49 2131 275348
Oberstr. 21             mail :      udo@umunk.GUN.de
4040 Neuss 1                        ...!{mcshh,smurf,unido}!easix!umunk!udo
Germany                 CompuServe: 100021,2515