tur/process
process management: pid, spawn, wait, exec, cwd, chdir.
Since: Phase B1
process/pid
(process/pid :int)
return the current process ID.
The PID of the calling process as :int.
(process/pid) ; => 12345
Since: Phase B2
process/ppid
(process/ppid :int)
return the parent process ID.
The PPID of the calling process as :int.
(process/ppid) ; => 1
Since: Phase B2
process/exit
(process/exit [code :int] :void)
terminate the process with the given exit code.
| code | exit status (0 = success, non-zero = failure) |
(process/exit 0)
Since: Phase B2
process/exec
(process/exec [path :cstr argv :int] :int)
replace the current process image with a new program.
| path | NUL-terminated path to the executable | |
| argv | cons list of cstr arguments (head = argv[0]) |
-1 if execvp fails (errno set); does not return on success.
(process/exec "/bin/ls" (cons "/bin/ls" (cons "-l" 0)))
Since: Phase B2
process/spawn
(process/spawn [path :cstr argv :int] :int)
fork and exec a new child process.
| path | path to the executable | |
| argv | cons list of cstr arguments (head = argv[0]) |
The child PID on success, -1 on fork failure.
(let [pid (process/spawn "/bin/ls" (cons "/bin/ls" (cons "-l" 0)))]
(process/wait pid))
Since: Phase B2
process/wait
(process/wait [pid :int] :int)
wait for a child process to exit.
| pid | child process ID returned by process/spawn |
The exit status code (0 = clean exit), -1 on error.
(process/wait child-pid) ; => 0
Since: Phase B2
process/run
(process/run [path :cstr argv :int] :int)
spawn a child process and wait for it to finish.
| path | path to the executable | |
| argv | cons list of cstr arguments |
An ok result (:int pointer) containing the exit code, or an err result containing a strdup'd error message cstr. Free with result-free when done.
(process/run "/bin/ls" (cons "/bin/ls" 0))
Since: Phase B2
process/capture
(process/capture [path :cstr argv :int] :int)
run a command and capture its stdout as a string.
| path | path to the executable | |
| argv | cons list of cstr arguments |
An ok result containing a heap-allocated NUL-terminated cstr of the captured stdout, or an err result with an error message cstr. Free captured output with free(); free the result with result-free.
(process/capture "/bin/echo" (cons "/bin/echo" (cons "hi" 0)))
Since: Phase B2
process/cwd
(process/cwd :cstr)
return the current working directory.
A heap-allocated NUL-terminated cstr of the cwd, or NULL on error. The caller must free the returned string.
(process/cwd) ; => "/home/user/project"
Since: Phase B2
process/chdir
(process/chdir [path :cstr] :int)
change the current working directory.
| path | the target directory path cstr |
0 on success, -1 on error (errno set).
(process/chdir "/tmp") ; => 0
Since: Phase B2