<i>l_pid</i> Returned by <i>fcntl()</i>



next up previous contents
Next: Performance Issues Up: Semantic Issues Previous: Non-interleaved Writes

l_pid Returned by fcntl()

  A process can check to see if a file has a lock on any data in the file by using F_GETLK with fcntl(). The l_pid field of the flock structure may be used under certain conditions with F_GETLK to return the process ID of the process holding the lock. Existing applications commonly use the l_pid returned to kill the process holding the lock, thereby releasing the lock.

In a network environment, processes may be running on different nodes. Consider what would happen if the l_pid returned refers to a process on another node. An application might kill an innocent process on its own node. This situation arises because F_GETLK with fcntl() is being used in an environment for which it was not designed. This is a semantic issue because the semantics of traditional Unix and IEEE 1003.1-1990 must be modified to avoid this situation.

There are several ways to modify the semantics of fcntl() to deal with this problem. One way would be to have a process ID space which would span several systems on a network, i.e., a given pid would uniquely identify both the process and the system on which the process runs. Then, a pid applied to a kill() could correctly signal the intended process. Another approach would be to have a unique process ID value which could refer to a process ``not known to the system.'' When this unique value for pid is used as an argument to kill() (or any other function which takes pid as an argument), the function would return an error.

Demonstrations were developed using an NFS implementation to illustrate for different client/server configurations what happens when a file is locked and F_GETLK with fcntl() is used to show the value of l_pid returned. Figure 2.1 illustrates how the demonstration proceeds. Commands are displayed in italics and the output of those commands is displayed in bold. The program setlock locks an entire file, waits for a newline, and then unlocks the file. The program getlock uses F_GETLK to show the value of l_pid returned for different client/server configurations. Source code for the demonstration programs (setlock.c and getlock.c) is located in Appendix gif. For the following demonstrations, Process A is the program setlock, Process B is the program getlock, and testfile is the file which is locked. In addition to Process A and Process B, another process on the system running Process A uses the ``ps'' command to confirm that the value for l_pid returned by Process B is indeed the process ID of Process A. Note that in these demonstrations, the Status Monitor and the Lock Manager must be running on both the client and the server.

Table 2.1 illustrates the use of Processes A and B in four different client/server configurations as follows:

  
Figure: l_pid returned by fcntl() demonstration procedure.

  
Table: l_pid summary

The NFS implementation makes F_GETLK and l_pid work correctly in all cases. This is accomplished by two additional protocols, the Lock Manager protocol and the Status Monitor protocol, used in conjunction with NFS. The Status Monitor protocol permits both clients and servers to be aware of what systems are up and running. The Status Monitor informs interested applications when a system failure occurs on a system which it is monitoring. The Lock Manager protocol implements record locking on NFS mounted file systems. A process on a remote system locking a file is identified by the Lock Manager and that value is returned by fcntl(). However, fcntl() does not identify the system on which the process holding the lock is running.



next up previous contents
Next: Performance Issues Up: Semantic Issues Previous: Non-interleaved Writes



Karen Olsen
Mon Aug 21 10:18:32 EDT 1995