Documentation
¶
Overview ¶
Package TSR provides the API to make the program run in the background, what used to be called "Terminate and Stay Resident" back in the days.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type Logger ¶
type Logger interface {
Print(v ...interface{})
Printf(format string, v ...interface{})
Println(v ...interface{})
}
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
func New ¶
New returns new Process. If caller does not set the PID file path and name explicitely with WithPIDFile option, it is inferred from the executable file name. So that the PID file for "foo.exe" will be "foo.pid". A relative path is resolved against the current working directory when New is called.
On POSIX systems, the running TSR process holds a lock on "<pidfile>.lock" for its whole lifetime, and IsRunning, PID and Terminate rely on that lock rather than on the PID written in the PID file, which is informational only. The lock file is never removed. Both files must reside on a local filesystem.
func (*Process) AtExit ¶
func (p *Process) AtExit(fn func())
AtExit appends the function to the list of functions that will be executed when the TSR process terminates. It should be called before TSR() is called.
func (*Process) Close ¶
Close removes the PID file. Called in the TSR process, it also releases the lock. Called in any other process, it removes the PID file only if it is stale, i.e. no running TSR process holds it.
func (*Process) PID ¶
PID returns the PID of the TSR process if it's running. On POSIX systems it returns ErrNotRunning if no process holds the lock on the PID file.