Commit c56061ae authored by Luís Oliveira's avatar Luís Oliveira
Browse files

Add EXIT, WAIT and WAITPID.

Patch courtesy of Jeff Palmucci <jpalmucci@csail.mit.edu>.
parent 2efe7f61
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@
   #:dirfd
   #:dup
   #:dup2
   #:exit
   #:fchdir
   #:fchmod
   #:fcntl
@@ -163,6 +164,8 @@
   #:unlink
   #:unsetenv
   #:usleep
   #:wait
   #:waitpid
   #:write
   #:writev

+25 −0
Original line number Diff line number Diff line
@@ -133,6 +133,31 @@
(defsyscall "fork" pid
  "Create a child process.")

(defsyscall "exit" :int
  "Exit a process immediately."
  (code :int))

(defcfun ("wait" %wait) pid
  (stat-loc :pointer))

(defun wait ()
  "Wait for any child process to terminate."
  (with-foreign-object (stat-loc :int)
    (let ((result (%wait stat-loc)))
      (values result (mem-ref stat-loc :int)))))

(defcfun ("waitpid" %waitpid) pid
  (pid pid)
  (stat-loc :pointer)
  (options :int))

(defun waitpid (pid &key (no-hang nil) (untraced nil))
  "Wait for a specific child process to terminate"
  (with-foreign-object (stat-loc :int)
    (let ((result (%waitpid pid stat-loc (logior (if no-hang wnohang 0)
                                                 (if untraced wuntraced 0)))))
      (values result (mem-ref stat-loc :int)))))

(defsyscall "getegid" gid
  "Get effective group id of the current process.")

+5 −0
Original line number Diff line number Diff line
@@ -632,3 +632,8 @@
  (constant (tiocghayesesp "TIOCGHAYESESP"))
  (constant (tiocshayesesp "TIOCSHAYESESP"))
  (constant (fioqsize "FIOQSIZE")))

;;;; from wait.h

(constant (wnohang "WNOHANG"))
(constant (wuntraced "WUNTRACED"))