From a444db0c1f6c698c6e08a4516cbf8db69bf1bdb5 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 14 May 2008 00:45:43 -0500 Subject: [PATCH] Move some words to unix.process --- extra/unix/process/process.factor | 61 +++++++++++++++++++++++++++++-- extra/unix/unix.factor | 55 ---------------------------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/extra/unix/process/process.factor b/extra/unix/process/process.factor index 48fac04a1c..644276ef7d 100755 --- a/extra/unix/process/process.factor +++ b/extra/unix/process/process.factor @@ -39,8 +39,63 @@ FUNCTION: int execve ( char* path, char** argv, char** envp ) ; : with-fork ( child parent -- ) fork-process dup zero? -roll swap curry if ; inline -: wait-for-pid ( pid -- status ) - 0 [ 0 waitpid drop ] keep *int WEXITSTATUS ; +: SIGKILL 9 ; inline +: SIGTERM 15 ; inline + +FUNCTION: int kill ( pid_t pid, int sig ) ; + +: PRIO_PROCESS 0 ; inline +: PRIO_PGRP 1 ; inline +: PRIO_USER 2 ; inline + +: PRIO_MIN -20 ; inline +: PRIO_MAX 20 ; inline + +! which/who = 0 for current process +FUNCTION: int getpriority ( int which, int who ) ; +FUNCTION: int setpriority ( int which, int who, int prio ) ; : set-priority ( n -- ) - 0 0 rot setpriority io-error ; \ No newline at end of file + 0 0 rot setpriority io-error ; + +! Flags for waitpid + +: WNOHANG 1 ; inline +: WUNTRACED 2 ; inline + +: WSTOPPED 2 ; inline +: WEXITED 4 ; inline +: WCONTINUED 8 ; inline +: WNOWAIT HEX: 1000000 ; inline + +! Examining status + +: WTERMSIG ( status -- value ) + HEX: 7f bitand ; inline + +: WIFEXITED ( status -- ? ) + WTERMSIG zero? ; inline + +: WEXITSTATUS ( status -- value ) + HEX: ff00 bitand -8 shift ; inline + +: WIFSIGNALED ( status -- ? ) + HEX: 7f bitand 1+ -1 shift 0 > ; inline + +: WCOREFLAG ( -- value ) + HEX: 80 ; inline + +: WCOREDUMP ( status -- ? ) + WCOREFLAG bitand zero? not ; inline + +: WIFSTOPPED ( status -- ? ) + HEX: ff bitand HEX: 7f = ; inline + +: WSTOPSIG ( status -- value ) + WEXITSTATUS ; inline + +FUNCTION: pid_t wait ( int* status ) ; +FUNCTION: pid_t waitpid ( pid_t wpid, int* status, int options ) ; + +: wait-for-pid ( pid -- status ) + 0 [ 0 waitpid drop ] keep *int WEXITSTATUS ; \ No newline at end of file diff --git a/extra/unix/unix.factor b/extra/unix/unix.factor index 5608f229f0..9a7d405546 100755 --- a/extra/unix/unix.factor +++ b/extra/unix/unix.factor @@ -178,61 +178,6 @@ FUNCTION: int unlink ( char* path ) ; FUNCTION: int utimes ( char* path, timeval[2] times ) ; -: SIGKILL 9 ; inline -: SIGTERM 15 ; inline - -FUNCTION: int kill ( pid_t pid, int sig ) ; - -: PRIO_PROCESS 0 ; inline -: PRIO_PGRP 1 ; inline -: PRIO_USER 2 ; inline - -: PRIO_MIN -20 ; inline -: PRIO_MAX 20 ; inline - -! which/who = 0 for current process -FUNCTION: int getpriority ( int which, int who ) ; -FUNCTION: int setpriority ( int which, int who, int prio ) ; - -! Flags for waitpid - -: WNOHANG 1 ; inline -: WUNTRACED 2 ; inline - -: WSTOPPED 2 ; inline -: WEXITED 4 ; inline -: WCONTINUED 8 ; inline -: WNOWAIT HEX: 1000000 ; inline - -! Examining status - -: WTERMSIG ( status -- value ) - HEX: 7f bitand ; inline - -: WIFEXITED ( status -- ? ) - WTERMSIG zero? ; inline - -: WEXITSTATUS ( status -- value ) - HEX: ff00 bitand -8 shift ; inline - -: WIFSIGNALED ( status -- ? ) - HEX: 7f bitand 1+ -1 shift 0 > ; inline - -: WCOREFLAG ( -- value ) - HEX: 80 ; inline - -: WCOREDUMP ( status -- ? ) - WCOREFLAG bitand zero? not ; inline - -: WIFSTOPPED ( status -- ? ) - HEX: ff bitand HEX: 7f = ; inline - -: WSTOPSIG ( status -- value ) - WEXITSTATUS ; inline - -FUNCTION: pid_t wait ( int* status ) ; -FUNCTION: pid_t waitpid ( pid_t wpid, int* status, int options ) ; - FUNCTION: ssize_t write ( int fd, void* buf, size_t nbytes ) ; {