SPAWNVEG(3ast) SPAWNVEG(3ast)

# [NAME](#NAME)

spawnveg - process spawn with process group and session control

# [SYNOPSIS](#SYNOPSIS)

#include &lt;ast.h&gt;

int spawnveg(const char* command, char\** argv, char\** envv, pid\_t pgid, int tcfd);

# [DESCRIPTION](#DESCRIPTION)

spawnveg combines [*fork*(2)](/man/os/ksh/fork.2), [*exec*(2)](/man/os/ksh/exec.2), [*setpgid*(2)](/man/os/ksh/setpgid.2) and [*setsid*(2)](/man/os/ksh/setsid.2) into a single call. If [*posix\_spawn*(3)](/man/os/ksh/posix_spawn.3) is available, that function is preferred over *fork*.

command, argv and envv are as in [*execve*(2)](/man/os/ksh/execve.2). pgid controls the new process group and session:

-1

The new process becomes a session leader. [*setsid*(2)](/man/os/ksh/setsid.2) is called in the child context.

0

The new process is in the caller's process group.

1

The new process becomes a process group leader.

&gt;1

The new process joins the process group *pgid*.

The tcfd argument is currently only used if the operating system supports the *posix\_spawn\_file\_actions\_addtcsetpgrp\_np* function. When tcfd is &gt;=0, spawnveg will set the controlling terminal for the new process to *tcfd*.

# [CAVEATS](#CAVEATS)

If the *posix\_spawn\_file\_actions\_addtcsetpgrp\_np* function is not available, then spawnveg cannot reliably set the terminal process group. As a result, it is incompatible with job control when used with terminals. Additionally, if the POSIX\_SPAWN\_SETSID attribute is not supported, then spawnveg cannot make the new process a session leader when using the *posix\_spawn* API.

# [SEE ALSO](#SEE_ALSO)

[fork(2)](/man/os/ksh/fork.2), [posix\_spawn(3)](/man/os/ksh/posix_spawn.3), [exec(2)](/man/os/ksh/exec.2), [setpgid(2)](/man/os/ksh/setpgid.2), [setsid(2)](/man/os/ksh/setsid.2), [spawnve(2)](/man/os/ksh/spawnve.2)

---

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