link() COHERENT System Call link() Create a link link(old, new) char *old, *new; A link to a file is another name for the file. All attributes of the file appear identical among all links. link creates a link called new to an existing file named old. For administrative reasons, it is an error for users other than the superuser to create a link to a directory. Such links can make the file system no longer tree structured unless carefully controlled, posing problems for commands such as find. ***** Example ***** This example, called lock.c, demonstrates how link can be used to perform intertask locking. With this technique, a program can start a process in the background and stop any other user from starting the identical process. main() { if(link("lock.c", "lockfile") == -1) { printf("Cannot link\n"); exit(1); } sleep(50); /* do nothing for 50 seconds */ unlink("lockfile"); printf("done\n"); exit(0); } ***** See Also ***** COHERENT system calls, find, ln, unlink() ***** Diagnostics ***** link returns zero when successful. It returns -1 on errors, e.g., old does not exist, new already exists, attempt to link across file systems, or no permission to create new in the target directory. ***** Notes ***** Because each mounted file system is a self-contained entity, links between different mounted file systems fail. COHERENT Lexicon Page 1
link() COHERENT System Call link() COHERENT Lexicon Page 2