PROC(3ast) PROC(3ast)

# [NAME](#NAME)

proc - process control routines (deprecated)

# [SYNOPSIS](#SYNOPSIS)

```
#include <proc.h>
Proc_t* procopen(const char* command, char** argv, char** envv, long* opv, long flags);
int procfree(Proc_t* proc);
int procclose(Proc_t* proc);
int procrun(const char* command, char** argv);
```

# [DESCRIPTION](#DESCRIPTION)

These routines provide a portable interface to process creation and execution. They used to work on systems with only [*spawnve*(2)](/man/os/ksh/spawnve.2) or [*spawnveg*(3)](/man/os/ksh/spawnveg.3). Now that libast has joined the 21st century and requires [*fork*(2)](/man/os/ksh/fork.2) and [*execve*(2)](/man/os/ksh/execve.2), this interface is deprecated and only kept for backward compatibility.

procopen runs *command* with arguments *argv*, environment modifications in *envv*, file descriptor, signal and process group operations in *opv* and flags in *flags*.

*command* is searched for using the PATH environment variable from the calling environment. If *command* is 0 then the current shell is used (see [*pathshell*(3)](/man/os/ksh/pathshell.3)). If *envv* is not 0 then it is a 0 terminated vector of *name*\[=*value*] strings that are added to the *command* environment using [*setenviron*(3)](/man/os/ksh/setenviron.3). If *name* appears in the parent environment then its value is replaced with the new *value*. If =*value* is omitted then *name* is removed from the child environment. The _ environment variable is set to contain the pathname for *command* and will appear at the top of the child environment.

If *opv* is not 0 then it is a zero-terminated vector of operations to perform. In the following *context* is a combination of PROC\_FD\_CHILD and PROC\_FD\_PARENT for the child and parent process context respectively. Valid operations are:

[**PROC\_FD\_CLOSE(fd, context)**](#PROC_FD_CLOSE%28)

The file descriptor *fd* is closed in *context*.

[**PROC\_FD\_DUP(from, to, context)**](#PROC_FD_DUP%28)

The file descriptor *from* is [*dup*(2)](/man/os/ksh/dup.2)'d into the file descriptor *to* in *context*.

[**PROC\_SIG\_DFL(sig)**](#PROC_SIG_DFL%28)

The signal handler for *sig* is set to SIG\_DFL in the child context.

[**PROC\_SIG\_IGN(sig)**](#PROC_SIG_IGN%28)

The signal handler for *sig* is set to SIG\_IGN in the child context.

[**PROC\_SYS\_PGRP(pgid)**](#PROC_SYS_PGRP%28)

The child process group is set to *pgid*. *pgid* may have the following values:

&lt;0

The child process becomes a session leader.

0

The child process is in the parent process group.

1

The child process becomes a process group leader.

&gt;1

The child process joins the process group *pgid*.

[**PROC\_SYS\_UMASK(mask)**](#PROC_SYS_UMASK%28)

The child process group file creation mask is set to *mask*.

*flags* is the inclusive-or of the following:

PROC\_ARGMOD

*argv\[-1]* and *argv\[0]* may be modified. This is an optimization that avoids an environment vector [*realloc(3)*](/man/os/ksh/realloc.3) when *command* is a shell script.

PROC\_BACKGROUND

Standard shell & setup is done for the child process.

PROC\_CLEANUP

Parent process redirection file descriptors are closed on error.

PROC\_DAEMON

Standard daemon setup is done for the child process.

PROC\_ENVCLEAR

The child environment is cleared before *envv* is added.

PROC\_GID

The child effective group ID is set to the real group ID.

PROC\_IGNORE

Parent pipe errors are ignored.

PROC\_OVERLAY

The current process is overlaid by *command* if possible (i.e., the [*fork*(2)](/man/os/ksh/fork.2) call is omitted).

PROC\_PARANOID

Paranoid: *command* is searched using the default standard PATH; the child environment variable PATH is set to the default standard; the PROC\_GID and PROC\_UID modes are set; only /bin/sh is used to execute *command* if it is a shell script.

PROC\_PRIVELEGED

If the effective user ID is 0 then the child real user ID is set to 0 and the child real group ID is set to the effective group ID.

PROC\_READ

*proc.rfd* is connected to *command*'s standard output.

PROC\_SESSION

The child process becomes a session group leader. (Equivalent to the *opv* entry PROC\_SYS\_PGRP(-1).)

PROC\_UID

The child effective user ID is set to the real user ID.

PROC\_WRITE

*proc.wfd* is connected to *commands*'s standard input.

The return value is a pointer to a structure with the following members:

pid\_t *pid*

The child process ID.

pid\_t *pgrp*

The child process group.

int *rfd*

A read file descriptor connected to *command*'s standard output.

int *wfd*

A write file descriptor connected to *command*'s standard input.

If an error occurs then 0 is returned.

procclose waits for the process *proc* to complete and then closes the command stream *proc*. The command exit status is returned. -1 is returned if the child portion of procopen failed.

procfree frees the process stream without waiting for *command* to complete. Presumably some other mechanism will be used to wait for *proc.pid*.

procrun combines procopen and procclose with the flags PROC\_GID|PROC\_UID and returns the command exit status.

# [SEE ALSO](#SEE_ALSO)

[popen(3)](/man/os/ksh/popen.3), [sfpopen(3)](/man/os/ksh/sfpopen.3), [spawnveg(3)](/man/os/ksh/spawnveg.3), [system(3)](/man/os/ksh/system.3)

---

Document: proc(3ast) from ksh 1.0.10-r37 (Chainguard OS)
Source: https://github.com/ksh93/ksh
