[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 2

ttylock, ttywait, ttyunlock, or ttylocked Subroutine

Purpose

Controls tty locking functions.

Library

Standard C Library (libc.a)

Syntax


int ttylock ( DeviceName)
char *DeviceName;

int ttywait (DeviceName)
char *DeviceName;

int ttyunlock (DeviceName)
char *DeviceName;

int ttylocked (DeviceName)
char *DeviceName;

Description

The ttylock subroutine creates the LCK..DeviceName file in the /etc/locks directory and writes the process ID of the calling process in that file. If LCK..DeviceName exists and the process whose ID is contained in this file is active, the ttylock subroutine returns an error.

There are programs like uucp and connect that create tty locks in the /etc/locks directory. The convention followed by these programs is to call the ttylock subroutine with an argument of DeviceName for locking the /dev/DeviceName file. This convention must be followed by all callers of the ttylock subroutine to make the locking mechanism work.

The ttywait subroutine blocks the calling process until the lock file associated with DeviceName, the /etc/locks/LCK..DeviceName file, is removed.

The ttyunlock subroutine removes the lock file, /etc/locks/LCK..DeviceName, if it is held by the current process.

The ttylocked subroutine checks to see if the lock file, /etc/locks/LCK..DeviceName, exists and the process that created the lock file is still active. If the process is no longer active, the lock file is removed.

Parameters

DeviceName Specifies the name of the device.

Return Values

Upon successful completion, the ttylock subroutine returns a value of 0. Otherwise, a value of -1 is returned.

The ttylocked subroutine returns a value of 0 if no process has a lock on device. Otherwise, a value of -1 is returned.

Examples

  1. To create a lock for /dev/tty0, use the following statement:

    rc = ttylock("tty0");
  2. To lock /dev/tty0 device and wait for lock to be cleared if it exists, use the following statements:

    if (ttylock("tty0"))
        ttywait("tty0");
    rc = ttylock("tty0");
  3. To remove the lock file for device /dev/tty0 created by a previous call to the ttylock subroutine, use the following statement:

    ttyunlock("tty0");
  4. To check for a lock on /dev/tty0, use the following statement:

    rc = ttylocked("tty0");

Related Information

The /etc/locks directory.

The Input and Output Handling Programmer's Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]