\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#178: [info pid] and [info tid] Subcommands}
\date{March 21, 2004}
\author{Joe Mistachkin}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#178}&\textbf{[info pid] and [info tid] Subcommands}\\\hline
Author&

Joe Mistachkin \tipmail{joe}{mistachkin.com}
\\
Created&Sunday, \(\text{21}^{\text{st}}\) March 2004\\
Type&Project\\
Tcl Version&\(8.7\)\\
State&Draft\\
Vote&Pending\\
Version&\tipversion$Revision: 1.9 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes two new \textbf{info} subcommands which are used to obtain the current process and thread identifiers.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

In certain types of applications, it is important to know what thread is currently executing. This is especially true for multithreaded applications or for scripts running in a threaded build of Tcl.

While the author realizes that there is already a \textbf{pid} command, the addition of the \textbf{info pid} subcommand still makes sense for the following reasons:
\begin{itemize}
\item{}
The \textbf{pid} command can also provide information totally unrelated to the \textit{current} process identifier. At one point (\cite{tip88}) it was even suggested that the \textbf{pid} command be overloaded to provide process control related functionality.
\item{}
To allow scripts that dynamically build other scripts (potentially for use with safe interpreters) using the \textbf{info} command and caller provided arguments. Using the \textbf{info} command instead of the \textbf{pid} command limits the amount of information that can be obtained by the safe interpreter.
\item{}
It is the opinion of the author that \textit{informational} commands, such as \textbf{pid} should really be subcommands of \textbf{info} as we start to move forward with the development of Tcl.
\end{itemize}

\section{Justification}

The \textbf{info tid} command should be in the core because the identity of the currently executing thread is just as fundamental on all modern operating systems as the current process identity. Once the thread identity is known, it can be used to communicate with other processes and threads in useful ways that do not require the Thread package. Loading the entire Thread package just to get the identity of the currently executing thread is overkill and may not be a good solution in application embedding scenarios. This is especially true for the browser plugin where loading extra packages is not ideal.

\section{Proposed Change}

Two new subcommands, \textbf{info pid} and \textbf{info tid}, would be added to the \textbf{info} command with the following syntax:

\begin{quote}
\textbf{info pid}
\end{quote}

This subcommand would return the process identifier for the current process.

\begin{quote}
\textbf{info tid}
\end{quote}

This subcommand would return the thread identifier for the current thread.

\section{Draft Implmentation}

A complete implementation of this TIP is available [\url{http://sf.net/tracker/?func=detail&aid=920731&group_id=10894&atid=310894}].

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\begin{thebibliography}{TIP \#1}
\addcontentsline{toc}{section}{References}
\bibitem[TIP \#88]{tip88}
Jeff Hobbs,
Vince Darley,
\emph{Extend Tcl Process Id Control via 'pid'},
on-line at \url{http://purl.org/tcl/tip/88.html}
\end{thebibliography}
\end{document}
