Up

Module Unix

Signature

module Fd = Fd
include Unix_syscalls
module Exit : module type of Core.Std.Unix.Exit
val system : string -> Exit_or_signal.t Import.Deferred.t
val system_exn : string -> unit Import.Deferred.t
val getpid : unit -> Core.Std.Pid.t
val getppid : unit -> Core.Std.Pid.t option
val getppid_exn : unit -> Core.Std.Pid.t
val this_process_became_child_of_init : ?poll_delay:Core.Std.Time.Span.t -> unit -> unit Import.Deferred.t

this_process_became_child_of_init returns a deferred that becomes determined when the current process becomes a child of init(8). This is useful to determine if one's parent has died, because in that case init will becomes one's parent.

See Linux_ext.pr_set_pdeathsig : Signal.t -> unit for related way to get information about parent death.

TODO: CUSTOM TAG poll_delay [controls how often to check]
val nice : int -> int
val cores : (unit -> int Import.Deferred.t) Core.Std.Or_error.t

cores () Returns the number of cores

type open_flag = [
| `Rdonly
| `Wronly
| `Rdwr
| `Nonblock
| `Append
| `Creat
| `Trunc
| `Excl
| `Noctty
| `Dsync
| `Sync
| `Rsync
]
type file_perm = int
val openfile : ?perm:file_perm -> ?close_on_exec:bool -> string -> mode:open_flag list -> Fd.t Import.Deferred.t
val with_file : ?exclusive:[
| `Read
| `Write
] -> ?perm:file_perm -> string -> mode:open_flag list -> f:(Fd.t -> 'a Import.Deferred.t) -> 'a Import.Deferred.t

with_file file ~mode ~perm ~f ?exclusive opens file, and applies f to the resulting file descriptor. When the result of f becomes determined, it closes the descriptor and returns the result of f. If exclusive is supplied, then the file descriptor is locked before calling f and unlocked after calling f.

module Open_flags : module type of Core.Std.Unix.Open_flags
val fcntl_getfl : Fd.t -> Open_flags.t Import.Deferred.t

fcntl_getfl and fcntl_setf are deferred wrappers around the corresponding functions in Core.Unix for accessing the open-file-descriptor table.

val fcntl_setfl : Fd.t -> Open_flags.t -> unit Import.Deferred.t
val close : ?should_close_file_descriptor:bool -> Fd.t -> unit Import.Deferred.t

close fd closes the file descriptor fd, and raises an exception if fd has already been closed.

In some situations, one may need to cause Async to release an fd that it is managing without closing the underlying file descriptor. In that case, one should supply ~should_close_file_descriptor:false, which will skip the underlying close() system call.

val lseek : Fd.t -> int64 -> mode:[<
| `Set
| `Cur
| `End
] -> int64 Import.Deferred.t
val truncate : string -> len:int64 -> unit Import.Deferred.t
val ftruncate : Fd.t -> len:int64 -> unit Import.Deferred.t
val fsync : Fd.t -> unit Import.Deferred.t
val fdatasync : Fd.t -> unit Import.Deferred.t
val sync : unit -> unit Import.Deferred.t
val lockf : ?len:Core.Std.Int64.t -> Fd.t -> [
| `Read
| `Write
] -> unit Import.Deferred.t

lockf fd read_or_write ?len exclusively locks for reading/writing the section of the open file fd specified by the current file position and len (see man lockf). It returns when the lock has been acquired. It raises if fd is closed.

val try_lockf : ?len:Core.Std.Int64.t -> Fd.t -> [
| `Read
| `Write
] -> bool

try_lockf fd read_or_write ?len attempts to exclusively lock for reading/writing the section of the open file fd specified by the current file position and len (see man lockf). It returns true if it acquired the lock. It raises if fd is closed.

val test_lockf : ?len:Core.Std.Int64.t -> Fd.t -> bool

lockf_is_locked fd ?len checks the lock on section of the open file fd specified by the current file position and len (see man lockf). If the section is unlocked or locked by this process, it returns true, else it returns false. It raises if fd is closed.

val unlockf : ?len:Core.Std.Int64.t -> Fd.t -> unit

unlockf fd ?len unlocks the section of the open file fd specified by the current file position and len (see man lockf). It raises if fd is closed.

module File_kind : sig .. end
module Stats : sig .. end
val stat : string -> Stats.t Import.Deferred.t
val lstat : string -> Stats.t Import.Deferred.t
val unlink : string -> unit Import.Deferred.t
val remove : string -> unit Import.Deferred.t
val rename : src:string -> dst:string -> unit Import.Deferred.t
val link : ?force:bool -> target:string -> link_name:string -> unit -> unit Import.Deferred.t
val chmod : string -> perm:file_perm -> unit Import.Deferred.t
val fchmod : Fd.t -> perm:file_perm -> unit Import.Deferred.t
val chown : string -> uid:int -> gid:int -> unit Import.Deferred.t
val fchown : Fd.t -> uid:int -> gid:int -> unit Import.Deferred.t
val access : string -> [
| `Read
| `Write
| `Exec
| `Exists
] list -> (unit, exn) Core.Std.Result.t Import.Deferred.t
val access_exn : string -> [
| `Read
| `Write
| `Exec
| `Exists
] list -> unit Import.Deferred.t
val set_close_on_exec : Fd.t -> unit
val clear_close_on_exec : Fd.t -> unit
val mkdir : ?p:unit -> ?perm:file_perm -> string -> unit Import.Deferred.t
val rmdir : string -> unit Import.Deferred.t
val chdir : string -> unit Import.Deferred.t
val getcwd : unit -> string Import.Deferred.t
val chroot : string -> unit Import.Deferred.t
type dir_handle = Core.Std.Unix.dir_handle
val opendir : string -> dir_handle Import.Deferred.t
val readdir : dir_handle -> string Import.Deferred.t
val rewinddir : dir_handle -> unit Import.Deferred.t
val closedir : dir_handle -> unit Import.Deferred.t
val pipe : Core.Std.Info.t -> ([
| `Reader of Fd.t
] * [
| `Writer of Fd.t
]) Import.Deferred.t

The info supplied to pipe is debugging information that will be included in the returned Fds.

val mkfifo : ?perm:file_perm -> string -> unit Import.Deferred.t

Create a named pipe with the given permissions.

val symlink : src:string -> dst:string -> unit Import.Deferred.t
val readlink : string -> string Import.Deferred.t
val mkstemp : string -> (string * Fd.t) Import.Deferred.t

mkstemp prefix creates and opens a unique temporary file with prefix, automatically appending a suffix of six random characters to make the name unique. Unlike C's mkstemp, prefix should not include six X's at the end.

Raises [Unix_error] on errors.
val mkdtemp : string -> string Import.Deferred.t
val getgrouplist : string -> int -> int array Import.Deferred.t
type process_times = Core.Std.Unix.process_times = {
tms_utime
: float ; (* User time for the process *)
tms_stime
: float ; (* System time for the process *)
tms_cutime
: float ; (* User time for the children processes *)
tms_cstime
: float ; (* System time for the children processes *)
}

Time functions.

val times : unit -> process_times
type tm = Core.Std.Unix.tm = {
tm_sec
: int ; (* Seconds 0..59 *)
tm_min
: int ; (* Minutes 0..59 *)
tm_hour
: int ; (* Hours 0..23 *)
tm_mday
: int ; (* Day of month 1..31 *)
tm_mon
: int ; (* Month of year 0..11 *)
tm_year
: int ; (* Year - 1900 *)
tm_wday
: int ; (* Day of week (Sunday is 0) *)
tm_yday
: int ; (* Day of year 0..365 *)
tm_isdst
: bool ; (* Daylight time savings in effect *)
}
val time : unit -> float
val gettimeofday : unit -> float
val gmtime : float -> tm
val localtime : float -> tm
val mktime : tm -> float * tm
val utimes : string -> access:float -> modif:float -> unit Import.Deferred.t
val environment : unit -> string array
val getenv : string -> string option
val getenv_exn : string -> string
val putenv : key:string -> data:string -> unit
val unsetenv : string -> unit
val fork_exec : prog:string -> args:string list -> ?use_path:bool -> ?env:[
| `Replace_raw of string list
] -> unit -> Core.Std.Pid.t Import.Deferred.t

fork_exec ~prog ~args ?path ?env forks and execs prog with args, and returns the child pid. If use_path = true (the default) and prog doesn't contain a slash, then fork_exec searches the PATH environment variable for prog. If env is supplied, it specifies the environment when prog is executed.

If env contains multiple bindings for the same variable, the last takes precedence. In the case of `Extend, bindings in env take precedence over the existing environment. See Unix.exec.

type wait_on = [
| `Any
| `Group of Core.Std.Pid.t
| `My_group
| `Pid of Core.Std.Pid.t
]
val wait_on_of_sexp : Sexplib.Sexp.t -> wait_on
val __wait_on_of_sexp__ : Sexplib.Sexp.t -> wait_on
val sexp_of_wait_on : wait_on -> Sexplib.Sexp.t
val wait_nohang : wait_on -> (Core.Std.Pid.t * Exit_or_signal.t) option
val wait_nohang_untraced : wait_on -> (Core.Std.Pid.t * Exit_or_signal_or_stop.t) option

waitpid pid returns a deferred that becomes determined with the child's exit status, when the child process with process id pid exits. waitpid_exn is like waitpid, except the result only becomes determined if the child exits with status zero; it raises if the child terminates win any other way.

val waitpid_exn : Core.Std.Pid.t -> unit Import.Deferred.t
module Inet_addr : sig .. end
module Cidr : module type of Core.Std.Unix.Cidr
module Protocol_family : sig .. end
val socketpair : unit -> Fd.t * Fd.t
module Socket : sig .. end
val bind_to_interface_exn : (Fd.t -> [
| `Any
| `Interface_name of string
] -> unit) Core.Std.Or_error.t
module Host : sig .. end
type socket_domain = Core.Std.Unix.socket_domain =
| PF_UNIX
| PF_INET
| PF_INET6
val socket_domain_of_sexp : Sexplib.Sexp.t -> socket_domain
val sexp_of_socket_domain : socket_domain -> Sexplib.Sexp.t
val bin_read_socket_domain : socket_domain Core.Std.Bin_prot.Read.reader
val __bin_read_socket_domain__ : (int -> socket_domain) Core.Std.Bin_prot.Read.reader
val bin_reader_socket_domain : socket_domain Core.Std.Bin_prot.Type_class.reader
val bin_size_socket_domain : socket_domain Core.Std.Bin_prot.Size.sizer
val bin_write_socket_domain : socket_domain Core.Std.Bin_prot.Write.writer
val bin_writer_socket_domain : socket_domain Core.Std.Bin_prot.Type_class.writer
type socket_type = Core.Std.Unix.socket_type =
| SOCK_STREAM
| SOCK_DGRAM
| SOCK_RAW
| SOCK_SEQPACKET
val socket_type_of_sexp : Sexplib.Sexp.t -> socket_type
val sexp_of_socket_type : socket_type -> Sexplib.Sexp.t
val bin_read_socket_type : socket_type Core.Std.Bin_prot.Read.reader
val __bin_read_socket_type__ : (int -> socket_type) Core.Std.Bin_prot.Read.reader
val bin_reader_socket_type : socket_type Core.Std.Bin_prot.Type_class.reader
val bin_size_socket_type : socket_type Core.Std.Bin_prot.Size.sizer
val bin_write_socket_type : socket_type Core.Std.Bin_prot.Write.writer
val bin_writer_socket_type : socket_type Core.Std.Bin_prot.Type_class.writer
type sockaddr = Core.Std.Unix.sockaddr =
| ADDR_UNIX of string
| ADDR_INET of Inet_addr.t * int
val sexp_of_sockaddr : sockaddr -> Sexplib.Sexp.t
val bin_read_sockaddr : sockaddr Core.Std.Bin_prot.Read.reader
val __bin_read_sockaddr__ : (int -> sockaddr) Core.Std.Bin_prot.Read.reader
val bin_size_sockaddr : sockaddr Core.Std.Bin_prot.Size.sizer
val bin_write_sockaddr : sockaddr Core.Std.Bin_prot.Write.writer
val sockaddr_of_sexp : Core.Std.Sexp.t -> sockaddr
type sockaddr_blocking_sexp = sockaddr

sockaddr_blocking_sexp is like sockaddr, with of_sexp that performs DNS lookup to resolve Inet_addr.t.

val sockaddr_blocking_sexp_of_sexp : Sexplib.Sexp.t -> sockaddr_blocking_sexp
val sexp_of_sockaddr_blocking_sexp : sockaddr_blocking_sexp -> Sexplib.Sexp.t
val bin_sockaddr_blocking_sexp : sockaddr_blocking_sexp Core.Std.Bin_prot.Type_class.t
val bin_read_sockaddr_blocking_sexp : sockaddr_blocking_sexp Core.Std.Bin_prot.Read.reader
val __bin_read_sockaddr_blocking_sexp__ : (int -> sockaddr_blocking_sexp) Core.Std.Bin_prot.Read.reader
val bin_reader_sockaddr_blocking_sexp : sockaddr_blocking_sexp Core.Std.Bin_prot.Type_class.reader
val bin_size_sockaddr_blocking_sexp : sockaddr_blocking_sexp Core.Std.Bin_prot.Size.sizer
val bin_write_sockaddr_blocking_sexp : sockaddr_blocking_sexp Core.Std.Bin_prot.Write.writer
val bin_writer_sockaddr_blocking_sexp : sockaddr_blocking_sexp Core.Std.Bin_prot.Type_class.writer
module Addr_info : sig .. end
module Name_info : sig .. end
val gethostname : unit -> string
val getuid : unit -> int
val geteuid : unit -> int
val getgid : unit -> int
val getegid : unit -> int
val setuid : int -> unit
type error = Core.Std.Unix.error =
| E2BIG
| EACCES
| EAGAIN
| EBADF
| EBUSY
| ECHILD
| EDEADLK
| EDOM
| EEXIST
| EFAULT
| EFBIG
| EINTR
| EINVAL
| EIO
| EISDIR
| EMFILE
| EMLINK
| ENAMETOOLONG
| ENFILE
| ENODEV
| ENOENT
| ENOEXEC
| ENOLCK
| ENOMEM
| ENOSPC
| ENOSYS
| ENOTDIR
| ENOTEMPTY
| ENOTTY
| ENXIO
| EPERM
| EPIPE
| ERANGE
| EROFS
| ESPIPE
| ESRCH
| EXDEV
| EWOULDBLOCK
| EINPROGRESS
| EALREADY
| ENOTSOCK
| EDESTADDRREQ
| EMSGSIZE
| EPROTOTYPE
| ENOPROTOOPT
| EPROTONOSUPPORT
| ESOCKTNOSUPPORT
| EOPNOTSUPP
| EPFNOSUPPORT
| EAFNOSUPPORT
| EADDRINUSE
| EADDRNOTAVAIL
| ENETDOWN
| ENETUNREACH
| ENETRESET
| ECONNABORTED
| ECONNRESET
| ENOBUFS
| EISCONN
| ENOTCONN
| ESHUTDOWN
| ETOOMANYREFS
| ETIMEDOUT
| ECONNREFUSED
| EHOSTDOWN
| EHOSTUNREACH
| ELOOP
| EOVERFLOW
| EUNKNOWNERR of int
Deprecated in favor of Error.t
val error_of_sexp : Sexplib.Sexp.t -> error
val sexp_of_error : error -> Sexplib.Sexp.t
exception Unix_error of Error.t * string * string
module Terminal_io : sig .. end
module Passwd : sig .. end
Structure of entries in the passwd database.
module Group : sig .. end
Structure of entries in the groups database.
val getifaddrs : unit -> Ifaddr.t list Import.Deferred.t
val getlogin : unit -> string Import.Deferred.t

Return the login name of the user executing the process.

This returns a deferred because the username may need to be looked up in what is essentially a database elsewhere on the network (winbound user, or NIS).

val wordexp : (?flags:[
| `No_cmd
| `Show_err
| `Undef
] list -> string -> string array Import.Deferred.t) Core.Std.Or_error.t