The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


chroot - change root directory (LEGACY)


#include <unistd.h>

int chroot(const char *path);


The path argument points to a pathname naming a directory. The chroot() function causes the named directory to become the root directory; that is, the starting point for path searches for pathnames beginning with /. The process' working directory is unaffected by chroot().

The process must have appropriate privileges to change the root directory.

The dot-dot entry in the root directory is interpreted to mean the root directory itself. Thus, dot-dot cannot be used to access files outside the subtree rooted at the root directory.

This interface need not be reentrant.


Upon successful completion, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error. If -1 is returned, no change is made in the root directory.


The chroot() function will fail if:
Search permission is denied for a component of path.
Too many symbolic links were encountered in resolving path.
The length of the path argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.
A component of path does not name an existing directory or path is an empty string.
A component of the path name is not a directory.
The effective user ID does not have appropriate privileges.

The chroot() function may fail if:

Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.




There is no portable use that an application could make of this interface.




chdir(), <unistd.h>.


Derived from Issue 1 of the SVID.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]