pid(n)
β¨ pid(n) β the "who even are you" command π
ok bestie so Tcl has a built-in command called pid and it's literally the process-identifier girlie. it's part of Tcl Built-In Commands, and yes she's been around since forever (iykyk). let's get into it π«Ά
πΈ SYNOPSIS πΈ
pid ?fileId?
π DESCRIPTION π
okay so here's the tea. pid has two moods and honestly? both slay.
If you pass the fileId argument, bestie, it should normally refer to a process pipeline β you know, the kind you made with the open command. In that case pid gives you back a list, and the elements of that list are the process identifiers of all the processes in the pipeline, in order. every single one. no skips. π
but wait β if fileId refers to an open file that is not a process pipeline? the list comes back empty. not a crisis, just the vibe. π
If you give it no fileId argument at all? then pid just returns the process identifier of the current process. it's giving main character energy, honestly.
and here's the important bit bestie: all process identifiers are returned as decimal strings. not ints, not vibes, strings. periodt. β¨
π¦ EXAMPLE π¦
ok so the goal here: print process info about the processes in a pipeline using the SysV ps program, before reading the output of that pipeline. so iconic of us.
set pipeline [open "| zcat somefile.gz | grep foobar | sort -u"]
# Print process information
exec ps -fp [pid $pipeline] >@stdout
# Print a separator and then the output of the pipeline
puts [string repeat - 70]
puts [read $pipeline]
close $pipeline
like?? we open the pipeline, we ask pid who's in it, we hand that straight to ps, we print a cute lil separator, then we read the goods. obsessed. π
π SEE ALSO π
π₯ KEYWORDS π₯
file, pipeline, process identifier
ok that's the whole page bestie, go forth and identify some processes π β¨
this one's from the Tcl era, dated 7.0, and it's pid(n) β manual page girlie forever π
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms