PIDLOCK(3) | NetBSD Library Functions Manual | PIDLOCK(3) |
int
pidlock(const char *lockfile, int flags, pid_t *locker, const char *info);
int
ttylock(const char *tty, int flags, pid_t *locker);
int
ttyunlock(const char *tty);
These functions use the method of creating a lockfile traditionally used by UUCP software. This is described as follows in the documentation for Taylor UUCP:
The PID is stored in ASCII format, with leading spaces to pad it out to ten characters, and a terminating newline. This implementation has been extended to put the hostname on the second line of the file, terminated with a newline, and optionally an arbitrary comment on the third line of the file, also terminated with a newline. If a comment is given, but PIDLOCK_NONBLOCK is not, a blank line will be written as the second line of the file.
The pidlock() function will attempt to create the file lockfile and put the current process's pid in it. The ttylock() function will do the same, but should be passed only the base name (with no leading directory prefix) of the tty to be locked; it will test that the tty exists in /dev and is a character device, and then create the file in the /var/spool/lock directory and prefix the filename with LCK... Use the ttyunlock() function to remove this lock.
The following flags may be passed in flags:
If locker is non-null, it will contain the PID of the locking process, if there is one, on return.
If info is non-null and the lock succeeds, the string it points to will be written as the third line of the lock file.
The PID returned will be the pid of the locker on the remote machine if PIDLOCK_USEHOSTNAME is specified, but there is no indication that this is not on the local machine.
March 19, 2006 | NetBSD 5.99 |