Skip to content
lehenbauer edited this page Sep 13, 2010 · 5 revisions

BSD – Tcl interface to various BSD UNIX functions

SYNOPSIS

  • ::bsd::getloadavg
  • ::bsd::rlimit get|set soft|hard limitName ?val?
  • ::bsd::rusage
  • ::bsd::setproctitle string
  • ::bsd::statfs _ path_
  • ::bsd::getfsstat ?-wait|-nowait?
  • ::bsd::syslog open ident logopt facility
  • ::bsd::syslog close
  • ::bsd::syslog logmask priority
  • ::bsd::syslog log priority message
  • ::bsd::abort

DESCRIPTION

The BSD extension provides Tcl programs with new Tcl commands to interface to various system calls and library routines present in BSD UNIX.

::bsd::getloadavg returns the number of processes in the system run queue as a list, representing averages over the last 1, 5, and 15 minutes.

::bsd::rlimit lets you get and set the current soft and hard settings for resource limits. You can specify a 64-bit integer value for any of the limits or unlimited to indicate that there should be no limit.

See the Berkeley manpage for getrlimit and setrlimit for details on the options available and what they do.

::bsd::rusage returns the cumulative resource usage for the current process, as a list of key-value pairs, suitable for loading into an array using array set. Resources listed include user CPU, system CPU, max resident set size, shared text Kbyte seconds, unshared data Kbyte seconds, statck Kbyte seconds, page reclaims, page faults, number of times swapped, number of file system inputs and outputs, number of interprocess communications (IPC) messages sent and received, number of signals delivered, number of voluntary context switches, and number of involuntary context switches. For more information see the BSD getursage manpage.

::bsd::setproctitle sets the process title that appears on the ps command. The title is set from the executable’s name, followed by the specified string. If the string argument begins with a dash characters, the executable’s name is skipped. If no string is specified, the process title is restored. For more information see the BSD setproctitle manpage.

::bsd::statfs returns information about a mounted filesystem. The path argument is the path name of any file within the mounted filesystem. Results are returned as a list of key-value pairs suitable for loading into an array using array set_. Values returned include the fundamental filesystem block size (fundamentalFileSystemBlockSize_), the optimal transfer block size (optimalTransferBlockSize_), the total number of data blocks (totalDataBlocks_), the total number of free blocks (freeBlocks_), and the total number of available free blocks (availableFreeBlocks_). Also included are the total number of filesystem nodes (totalFileNodes_) and the free file nodes (_freeFileNodes), the file system type (fileSystemType), mount point (mountPoint), and mounted filesystem name (mountedFileSystem Finally a list of flags is provided, which can include readOnly, synchronous, noExec, noSUID, noDev, union, asynchronous, SUIDdir, softUpdates, noFollowSymlinks, noAtime, noClusterRead, noClusterWrite, exportReadOnly, exported, worldExported, anonUidMapping, kerberosUidMapping, webNFS, filesystemStoredLocally, quotasEnabled, rootFilesystem, userMounted, multiLabel, and aclsEnabled.

::bsd::getfsstat functions like statfs, except that it returns a list of lists with information about all mounted filesystems. If -nowait or no option is specified, getfsstat will directly return the filesystem information retained in the kernel to avoid delays caused by waiting for updated information from a filesystem that is perhaps temporarily unable to respond, at the cost of the data perhaps not reflecting the absolutely current status of the filesystem. As some of the information returned may be out of date, if -wait is specified, getfsstat will request updated information for each mounted filesystem prior to returning.

::bsd::syslog provides a direct interface to the syslog library to provide a way to write messages into the system log. ::bsd::syslog open takes an identifier, a list of zero or more log options, and a facility name. The facility name can be one of auth, authpriv, console, cron, daemon, ftp, kern, lpr, mail, news, ntp, security, syslog, user, uucp, local0, local1, local2, local3, local4, local5, local6, or local7.

Log options can include console, which causes the message to be logged on the console if there are errors in sending it, no_delay, which theoretically says not to delay opening the syslog connection until the first syslog call is made, but check your documentation on syslog(3) to see if that’s really true, pid, which says to log the process ID along with whatever else, and perror, which says to log the message to stderr as well as to the system log.

::bsd::syslog log takes a priority and a message. Priority can be one of emerg, alert, crit, err, warning, notice, info, or debug, in descending order of priority. Check your documentation on your syslog library, high priority messages do stuff besides logging, like blasting to all logged in users, while ::bsd::syslog close closes the connection to the system log. Finally, ::bsd::syslog logmask sets the log priority mask and masks all priorities up to and including the specified one. For instance, if you invoked the logmask option with the info priority, both info and debug log messages would be suppressed.

::bsd::abort causes abnormal program termination to occur by issuing an abort signal and will work unless the SIGABRT signal is being caught and the signal handler does not return.

Clone this wiki locally