process(3tcl)
π process(3tcl) π
okay bestie, welcome to tcl::process β a built-in command in the Tcl Built-In Commands manual, and honestly? it's giving subprocess manager, main character energy. it's the girl who keeps track of every lil child process you spawn. π
β¨ NAME β¨
tcl::process β subprocess management π«Ά
πΈ SYNOPSIS πΈ
::tcl::process option ?arg arg ...?
π DESCRIPTION π
so this command is literally your way to manage the subprocesses that open and exec create β and you find them by their process identifiers (PIDs), iykyk. the legal options (which may be abbreviated, so you can be lazy, we support that) are:
::tcl::process autopurge ?flag?β the automatic purge facility, aka the girl who cleans up after the party. ifflagis specified as a boolean value, it activates or deactivates autopurge. and in all cases, it returns the current status as a boolean value. when autopurge is active,Tcl_ReapDetachedProcsgets called each time theexeccommand is executed or a pipe channel created byopenis closed. when autopurge is inactive, you have to call::tcl::process purgeexplicitly β no free rides. by default, autopurge is active. periodt.::tcl::process listβ returns the list of subprocess PIDs. this includes all currently executing subprocesses and all terminated subprocesses that have not yet had their corresponding process table entries purged. yes, the ghosts are still on the list until someone reaps them. π»::tcl::process purge ?pids?β cleans up all data associated with terminated subprocesses. ifpidsis specified as a list of PIDs, the command only cleans up data for the matching subprocesses, if they exist. if a process listed is still active, this command does nothing to that process (she's still busy, leave her alone). any PID that does not correspond to a subprocess is ignored.::tcl::process status ?switches? ?pids?β returns a dictionary mapping subprocess PIDs to their respective status. ifpidsis specified as a list of PIDs, the command only returns the status of the matching subprocesses, if they exist. any PID that does not correspond to a subprocess is ignored. for active processes, the status is an empty value. for terminated processes, the status is a list with the following format:{code ?msg errorCode?}, where:codeβ is a standard Tcl return code, i.e.,0forTCL_OKand1forTCL_ERROR,msgβ is the human-readable error message,errorCodeβ uses the same format as theerrorCodeglobal variable
ngl, msg and errorCode are only present for abnormally terminated processes (i.e. those where the code is nonzero). and under the hood? this command calls Tcl_WaitPid with the WNOHANG flag set for non-blocking behavior β unless the -wait switch is set (see below, bestie, keep reading).
additionally, ::tcl::process status accepts the following switches:
-waitβ by default the command returns immediately (the underlyingTcl_WaitPidis called with theWNOHANGflag set) unless this switch is set. ifpidsis specified as a list of PIDs, the command waits until the status of the matching subprocesses are available. ifpidswas not specified, this command will wait for all known subprocesses. she will literally sit there and wait. loyalty. π«‘--β marks the end of switches. the argument following this one will be treated as the first arg even if it starts with a-. iconic protective behavior.
π₯ EXAMPLES π₯
these show the use of ::tcl::process. some of the results from ::tcl::process status are split over multiple lines for readability (not because they're being dramatic, promise).
::tcl::process autopurge
β true
::tcl::process autopurge false
β false
set pid1 [exec command1 a b c | command2 d e f &]
β 123 456
set chan [open "|command1 a b c | command2 d e f"]
β file123
set pid2 [pid $chan]
β 789 1011
::tcl::process list
β 123 456 789 1011
::tcl::process status
β 123 0
456 {1 "child killed: write on pipe with no readers" {
CHILDKILLED 456 SIGPIPE "write on pipe with no readers"}}
789 {1 "child suspended: background tty read" {
CHILDSUSP 789 SIGTTIN "background tty read"}}
1011 {}
::tcl::process status 123
β 123 0
::tcl::process status 1011
β 1011 {}
::tcl::process status -wait
β 123 0
456 {1 "child killed: write on pipe with no readers" {
CHILDKILLED 456 SIGPIPE "write on pipe with no readers"}}
789 {1 "child suspended: background tty read" {
CHILDSUSP 789 SIGTTIN "background tty read"}}
1011 {1 "child process exited abnormally" {
CHILDSTATUS 1011 -1}}
::tcl::process status 1011
β 1011 {1 "child process exited abnormally" {
CHILDSTATUS 1011 -1}}
::tcl::process purge
exec command1 1 2 3 &
β 1213
::tcl::process list
β 1213
π¦ SEE ALSO π¦
exec(3tcl), open(3tcl), pid(3tcl), Tcl_DetachPids(3tcl), Tcl_WaitPid(3tcl), Tcl_ReapDetachedProcs(3tcl)
go read those too, they're the friend group. π
β KEYWORDS β
background, child, detach, process, wait
okay that's the whole page, bestie, no cap. this one's from Tcl 9.0, and the page is process(3tcl) β go forth and manage your subprocesses, you absolute queen. πβ¨
π¦ where this page comes from
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 2017 Frederic Bonnet
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms