UnixSysCalls.mx
Copyright Ó 1989, 1990, 1991 by Xerox Corporation. All rights reserved.
Created by Michael Plass, May 18, 1989
Michael Plass, December 2, 1991 10:01 am PST
Last changed by Pavel on April 1, 1990 5:33 pm PDT
(cedar-imports "UnixSpawn" "PFS" "UnixSysCalls" "SchemeSys")
(cedar-directory "Rope" "UnixTypes")
(cedar-require "Require Cedar UnixCommands UnixSpawn")
(release-as "Cedar" "Scheme")
(
primitive-enable
UnixSpawn.Error => {
Complain[code, msg];
};
)
devNull:
ROPE = "/dev/null";
DeScheme:
PROC [ref:
REF, inP:
BOOL]
RETURNS [
REF] = {
SELECT ref
FROM
undefined, true => ref ← SchemeSys.GetPort[undefined, inP];
false => ref ← devNull;
ENDCASE => {
WITH ref
SELECT
FROM
string: Scheme.String => ref ← RopeFromString[string];
ENDCASE => NULL;
};
RETURN [ref]
};
DeCedar:
PROC [a:
REF]
RETURNS [
REF] = {
WITH a
SELECT
FROM
lora: LIST OF REF => RETURN [Cons[lora.first, DeCedar[lora.rest]]];
rope: ROPE => RETURN [StringFromRope[rope]];
ENDCASE => RETURN [a];
};
(define-proc (
unix-spawn cmd-string (stdin) (stdout) (stderr))
fork a (Unix) process to run cmd, attaching its standard input, output and error file descriptors to the files named by stdin, stdout, stderr. n.b. the files may be named pipes.
The returned value is the exit status of the spawned process or #f for failure.
"fork a (Unix) process to run cmd, attaching its standard input, output and error file descriptors to the files named by stdin, stdout, stderr"
stdin ← DeScheme[stdin, TRUE];
stdout ← DeScheme[stdout, FALSE];
stderr ← DeScheme[stderr, FALSE];
result ← DeCedar[UnixSpawn.Spawn[command: RopeFromString[TheString[cmdString]], stdin: stdin, stdout: stdout, stderr: stderr, wd: PFS.RopeFromPath[PFS.GetWDir[]], exec: TRUE, tty: FALSE, debug: FALSE].details];
)
(define-proc (
unix-getpid)
"get unix process id"
result ← MakeFixnum[UnixSysCalls.GetPID[]];
)
(define-proc (
unix-getppid)
"get unix parent process id"
result ← MakeFixnum[UnixSysCalls.GetPPID[]];
)
(define-proc (
unix-getpgrp pid)
"get unix process group"
result ← MakeFixnum[UnixSysCalls.GetPGrp[KCheck[pid]]];
)
(define-proc (
unix-kill pid signal)
"kill (signal) a unix process"
res: UnixTypes.SysCallResult = UnixSysCalls.Kill[KCheck[pid], VAL[KCheck[signal]]];
result ← IF res=success THEN true ELSE false;
)
(define-proc (
unix-killpg pid signal)
"kill (signal) a unix process group"
res: UnixTypes.SysCallResult = UnixSysCalls.KillPG[KCheck[pid], VAL[KCheck[signal]]];
result ← IF res=success THEN true ELSE false;
)