Previous section   Next section

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 9.  Working with Files and Programs

The exit and pid Commands

The exit command terminates your script. Note that exit causes termination of the whole process that was running the script. If you supply an integer-valued argument to exit, then that becomes the exit status of the process.

The pid command returns the process ID of the current process. This can be useful as the seed for a random number generator because it changes each time you run your script. It is also common to embed the process ID in the name of temporary files.

You can also find out the process IDs associated with a process pipeline with pid:

set pipe [open "|command"]
set pids [pid $pipe]

There is no built-in mechanism to control processes in Tcl. On UNIX systems you can exec the kill program to terminate a process:

exec kill $pid

      Previous section   Next section