No matching definitions.

tur/process

stdlib/process.tur

process management: pid, spawn, wait, exec, cwd, chdir.

Since: Phase B1

defn

process/pid

(process/pid :int)

return the current process ID.

The PID of the calling process as :int.

(process/pid)  ; => 12345

Since: Phase B2

defn

process/ppid

(process/ppid :int)

return the parent process ID.

The PPID of the calling process as :int.

(process/ppid)  ; => 1

Since: Phase B2

defn

process/exit

(process/exit [code :int] :void)

terminate the process with the given exit code.

codeexit status (0 = success, non-zero = failure)
(process/exit 0)

Since: Phase B2

defn

process/exec

(process/exec [path :cstr argv :int] :int)

replace the current process image with a new program.

pathNUL-terminated path to the executable
argvcons 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

defn

process/spawn

(process/spawn [path :cstr argv :int] :int)

fork and exec a new child process.

pathpath to the executable
argvcons 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

defn

process/wait

(process/wait [pid :int] :int)

wait for a child process to exit.

pidchild process ID returned by process/spawn

The exit status code (0 = clean exit), -1 on error.

(process/wait child-pid)  ; => 0

Since: Phase B2

defn

process/run

(process/run [path :cstr argv :int] :int)

spawn a child process and wait for it to finish.

pathpath to the executable
argvcons 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

defn

process/capture

(process/capture [path :cstr argv :int] :int)

run a command and capture its stdout as a string.

pathpath to the executable
argvcons 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

defn

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

defn

process/chdir

(process/chdir [path :cstr] :int)

change the current working directory.

paththe target directory path cstr

0 on success, -1 on error (errno set).

(process/chdir "/tmp")  ; => 0

Since: Phase B2