<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://tcl.activestate.com/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu Feb 09 10:57:20 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='88'>
<header><title>Extend Tcl Process Id Control via &apos;pid&apos;</title><author address="mailto:JeffH@ActiveState.com">Jeff Hobbs</author><author address="mailto:vincentdarley@users.sourceforge.net">Vince Darley</author><status type='project' state='rejected' tclversion="8.4" vote='after'>$Revision: 1.9 $</status><history></history><created day='11' month='mar' year='2002' /><obsoleted tip='240'/></header>
<abstract>This TIP proposes extended the [pid] command to provide more control over native processes in Tcl.</abstract>
<body><section title="Rationale">
<para>Certain process control functions have shown themselves to be portable and of high usefulness to Tcl programmers. Most of these already exist in TclX, but simply requiring that extension isn&apos;t always acceptable. The [pid] command in Tcl is a command that is often overlooked, and so simple that it lends itself easily to being enhanced with new syntax. This TIP proposes adding subcommands to [pid] that extend the process control functionality of pure Tcl.</para>
</section>
<section title="Specification">
<verbatim><vline encoding='base64'>ICAgcGlkID9maWxlSWQ/</vline><vline encoding='base64'>ICAgcGlkIHRlcm1pbmF0ZSA/LWZvcmNlPyA/LS0/IHBpZCA/cGlkIC4uLj8=</vline></verbatim>
<para>The first line is the current definition for [pid], which is to return the name of the current process id, or that attached to a <emph style="italic">fileId</emph> (as returned by [open] or [socket]). I propose to add only <emph style="italic">terminate</emph> initially. This command is adapted almost directly from TclX&apos;s signal handling, but changed to work as a subcommand of [pid]. This is to satisfy one of the most common requests from users regarding process management - killing a known process. It also establishes the framework of extending [pid] for future modifications. The ?-force? argument causes a forceful termination (the usage of SIGKILL on Unix, for Windows and Mac termination is already forceful).</para>
</section>
<section title="Reference Implementation">
<para>Although TclX&apos;s current documentation denies it, the <emph style="italic">send</emph> is already implemented for Windows (as <emph style="italic">kill</emph> under TclX) as well as Unix. Macintosh implementations for OS 9 and below would need to be created, or the documentation would need to stress that these are not available there (OS X is Unix based). Jim Ingham notes that a variant of <emph style="italic">kill</emph> could be created for OS 9. These functions are really meant to round out the process control functionality in Tcl (started with <emph style="italic">exec</emph> and <emph style="italic">open|</emph>), which are already of limited portability to Mac OS 9 (but undeniable usefulness elsewhere).</para>
<para>File: <emph style="italic">tcl/mac/tclMacChan.c</emph></para>
<para>File: <emph style="italic">tcl/unix/tclUnixPipe.c</emph></para>
<para>File: <emph style="italic">tcl/win/tclWinPipe.c</emph></para>
<para>Function: <emph style="italic">Tcl_PidObjCmd</emph></para>
</section>
<section title="Future Potential">
<para>What this also provides is a blueprint for future process management functions like these:</para>
<verbatim><vline encoding='base64'>ICAgcGlkIGlkID8tdXNlciA/dXNlcklkT3JOYW1lPz8gPy1ncm91cCA/Z3JvdXBJZE9yTmFtZT8/ID8tcGFyZW50IHBhcmVudElkPw==</vline><vline encoding='base64'>ICAgcGlkIHdhaXQgPy1ub2hhbmcgYm9vbD8gPy11bnRyYWNlZCBib29sPyA/LWdyb3VwIGJvb2w/ID9maWxlSWRPclBpZD8=</vline><vline encoding='base64'>ICAgcGlkIG5pY2UgPy1sZXZlbCBuaWNlTGV2ZWw/IGZpbGVJZE9yUGlk</vline><vline encoding='base64'>ICAgcGlkIGxpc3QgP3BhdHRlcm4/</vline><vline encoding='base64'>ICAgcGlkIGlkID8tc2Vzc2lvbiBpZD8gPy1wcm9jZXNzZ3JvdXAgaWQ/</vline><vline encoding='base64'>ICAgcGlkIGhhbmRsZSBhY3Rpb24gc2lnbmFsIC4uLg==</vline><vline encoding='base64'>ICAgcGlkIHNlbmQgc2lnbmFsVHlwZSBmaWxlSWRPclBpZCA/ZmlsZUlkT3JQaWQgLi4uPw==</vline></verbatim>
<para>[pid wait] was in the initial tip, but it was recommended to rework it with callback to make it much more useful to the user. The [pid id] command was intended for Unix only, operating on the current process id, and would function similar to the [file attributes] command, but Windows NT does have similar functionality. The <emph style="italic">-user</emph> and <emph style="italic">-group</emph> options will return the name if possible, otherwise the id. The <emph style="italic">-parent</emph> option would be read-only (like <emph style="italic">-longname</emph> for [file attributes]). [pid send] suffers from cross-platform portability as well. On Windows, you can only <emph style="italic">raise</emph> signals inside of your own process.</para>
<para>[pid nice] is easy to implement, while [pid list] is very much platform sensitive. [pid handle] is for signal handling, another oft-requested feature for the core, and would be based on the TclX [signal] command (perhaps named <emph style="italic">trap</emph> as in Expect?). It could be massaged to various forms. These aren&apos;t to be addressed in this TIP, but are just ideas for the future.</para>
</section>
<section title="Comments">
<verbatim><vline encoding='base64'>ICAgcGlkIGtpbGwgPy1ncm91cCBib29sPyA/LXNpZ25hbCBzaWduYWxUeXBlPyBmaWxlSWRPclBpZCA/ZmlsZUlkT3JQaWQgLi4uPw==</vline></verbatim>
<para>This was the original form for [pid send], but it was noted that we are really sending signals. While I prefer the specificity of users recognizing <emph style="italic">kill</emph> as a command, what this really does is send specific signals (ANSI C specifies SIGABRT, SIGINT and SIGTERM, and for Unix we would handle the other POSIX names too). Thus I changed it to the <emph style="italic">send</emph> command documented above.</para>
<para>[process] rather than [pid] seems a more logical name for this command, but we are working within the constraints of the existing commands in order to prevent command bloat. There is still logic in the naming, as we are dealing with process ids.</para>
<para>[pid terminate] was also recommended to have the ability to terminate a process <emph style="italic">and</emph> all its children. This would be useful, but is not in the scope of the current tip.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

