.TH erlang 3erl "erts 13.2.2.5" "Ericsson AB" "Erlang Module Definition" .SH NAME erlang \- The Erlang BIFs and predefined types. .SH DESCRIPTION .LP By convention, most Built-In Functions (BIFs) and all predefined types are included in this module\&. Some of the BIFs and all of the predefined types are viewed more or less as part of the Erlang programming language and are \fIauto-imported\fR\&\&. Thus, it is not necessary to specify the module name\&. For example, the calls \fIatom_to_list(erlang)\fR\& and \fIerlang:atom_to_list(erlang)\fR\& are identical\&. .LP Auto-imported BIFs are listed without module prefix\&. BIFs listed with module prefix are not auto-imported\&. .LP Predefined types are listed in the Predefined datatypes section of this reference manual and in the Types and Function Specifications section of the Erlang Reference Manual\&. .LP BIFs can fail for various reasons\&. All BIFs fail with reason \fIbadarg\fR\& if they are called with arguments of an incorrect type\&. The other reasons are described in the description of each individual BIF\&. .LP Some BIFs can be used in guard tests and are marked with "Allowed in guard tests"\&. .SH DATA TYPES .SS Predefined datatypes .nf \fBany()\fR\& = any() .br .fi .RS .LP All possible Erlang terms\&. Synonym for \fIterm()\fR\&\&. .RE .nf \fBarity()\fR\& = arity() .br .fi .RS .LP The arity of a function or type\&. .RE .nf \fBatom()\fR\& = atom() .br .fi .RS .LP An Erlang atom\&. .RE .nf \fBbinary()\fR\& = <<_:_*8>> .br .fi .RS .LP An Erlang binary, that is, a bitstring with a size divisible by 8\&. .RE .nf \fBbitstring()\fR\& = <<_:_*1>> .br .fi .RS .LP An Erlang bitstring\&. .RE .nf \fBboolean()\fR\& = true | false .br .fi .RS .LP A boolean value\&. .RE .nf \fBbyte()\fR\& = 0\&.\&.255 .br .fi .RS .LP A byte of data represented by an integer\&. .RE .nf \fBchar()\fR\& = 0\&.\&.1114111 .br .fi .RS .LP An ASCII character or a unicode codepoint presented by an integer\&. .RE .nf \fBfloat()\fR\& = float() .br .fi .RS .LP An Erlang float\&. .RE .nf \fBfunction()\fR\& = function() .br .fi .RS .LP An Erlang fun\&. .RE .nf \fBidentifier()\fR\& = pid() | port() | reference() .br .fi .RS .LP An unique identifier for some entity, for example a process, port or monitor\&. .RE .nf \fBinteger()\fR\& = integer() .br .fi .RS .LP An Erlang integer\&. .RE .nf \fBiodata()\fR\& = iolist() | binary() .br .fi .RS .LP A binary or list containing bytes and/or iodata\&. This datatype is used to represent data that is meant to be output using any I/O module\&. For example: file:write/2 or gen_tcp:send/2\&. .LP To convert an iodata() term to binary() you can use iolist_to_binary/2\&. To transcode a string() or unicode:chardata() to iodata() you can use unicode:characters_to_binary/1\&. .RE .nf \fBiolist()\fR\& = .br maybe_improper_list(byte() | binary() | iolist(), .br binary() | []) .br .fi .RS .LP A list containing bytes and/or iodata\&. This datatype is used to represent data that is meant to be output using any I/O module\&. For example: file:write/2 or gen_tcp:send/2\&. .LP In most use cases you want to use iodata() instead of this type\&. .RE .nf \fBlist()\fR\& = [any()] .br .fi .RS .LP An Erlang list containing terms of any type\&. .RE .nf \fBlist(ContentType)\fR\& = [ContentType] .br .fi .RS .LP An Erlang list containing terms of the type \fIContentType\fR\&\&. .RE .nf \fBmap()\fR\& = #{any() => any()} .br .fi .RS .LP An Erlang map containing any number of key and value associations\&. .RE .nf \fBmaybe_improper_list()\fR\& = maybe_improper_list(any(), any()) .br .fi .RS .LP An Erlang list that is not guaranteed to end with a [], and where the list elements can be of any type\&. .RE .nf \fBmaybe_improper_list(ContentType, TerminationType)\fR\& = .br maybe_improper_list(ContentType, TerminationType) .br .fi .RS .LP An Erlang list, that is not guaranteed to end with a [], and where the list elements are of the type \fIContentType\fR\&\&. .RE .nf \fBmfa()\fR\& = {module(), atom(), arity()} .br .fi .RS .LP A three-tuple representing a \fIModule:Function/Arity\fR\& function signature\&. .RE .nf \fBmodule()\fR\& = atom() .br .fi .RS .LP An Erlang module represented by an atom\&. .RE .nf \fBneg_integer()\fR\& = integer() =< -1 .br .fi .RS .LP A negative integer\&. .RE .nf \fBnil()\fR\& = [] .br .fi .RS .LP The empty list()\&. .RE .nf \fBno_return()\fR\& = none() .br .fi .RS .LP The type used to show that a function will \fInever\fR\& return a value, that is it will \fIalways\fR\& throw an exception\&. .RE .nf \fBnode()\fR\& = atom() .br .fi .RS .LP An Erlang node represented by an atom\&. .RE .nf \fBnon_neg_integer()\fR\& = integer() >= 0 .br .fi .RS .LP A non-negative integer, that is any positive integer or 0\&. .RE .nf \fBnone()\fR\& = none() .br .fi .RS .LP This type is used to show that a function will \fInever\fR\& return a value; that is it will \fIalways\fR\& throw an exception\&. In a spec, use \fIno_return()\fR\& for the sake of clarity\&. .RE .nf \fBnonempty_binary()\fR\& = <<_:8, _:_*8>> .br .fi .RS .LP A binary() that contains some data\&. .RE .nf \fBnonempty_bitstring()\fR\& = <<_:1, _:_*1>> .br .fi .RS .LP A bitstring() that contains some data\&. .RE .nf \fBnonempty_improper_list(ContentType, TerminationType)\fR\& = .br nonempty_improper_list(ContentType, TerminationType) .br .fi .RS .LP A maybe_improper_list/2 that contains some items\&. .RE .nf \fBnonempty_list()\fR\& = [any(), \&.\&.\&.] .br .fi .RS .LP A list() that contains some items\&. .RE .nf \fBnonempty_list(ContentType)\fR\& = [ContentType, \&.\&.\&.] .br .fi .RS .LP A list(ContentType) that contains some items\&. .RE .nf \fBnonempty_maybe_improper_list()\fR\& = .br nonempty_maybe_improper_list(any(), any()) .br .fi .RS .LP A maybe_improper_list() that contains some items\&. .RE .nf \fBnonempty_maybe_improper_list(ContentType, TerminationType)\fR\& = .br nonempty_maybe_improper_list(ContentType, TerminationType) .br .fi .RS .LP A maybe_improper_list(ContentType, TerminationType) that contains some items\&. .RE .nf \fBnonempty_string()\fR\& = [char(), \&.\&.\&.] .br .fi .RS .LP A string() that contains some characters\&. .RE .nf \fBnumber()\fR\& = integer() | float() .br .fi .RS .LP An Erlang number\&. .RE .nf \fBpid()\fR\& = pid() .br .fi .RS .LP An Erlang process identifier\&. .RE .nf \fBport()\fR\& = port() .br .fi .RS .LP An Erlang port identifier\&. .RE .nf \fBpos_integer()\fR\& = integer() >= 1 .br .fi .RS .LP An integer greater than zero\&. .RE .nf \fBreference()\fR\& = reference() .br .fi .RS .LP An Erlang reference\&. .RE .nf \fBstring()\fR\& = [char()] .br .fi .RS .LP A character string represented by a list of ASCII characters or unicode codepoints\&. .RE .nf \fBterm()\fR\& = any() .br .fi .RS .LP All possible Erlang terms\&. Synonym for \fIany()\fR\&\&. .RE .nf \fBtimeout()\fR\& = infinity | integer() >= 0 .br .fi .RS .LP A timeout value that can be passed to a receive expression\&. .RE .nf \fBtuple()\fR\& = tuple() .br .fi .RS .LP An Erlang tuple\&. .RE .SS Other Datatypes .nf \fBext_binary()\fR\& = binary() .br .fi .RS .LP A binary data object, structured according to the Erlang external term format\&. .RE .nf \fBext_iovec()\fR\& = iovec() .br .fi .RS .LP A term of type \fIiovec()\fR\&, structured according to the Erlang external term format\&. .RE .nf \fBiovec()\fR\& = [binary()] .br .fi .RS .LP A list of binaries\&. This datatype is useful to use together with \fIenif_inspect_iovec\fR\&\&. .RE .nf \fBmessage_queue_data()\fR\& = off_heap | on_heap .br .fi .RS .LP See \fIprocess_flag(message_queue_data, MQD)\fR\&\&. .RE .nf \fBmonitor_option()\fR\& = .br {alias, explicit_unalias | demonitor | reply_demonitor} | .br {tag, term()} .br .fi .RS .LP See \fImonitor/3\fR\&\&. .RE .nf \fBtimestamp()\fR\& = .br {MegaSecs :: integer() >= 0, .br Secs :: integer() >= 0, .br MicroSecs :: integer() >= 0} .br .fi .RS .LP See \fIerlang:timestamp/0\fR\&\&. .RE .nf \fBtime_unit()\fR\& = .br integer() >= 1 | .br second | millisecond | microsecond | nanosecond | native | .br perf_counter | .br deprecated_time_unit() .br .fi .RS .LP Supported time unit representations: .RS 2 .TP 2 .B \fIPartsPerSecond :: integer() >= 1\fR\&: Time unit expressed in parts per second\&. That is, the time unit equals \fI1/PartsPerSecond\fR\& second\&. .TP 2 .B \fIsecond\fR\&: Symbolic representation of the time unit represented by the integer \fI1\fR\&\&. .TP 2 .B \fImillisecond\fR\&: Symbolic representation of the time unit represented by the integer \fI1000\fR\&\&. .TP 2 .B \fImicrosecond\fR\&: Symbolic representation of the time unit represented by the integer \fI1000_000\fR\&\&. .TP 2 .B \fInanosecond\fR\&: Symbolic representation of the time unit represented by the integer \fI1000_000_000\fR\&\&. .TP 2 .B \fInative\fR\&: Symbolic representation of the native time unit used by the Erlang runtime system\&. .RS 2 .LP The \fInative\fR\& time unit is determined at runtime system start, and remains the same until the runtime system terminates\&. If a runtime system is stopped and then started again (even on the same machine), the \fInative\fR\& time unit of the new runtime system instance can differ from the \fInative\fR\& time unit of the old runtime system instance\&. .RE .RS 2 .LP One can get an approximation of the \fInative\fR\& time unit by calling \fIerlang:convert_time_unit(1, second, native)\fR\&\&. The result equals the number of whole \fInative\fR\& time units per second\&. If the number of \fInative\fR\& time units per second does not add up to a whole number, the result is rounded downwards\&. .RE .LP .RS -4 .B Note: .RE The value of the \fInative\fR\& time unit gives you more or less no information about the quality of time values\&. It sets a limit for the resolution and for the precision of time values, but it gives no information about the accuracy of time values\&. The resolution of the \fInative\fR\& time unit and the resolution of time values can differ significantly\&. .TP 2 .B \fIperf_counter\fR\&: Symbolic representation of the performance counter time unit used by the Erlang runtime system\&. .RS 2 .LP The \fIperf_counter\fR\& time unit behaves much in the same way as the \fInative\fR\& time unit\&. That is, it can differ between runtime restarts\&. To get values of this type, call \fIos:perf_counter/0\fR\&\&. .RE .TP 2 .B \fIdeprecated_time_unit()\fR\&: Deprecated symbolic representations kept for backwards-compatibility\&. .RE .LP The \fItime_unit/0\fR\& type can be extended\&. To convert time values between time units, use \fIerlang:convert_time_unit/3\fR\&\&. .RE .nf \fBdeprecated_time_unit()\fR\& = .br seconds | milli_seconds | micro_seconds | nano_seconds .br .fi .RS .LP The \fItime_unit()\fR\& type also consist of the following \fIdeprecated\fR\& symbolic time units: .RS 2 .TP 2 .B \fIseconds\fR\&: Same as \fIsecond\fR\&\&. .TP 2 .B \fImilli_seconds\fR\&: Same as \fImillisecond\fR\&\&. .TP 2 .B \fImicro_seconds\fR\&: Same as \fImicrosecond\fR\&\&. .TP 2 .B \fInano_seconds\fR\&: Same as \fInanosecond\fR\&\&. .RE .RE .nf \fBdist_handle()\fR\& .br .fi .RS .LP An opaque handle identifying a distribution channel\&. .RE .nf \fBnif_resource()\fR\& .br .fi .RS .LP An opaque handle identifying a NIF resource object \&. .RE .nf \fBspawn_opt_option()\fR\& = .br link | monitor | .br {monitor, MonitorOpts :: [monitor_option()]} | .br {priority, Level :: priority_level()} | .br {fullsweep_after, Number :: integer() >= 0} | .br {min_heap_size, Size :: integer() >= 0} | .br {min_bin_vheap_size, VSize :: integer() >= 0} | .br {max_heap_size, Size :: max_heap_size()} | .br {message_queue_data, MQD :: message_queue_data()} | .br {async_dist, Enabled :: boolean()} .br .fi .RS .LP Options for \fIspawn_opt()\fR\&\&. .RE .nf \fBpriority_level()\fR\& = low | normal | high | max .br .fi .RS .LP Process priority level\&. For more info see \fIprocess_flag(priority, Level)\fR\& .RE .nf \fBmax_heap_size()\fR\& = .br integer() >= 0 | .br #{size => integer() >= 0, .br kill => boolean(), .br error_logger => boolean()} .br .fi .RS .LP Process max heap size configuration\&. For more info see \fIprocess_flag(max_heap_size, MaxHeapSize)\fR\& .RE .nf \fBmessage_queue_data()\fR\& = off_heap | on_heap .br .fi .RS .LP Process message queue data configuration\&. For more information, see \fIprocess_flag(message_queue_data, MQD)\fR\& .RE .nf \fBstacktrace()\fR\& = .br [{module(), .br atom(), .br arity() | [term()], .br [stacktrace_extrainfo()]} | .br {function(), arity() | [term()], [stacktrace_extrainfo()]}] .br .fi .nf \fBstacktrace_extrainfo()\fR\& = .br {line, integer() >= 1} | .br {file, unicode:chardata()} | .br {error_info, .br #{module => module(), function => atom(), cause => term()}} | .br {atom(), term()} .br .fi .RS .LP An Erlang stacktrace as described by Errors and Error Handling section in the Erlang Reference Manual\&. .RE .nf \fBsend_destination()\fR\& = .br pid() | .br reference() | .br port() | .br (RegName :: atom()) | .br {RegName :: atom(), Node :: node()} .br .fi .RS .LP The destination for a send operation, can be a remote or local process identifier, a (local) port, a reference denoting a process alias, a locally registered name, or a tuple \fI{RegName, Node}\fR\& for a registered name at another node\&. .RE .SH EXPORTS .LP .nf .B abs(Float) -> float() .br .fi .br .nf .B abs(Int) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Int = integer() .br .RE .RE .RS .LP Returns an integer or float that is the arithmetical absolute value of \fIFloat\fR\& or \fIInt\fR\&, for example: .LP .nf > abs(-3\&.33)\&. 3.33 > abs(-3)\&. 3 .fi .LP Allowed in guard tests\&. .RE .LP .nf .B erlang:adler32(Data) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Data = iodata() .br .RE .RE .RS .LP Computes and returns the adler32 checksum for \fIData\fR\&\&. .RE .LP .nf .B erlang:adler32(OldAdler, Data) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 OldAdler = integer() >= 0 .br Data = iodata() .br .RE .RE .RS .LP Continues computing the adler32 checksum by combining the previous checksum, \fIOldAdler\fR\&, with the checksum of \fIData\fR\&\&. .LP The following code: .LP .nf X = erlang:adler32(Data1), Y = erlang:adler32(X,Data2). .fi .LP assigns the same value to \fIY\fR\& as this: .LP .nf Y = erlang:adler32([Data1,Data2]). .fi .RE .LP .nf .B erlang:adler32_combine(FirstAdler, SecondAdler, SecondSize) -> .B integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 FirstAdler = SecondAdler = SecondSize = integer() >= 0 .br .RE .RE .RS .LP Combines two previously computed adler32 checksums\&. This computation requires the size of the data object for the second checksum to be known\&. .LP The following code: .LP .nf Y = erlang:adler32(Data1), Z = erlang:adler32(Y,Data2). .fi .LP assigns the same value to \fIZ\fR\& as this: .LP .nf X = erlang:adler32(Data1), Y = erlang:adler32(Data2), Z = erlang:adler32_combine(X,Y,iolist_size(Data2)). .fi .RE .LP .nf .B alias() -> Alias .br .fi .br .nf .B alias(Opts) -> Alias .br .fi .br .RS .LP Types: .RS 3 Alias = reference() .br Opts = [explicit_unalias | reply] .br .RE .RE .RS .LP Create an alias which can be used when sending messages to the process that created the alias\&. When the alias has been deactivated, messages sent using the alias will be dropped\&. An alias can be deactivated using \fIunalias/1\fR\&\&. Currently available options for \fIalias/1\fR\&: .RS 2 .TP 2 .B \fIexplicit_unalias\fR\&: The alias can only be deactivated via a call to \fIunalias/1\fR\&\&. This is also the default behaviour if no options are passed or if \fIalias/0\fR\& is called\&. .TP 2 .B \fIreply\fR\&: The alias will be automatically deactivated when a reply message sent via the alias is received\&. The alias can also still be deactivated via a call to \fIunalias/1\fR\&\&. .RE .LP Example: .LP .nf server() -> receive {request, AliasReqId, Request} -> Result = perform_request(Request), AliasReqId ! {reply, AliasReqId, Result} end, server(). client(ServerPid, Request) -> AliasReqId = alias([reply]), ServerPid ! {request, AliasReqId, Request}, %% Alias will be automatically deactivated if we receive a reply %% since we used the 'reply' option... receive {reply, AliasReqId, Result} -> Result after 5000 -> unalias(AliasReqId), %% Flush message queue in case the reply arrived %% just before the alias was deactivated... receive {reply, AliasReqId, Result} -> Result after 0 -> exit(timeout) end end. .fi .LP Note that both the server and the client in this example must be executing on at least OTP 24 systems in order for this to work\&. .LP For more information on process aliases see the \fIProcess Aliases\fR\& section of the \fIErlang Reference Manual\fR\& \&. .RE .LP .nf .B erlang:append_element(Tuple1, Term) -> Tuple2 .br .fi .br .RS .LP Types: .RS 3 Tuple1 = Tuple2 = tuple() .br Term = term() .br .RE .RE .RS .LP Returns a new tuple that has one element more than \fITuple1\fR\&, and contains the elements in \fITuple1\fR\& followed by \fITerm\fR\& as the last element\&. Semantically equivalent to \fIlist_to_tuple(tuple_to_list(Tuple1) ++ [Term])\fR\&, but much faster\&. Example: .LP .nf > erlang:append_element({one, two}, three)\&. {one,two,three} .fi .RE .LP .nf .B apply(Fun, Args) -> term() .br .fi .br .RS .LP Types: .RS 3 Fun = function() .br Args = [term()] .br .RE .RE .RS .LP Calls a fun, passing the elements in \fIArgs\fR\& as arguments\&. .LP If the number of elements in the arguments are known at compile time, the call is better written as \fIFun(Arg1, Arg2, \&.\&.\&. ArgN)\fR\&\&. .LP .RS -4 .B Warning: .RE Earlier, \fIFun\fR\& could also be specified as \fI{Module, Function}\fR\&, equivalent to \fIapply(Module, Function, Args)\fR\&\&. \fIThis use is deprecated and will stop working in a future release\&.\fR\& .RE .LP .nf .B apply(Module, Function, Args) -> term() .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Returns the result of applying \fIFunction\fR\& in \fIModule\fR\& to \fIArgs\fR\&\&. The applied function must be exported from \fIModule\fR\&\&. The arity of the function is the length of \fIArgs\fR\&\&. Example: .LP .nf > apply(lists, reverse, [[a, b, c]])\&. [c,b,a] > apply(erlang, atom_to_list, [\&'Erlang\&'])\&. "Erlang" .fi .LP If the number of arguments are known at compile time, the call is better written as \fIModule:Function(Arg1, Arg2, \&.\&.\&., ArgN)\fR\&\&. .LP Failure: \fIerror_handler:undefined_function/3\fR\& is called if the applied function is not exported\&. The error handler can be redefined (see \fIprocess_flag/2\fR\&)\&. If \fIerror_handler\fR\& is undefined, or if the user has redefined the default \fIerror_handler\fR\& so the replacement module is undefined, an error with reason \fIundef\fR\& is generated\&. .RE .LP .nf .B atom_to_binary(Atom) -> binary() .br .fi .br .RS .LP Types: .RS 3 Atom = atom() .br .RE .RE .RS .LP The same as \fIatom_to_binary\fR\&\fI(Atom, utf8)\fR\&\&. .RE .LP .nf .B atom_to_binary(Atom, Encoding) -> binary() .br .fi .br .RS .LP Types: .RS 3 Atom = atom() .br Encoding = latin1 | unicode | utf8 .br .RE .RE .RS .LP Returns a binary corresponding to the text representation of \fIAtom\fR\&\&. If \fIEncoding\fR\& is \fIlatin1\fR\&, one byte exists for each character in the text representation\&. If \fIEncoding\fR\& is \fIutf8\fR\& or \fIunicode\fR\&, the characters are encoded using UTF-8 where characters may require multiple bytes\&. .LP .RS -4 .B Note: .RE As from Erlang/OTP 20, atoms can contain any Unicode character and \fIatom_to_binary(Atom, latin1)\fR\& may fail if the text representation for \fIAtom\fR\& contains a Unicode character > 255\&. .LP Example: .LP .nf > atom_to_binary(\&'Erlang\&', latin1)\&. <<"Erlang">> .fi .RE .LP .nf .B atom_to_list(Atom) -> string() .br .fi .br .RS .LP Types: .RS 3 Atom = atom() .br .RE .RE .RS .LP Returns a list of unicode code points corresponding to the text representation of \fIAtom\fR\&, for example: .LP .nf > atom_to_list(\&'Erlang\&')\&. "Erlang" .fi .LP .nf > atom_to_list(\&'你好\&')\&. [20320,22909] .fi .LP See \fIunicode(3erl)\fR\& for how to convert the resulting list to different formats\&. .RE .LP .nf .B binary_part(Subject, PosLen) -> binary() .br .fi .br .RS .LP Types: .RS 3 Subject = binary() .br PosLen = {Start :: integer() >= 0, Length :: integer()} .br .RE .RE .RS .LP Extracts the part of the binary described by \fIPosLen\fR\&\&. .LP Negative length can be used to extract bytes at the end of a binary, for example: .LP .nf 1> Bin = <<1,2,3,4,5,6,7,8,9,10>>. 2> binary_part(Bin,{byte_size(Bin), -5}). <<6,7,8,9,10>> .fi .LP Failure: \fIbadarg\fR\& if \fIPosLen\fR\& in any way references outside the binary\&. .LP \fIStart\fR\& is zero-based, that is: .LP .nf 1> Bin = <<1,2,3>> 2> binary_part(Bin,{0,2}). <<1,2>> .fi .LP For details about the \fIPosLen\fR\& semantics, see \fIbinary(3erl)\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B binary_part(Subject, Start, Length) -> binary() .br .fi .br .RS .LP Types: .RS 3 Subject = binary() .br Start = integer() >= 0 .br Length = integer() .br .RE .RE .RS .LP The same as \fIbinary_part(Subject, {Start, Length})\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B binary_to_atom(Binary) -> atom() .br .fi .br .RS .LP Types: .RS 3 Binary = binary() .br .RE .RE .RS .LP The same as \fIbinary_to_atom\fR\&\fI(Binary, utf8)\fR\&\&. .RE .LP .nf .B binary_to_atom(Binary, Encoding) -> atom() .br .fi .br .RS .LP Types: .RS 3 Binary = binary() .br Encoding = latin1 | unicode | utf8 .br .RE .RE .RS .LP Returns the atom whose text representation is \fIBinary\fR\&\&. If \fIEncoding\fR\& is \fIutf8\fR\& or \fIunicode\fR\&, the binary must contain valid UTF-8 sequences\&. .LP .RS -4 .B Note: .RE As from Erlang/OTP 20, \fIbinary_to_atom(Binary, utf8)\fR\& is capable of decoding any Unicode character\&. Earlier versions would fail if the binary contained Unicode characters > 255\&. .LP .RS -4 .B Note: .RE The number of characters that are permitted in an atom name is limited\&. The default limits can be found in the efficiency guide (section Advanced)\&. .LP .RS -4 .B Note: .RE There is configurable limit on how many atoms that can exist and atoms are not garbage collected\&. Therefore, it is recommended to consider whether \fIbinary_to_existing_atom/2\fR\& is a better option than \fIbinary_to_atom/2\fR\&\&. The default limits can be found in efficiency guide (section Advanced)\&. .LP Examples: .LP .nf > binary_to_atom(<<"Erlang">>, latin1)\&. \&'Erlang' .fi .LP .nf > binary_to_atom(<<1024/utf8>>, utf8)\&. 'Ѐ' .fi .RE .LP .nf .B binary_to_existing_atom(Binary) -> atom() .br .fi .br .RS .LP Types: .RS 3 Binary = binary() .br .RE .RE .RS .LP The same as \fIbinary_to_existing_atom\fR\& \fI(Binary, utf8)\fR\&\&. .RE .LP .nf .B binary_to_existing_atom(Binary, Encoding) -> atom() .br .fi .br .RS .LP Types: .RS 3 Binary = binary() .br Encoding = latin1 | unicode | utf8 .br .RE .RE .RS .LP As \fIbinary_to_atom/2\fR\&, but the atom must exist\&. .LP The Erlang system has a configurable limit for the total number of atoms that can exist, and atoms are not garbage collected\&. Therefore, it is not safe to create many atoms from binaries that come from an untrusted source (for example, a file fetched from the Internet), for example, using \fIbinary_to_atom/2\fR\&\&. This function is thus the appropriate option when the input binary comes from an untrusted source\&. .LP An atom exists in an Erlang system when included in a loaded Erlang module or when created programmatically (for example, by \fIbinary_to_atom/2\fR\&)\&. See the next note for an example of when an atom exists in the source code for an Erlang module but not in the compiled version of the same module\&. .LP Failure: \fIbadarg\fR\& if the atom does not exist\&. .LP .RS -4 .B Note: .RE Note that the compiler may optimize away atoms\&. For example, the compiler will rewrite \fIatom_to_list(some_atom)\fR\& to \fI"some_atom"\fR\&\&. If that expression is the only mention of the atom \fIsome_atom\fR\& in the containing module, the atom will not be created when the module is loaded, and a subsequent call to \fIbinary_to_existing_atom(<<"some_atom">>, utf8)\fR\& will fail\&. .LP .RS -4 .B Note: .RE The number of characters that are permitted in an atom name is limited\&. The default limits can be found in the efficiency guide (section Advanced)\&. .RE .LP .nf .B binary_to_float(Binary) -> float() .br .fi .br .RS .LP Types: .RS 3 Binary = binary() .br .RE .RE .RS .LP Returns the float whose text representation is \fIBinary\fR\&, for example: .LP .nf > binary_to_float(<<"2\&.2017764e+0">>)\&. 2.2017764 .fi .LP The float string format is the same as the format for Erlang float literals except for that underscores are not permitted\&. .LP Failure: \fIbadarg\fR\& if \fIBinary\fR\& contains a bad representation of a float\&. .RE .LP .nf .B binary_to_integer(Binary) -> integer() .br .fi .br .RS .LP Types: .RS 3 Binary = binary() .br .RE .RE .RS .LP Returns an integer whose text representation is \fIBinary\fR\&, for example: .LP .nf > binary_to_integer(<<"123">>)\&. 123 .fi .LP \fIbinary_to_integer/1\fR\& accepts the same string formats as \fIlist_to_integer/1\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIBinary\fR\& contains a bad representation of an integer\&. .RE .LP .nf .B binary_to_integer(Binary, Base) -> integer() .br .fi .br .RS .LP Types: .RS 3 Binary = binary() .br Base = 2\&.\&.36 .br .RE .RE .RS .LP Returns an integer whose text representation in base \fIBase\fR\& is \fIBinary\fR\&, for example: .LP .nf > binary_to_integer(<<"3FF">>, 16)\&. 1023 .fi .LP \fIbinary_to_integer/2\fR\& accepts the same string formats as \fIlist_to_integer/2\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIBinary\fR\& contains a bad representation of an integer\&. .RE .LP .nf .B binary_to_list(Binary) -> [byte()] .br .fi .br .RS .LP Types: .RS 3 Binary = binary() .br .RE .RE .RS .LP Returns a list of integers corresponding to the bytes of \fIBinary\fR\&\&. .RE .LP .nf .B binary_to_list(Binary, Start, Stop) -> [byte()] .br .fi .br .RS .LP Types: .RS 3 Binary = binary() .br Start = Stop = integer() >= 1 .br .RS 2 1\&.\&.byte_size(\fIBinary\fR\&) .RE .RE .RE .RS .LP As \fIbinary_to_list/1\fR\&, but returns a list of integers corresponding to the bytes from position \fIStart\fR\& to position \fIStop\fR\& in \fIBinary\fR\&\&. The positions in the binary are numbered starting from 1\&. .LP .RS -4 .B Note: .RE \fIThe one-based indexing for binaries used by this function is deprecated\&.\fR\& New code is to use \fIbinary:bin_to_list/3\fR\& in STDLIB instead\&. All functions in module \fIbinary\fR\& consistently use zero-based indexing\&. .RE .LP .nf .B binary_to_term(Binary) -> term() .br .fi .br .RS .LP Types: .RS 3 Binary = ext_binary() .br .RE .RE .RS .LP Returns an Erlang term that is the result of decoding binary object \fIBinary\fR\&, which must be encoded according to the Erlang external term format\&. .LP .nf > Bin = term_to_binary(hello)\&. <<131,100,0,5,104,101,108,108,111>> > hello = binary_to_term(Bin)\&. hello .fi .LP .RS -4 .B Warning: .RE When decoding binaries from untrusted sources, the untrusted source may submit data in a way to create resources, such as atoms and remote references, that cannot be garbage collected and lead to Denial of Service attack\&. In such cases, consider using \fIbinary_to_term/2\fR\& with the \fIsafe\fR\& option\&. .LP See also \fIterm_to_binary/1\fR\& and \fIbinary_to_term/2\fR\&\&. .RE .LP .nf .B binary_to_term(Binary, Opts) -> term() | {term(), Used} .br .fi .br .RS .LP Types: .RS 3 Binary = ext_binary() .br Opt = safe | used .br Opts = [Opt] .br Used = integer() >= 1 .br .RE .RE .RS .LP As \fIbinary_to_term/1\fR\&, but takes these options: .RS 2 .TP 2 .B \fIsafe\fR\&: Use this option when receiving binaries from an untrusted source\&. .RS 2 .LP When enabled, it prevents decoding data that can be used to attack the Erlang runtime\&. In the event of receiving unsafe data, decoding fails with a \fIbadarg\fR\& error\&. .RE .RS 2 .LP This prevents creation of new atoms directly, creation of new atoms indirectly (as they are embedded in certain structures, such as process identifiers, refs, and funs), and creation of new external function references\&. None of those resources are garbage collected, so unchecked creation of them can exhaust available memory\&. .RE .LP .nf > binary_to_term(<<131,100,0,5,"hello">>, [safe])\&. ** exception error: bad argument > hello\&. hello > binary_to_term(<<131,100,0,5,"hello">>, [safe])\&. hello .fi .LP .RS -4 .B Warning: .RE The \fIsafe\fR\& option ensures the data is safely processed by the Erlang runtime but it does not guarantee the data is safe to your application\&. You must always validate data from untrusted sources\&. If the binary is stored or transits through untrusted sources, you should also consider cryptographically signing it\&. .TP 2 .B \fIused\fR\&: Changes the return value to \fI{Term, Used}\fR\& where \fIUsed\fR\& is the number of bytes actually read from \fIBinary\fR\&\&. .LP .nf > Input = <<131,100,0,5,"hello","world">>\&. <<131,100,0,5,104,101,108,108,111,119,111,114,108,100>> > {Term, Used} = binary_to_term(Input, [used])\&. {hello, 9} > split_binary(Input, Used)\&. {<<131,100,0,5,104,101,108,108,111>>, <<"world">>} .fi .RE .LP Failure: \fIbadarg\fR\& if \fIsafe\fR\& is specified and unsafe data is decoded\&. .LP See also \fIterm_to_binary/1\fR\&, \fIbinary_to_term/1\fR\&, and \fIlist_to_existing_atom/1\fR\&\&. .RE .LP .nf .B bit_size(Bitstring) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Bitstring = bitstring() .br .RE .RE .RS .LP Returns an integer that is the size in bits of \fIBitstring\fR\&, for example: .LP .nf > bit_size(<<433:16,3:3>>)\&. 19 > bit_size(<<1,2,3>>)\&. 24 .fi .LP Allowed in guard tests\&. .RE .LP .nf .B bitstring_to_list(Bitstring) -> [byte() | bitstring()] .br .fi .br .RS .LP Types: .RS 3 Bitstring = bitstring() .br .RE .RE .RS .LP Returns a list of integers corresponding to the bytes of \fIBitstring\fR\&\&. If the number of bits in the binary is not divisible by 8, the last element of the list is a bitstring containing the remaining 1-7 bits\&. Examples: .LP .nf > bitstring_to_list(<<433:16>>)\&. [1,177] .fi .LP .nf > bitstring_to_list(<<433:16,3:3>>)\&. [1,177,<<3:3>>] .fi .RE .LP .nf .B erlang:bump_reductions(Reductions) -> true .br .fi .br .RS .LP Types: .RS 3 Reductions = integer() >= 1 .br .RE .RE .RS .LP This implementation-dependent function increments the reduction counter for the calling process\&. In the Beam emulator, the reduction counter is normally incremented by one for each function and BIF call\&. A context switch is forced when the counter reaches the maximum number of reductions for a process (4000 reductions in Erlang/OTP 19\&.2 and later)\&. .LP .RS -4 .B Warning: .RE This BIF can be removed in a future version of the Beam machine without prior warning\&. It is unlikely to be implemented in other Erlang implementations\&. .RE .LP .nf .B byte_size(Bitstring) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Bitstring = bitstring() .br .RE .RE .RS .LP Returns an integer that is the number of bytes needed to contain \fIBitstring\fR\&\&. That is, if the number of bits in \fIBitstring\fR\& is not divisible by 8, the resulting number of bytes is rounded \fIup\fR\&\&. Examples: .LP .nf > byte_size(<<433:16,3:3>>)\&. 3 > byte_size(<<1,2,3>>)\&. 3 .fi .LP Allowed in guard tests\&. .RE .LP .nf .B erlang:cancel_timer(TimerRef) -> Result .br .fi .br .RS .LP Types: .RS 3 TimerRef = reference() .br Time = integer() >= 0 .br Result = Time | false .br .RE .RE .RS .LP Cancels a timer\&. The same as calling \fIerlang:cancel_timer(TimerRef, [])\fR\&\&. .RE .LP .nf .B erlang:cancel_timer(TimerRef, Options) -> Result | ok .br .fi .br .RS .LP Types: .RS 3 TimerRef = reference() .br Async = Info = boolean() .br Option = {async, Async} | {info, Info} .br Options = [Option] .br Time = integer() >= 0 .br Result = Time | false .br .RE .RE .RS .LP Cancels a timer that has been created by \fIerlang:start_timer\fR\& or \fIerlang:send_after\fR\&\&. \fITimerRef\fR\& identifies the timer, and was returned by the BIF that created the timer\&. .LP \fIOption\fR\&s: .RS 2 .TP 2 .B \fI{async, Async}\fR\&: Asynchronous request for cancellation\&. \fIAsync\fR\& defaults to \fIfalse\fR\&, which causes the cancellation to be performed synchronously\&. When \fIAsync\fR\& is set to \fItrue\fR\&, the cancel operation is performed asynchronously\&. That is, \fIcancel_timer()\fR\& sends an asynchronous request for cancellation to the timer service that manages the timer, and then returns \fIok\fR\&\&. .TP 2 .B \fI{info, Info}\fR\&: Requests information about the \fIResult\fR\& of the cancellation\&. \fIInfo\fR\& defaults to \fItrue\fR\&, which means the \fIResult\fR\& is given\&. When \fIInfo\fR\& is set to \fIfalse\fR\&, no information about the result of the cancellation is given\&. .RS 2 .TP 2 * When \fIAsync\fR\& is \fIfalse\fR\&: if \fIInfo\fR\& is \fItrue\fR\&, the \fIResult\fR\& is returned by \fIerlang:cancel_timer()\fR\&\&. otherwise \fIok\fR\& is returned\&. .LP .TP 2 * When \fIAsync\fR\& is \fItrue\fR\&: if \fIInfo\fR\& is \fItrue\fR\&, a message on the form \fI{cancel_timer, TimerRef, Result}\fR\& is sent to the caller of \fIerlang:cancel_timer()\fR\& when the cancellation operation has been performed, otherwise no message is sent\&. .LP .RE .RE .LP More \fIOption\fR\&s may be added in the future\&. .LP If \fIResult\fR\& is an integer, it represents the time in milliseconds left until the canceled timer would have expired\&. .LP If \fIResult\fR\& is \fIfalse\fR\&, a timer corresponding to \fITimerRef\fR\& could not be found\&. This can be either because the timer had expired, already had been canceled, or because \fITimerRef\fR\& never corresponded to a timer\&. Even if the timer had expired, it does not tell you if the time-out message has arrived at its destination yet\&. .LP .RS -4 .B Note: .RE The timer service that manages the timer can be co-located with another scheduler than the scheduler that the calling process is executing on\&. If so, communication with the timer service takes much longer time than if it is located locally\&. If the calling process is in critical path, and can do other things while waiting for the result of this operation, or is not interested in the result of the operation, you want to use option \fI{async, true}\fR\&\&. If using option \fI{async, false}\fR\&, the calling process blocks until the operation has been performed\&. .LP See also \fIerlang:send_after/4\fR\&, \fIerlang:start_timer/4\fR\&, and \fIerlang:read_timer/2\fR\&\&. .RE .LP .nf .B ceil(Number) -> integer() .br .fi .br .RS .LP Types: .RS 3 Number = number() .br .RE .RE .RS .LP Returns the smallest integer not less than \fINumber\fR\&\&. For example: .LP .nf > ceil(5\&.5)\&. 6 .fi .LP Allowed in guard tests\&. .RE .LP .nf .B check_old_code(Module) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Module = module() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fIModule\fR\& has old code, otherwise \fIfalse\fR\&\&. .LP See also \fIcode(3erl)\fR\&\&. .RE .LP .nf .B check_process_code(Pid, Module) -> CheckResult .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br Module = module() .br CheckResult = boolean() .br .RE .RE .RS .LP The same as \fIcheck_process_code(Pid, Module, [])\fR\&\&. .RE .LP .nf .B check_process_code(Pid, Module, OptionList) -> CheckResult | async .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br Module = module() .br RequestId = term() .br Option = {async, RequestId} | {allow_gc, boolean()} .br OptionList = [Option] .br CheckResult = boolean() | aborted .br .RE .RE .RS .LP Checks if the node local process identified by \fIPid\fR\& executes old code for \fIModule\fR\&\&. .LP \fIOption\fR\&s: .RS 2 .TP 2 .B \fI{allow_gc, boolean()}\fR\&: Determines if garbage collection is allowed when performing the operation\&. If \fI{allow_gc, false}\fR\& is passed, and a garbage collection is needed to determine the result of the operation, the operation is aborted (see information on \fICheckResult\fR\& below)\&. The default is to allow garbage collection, that is, \fI{allow_gc, true}\fR\&\&. .TP 2 .B \fI{async, RequestId}\fR\&: The function \fIcheck_process_code/3\fR\& returns the value \fIasync\fR\& immediately after the request has been sent\&. When the request has been processed, the process that called this function is passed a message on the form \fI{check_process_code, RequestId, CheckResult}\fR\&\&. .RE .LP If \fIPid\fR\& equals \fIself()\fR\&, and no \fIasync\fR\& option has been passed, the operation is performed at once\&. Otherwise a request for the operation is sent to the process identified by \fIPid\fR\&, and is handled when appropriate\&. If no \fIasync\fR\& option has been passed, the caller blocks until \fICheckResult\fR\& is available and can be returned\&. .LP \fICheckResult\fR\& informs about the result of the request as follows: .RS 2 .TP 2 .B \fItrue\fR\&: The process identified by \fIPid\fR\& executes old code for \fIModule\fR\&\&. That is, the current call of the process executes old code for this module, or the process has references to old code for this module, or the process contains funs that references old code for this module\&. .TP 2 .B \fIfalse\fR\&: The process identified by \fIPid\fR\& does not execute old code for \fIModule\fR\&\&. .TP 2 .B \fIaborted\fR\&: The operation was aborted, as the process needed to be garbage collected to determine the operation result, and the operation was requested by passing option \fI{allow_gc, false}\fR\&\&. .RE .LP .RS -4 .B Note: .RE Up until ERTS version 8\&.*, the check process code operation checks for all types of references to the old code\&. That is, direct references (e\&.g\&. return addresses on the process stack), indirect references (\fIfun\fR\&s in process context), and references to literals in the code\&. .LP As of ERTS version 9\&.0, the check process code operation only checks for direct references to the code\&. Indirect references via \fIfun\fR\&s will be ignored\&. If such \fIfun\fR\&s exist and are used after a purge of the old code, an exception will be raised upon usage (same as the case when the \fIfun\fR\& is received by the process after the purge)\&. Literals will be taken care of (copied) at a later stage\&. This behavior can as of ERTS version 8\&.1 be enabled when building OTP, and will automatically be enabled if dirty scheduler support is enabled\&. .LP See also \fIcode(3erl)\fR\&\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIPid\fR\& is not a node local process identifier\&. .TP 2 .B \fIbadarg\fR\&: If \fIModule\fR\& is not an atom\&. .TP 2 .B \fIbadarg\fR\&: If \fIOptionList\fR\& is an invalid list of options\&. .RE .RE .LP .nf .B erlang:convert_time_unit(Time, FromUnit, ToUnit) -> ConvertedTime .br .fi .br .RS .LP Types: .RS 3 Time = ConvertedTime = integer() .br FromUnit = ToUnit = time_unit() .br .RE .RE .RS .LP Converts the \fITime\fR\& value of time unit \fIFromUnit\fR\& to the corresponding \fIConvertedTime\fR\& value of time unit \fIToUnit\fR\&\&. The result is rounded using the floor function\&. .LP .RS -4 .B Warning: .RE You can lose accuracy and precision when converting between time units\&. To minimize such loss, collect all data at \fInative\fR\& time unit and do the conversion on the end result\&. .RE .LP .nf .B erlang:crc32(Data) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Data = iodata() .br .RE .RE .RS .LP Computes and returns the crc32 (IEEE 802\&.3 style) checksum for \fIData\fR\&\&. .RE .LP .nf .B erlang:crc32(OldCrc, Data) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 OldCrc = integer() >= 0 .br Data = iodata() .br .RE .RE .RS .LP Continues computing the crc32 checksum by combining the previous checksum, \fIOldCrc\fR\&, with the checksum of \fIData\fR\&\&. .LP The following code: .LP .nf X = erlang:crc32(Data1), Y = erlang:crc32(X,Data2). .fi .LP assigns the same value to \fIY\fR\& as this: .LP .nf Y = erlang:crc32([Data1,Data2]). .fi .RE .LP .nf .B erlang:crc32_combine(FirstCrc, SecondCrc, SecondSize) -> .B integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 FirstCrc = SecondCrc = SecondSize = integer() >= 0 .br .RE .RE .RS .LP Combines two previously computed crc32 checksums\&. This computation requires the size of the data object for the second checksum to be known\&. .LP The following code: .LP .nf Y = erlang:crc32(Data1), Z = erlang:crc32(Y,Data2). .fi .LP assigns the same value to \fIZ\fR\& as this: .LP .nf X = erlang:crc32(Data1), Y = erlang:crc32(Data2), Z = erlang:crc32_combine(X,Y,iolist_size(Data2)). .fi .RE .LP .nf .B date() -> Date .br .fi .br .RS .LP Types: .RS 3 Date = calendar:date() .br .RE .RE .RS .LP Returns the current date as \fI{Year, Month, Day}\fR\&\&. .LP The time zone and Daylight Saving Time correction depend on the underlying OS\&. The return value is based on the OS System Time\&. Example: .LP .nf > date()\&. {1995,2,19} .fi .RE .LP .nf .B erlang:decode_packet(Type, Bin, Options) -> .B {ok, Packet, Rest} | .B {more, Length} | .B {error, Reason} .br .fi .br .RS .LP Types: .RS 3 Type = .br raw | 0 | 1 | 2 | 4 | asn1 | cdr | sunrm | fcgi | tpkt | .br line | http | http_bin | httph | httph_bin .br Bin = binary() .br Options = [Opt] .br Opt = .br {packet_size, integer() >= 0} | .br {line_length, integer() >= 0} .br Packet = binary() | HttpPacket .br Rest = binary() .br Length = integer() >= 0 | undefined .br Reason = term() .br HttpPacket = .br HttpRequest | HttpResponse | HttpHeader | http_eoh | HttpError .br HttpRequest = {http_request, HttpMethod, HttpUri, HttpVersion} .br HttpResponse = .br {http_response, HttpVersion, integer(), HttpString} .br HttpHeader = .br {http_header, .br integer(), .br HttpField, .br UnmodifiedField :: HttpString, .br Value :: HttpString} .br HttpError = {http_error, HttpString} .br HttpMethod = .br \&'OPTIONS\&' | \&'GET\&' | \&'HEAD\&' | \&'POST\&' | \&'PUT\&' | \&'DELETE\&' | .br \&'TRACE\&' | HttpString .br HttpUri = .br \&'*\&' | .br {absoluteURI, .br http | https, .br Host :: HttpString, .br Port :: inet:port_number() | undefined, .br Path :: HttpString} | .br {scheme, Scheme :: HttpString, HttpString} | .br {abs_path, HttpString} | .br HttpString .br HttpVersion = .br {Major :: integer() >= 0, Minor :: integer() >= 0} .br HttpField = .br \&'Cache-Control\&' | \&'Connection\&' | \&'Date\&' | \&'Pragma\&' | .br \&'Transfer-Encoding\&' | \&'Upgrade\&' | \&'Via\&' | \&'Accept\&' | .br \&'Accept-Charset\&' | \&'Accept-Encoding\&' | \&'Accept-Language\&' | .br \&'Authorization\&' | \&'From\&' | \&'Host\&' | \&'If-Modified-Since\&' | .br \&'If-Match\&' | \&'If-None-Match\&' | \&'If-Range\&' | .br \&'If-Unmodified-Since\&' | \&'Max-Forwards\&' | .br \&'Proxy-Authorization\&' | \&'Range\&' | \&'Referer\&' | \&'User-Agent\&' | .br \&'Age\&' | \&'Location\&' | \&'Proxy-Authenticate\&' | \&'Public\&' | .br \&'Retry-After\&' | \&'Server\&' | \&'Vary\&' | \&'Warning\&' | .br \&'Www-Authenticate\&' | \&'Allow\&' | \&'Content-Base\&' | .br \&'Content-Encoding\&' | \&'Content-Language\&' | \&'Content-Length\&' | .br \&'Content-Location\&' | \&'Content-Md5\&' | \&'Content-Range\&' | .br \&'Content-Type\&' | \&'Etag\&' | \&'Expires\&' | \&'Last-Modified\&' | .br \&'Accept-Ranges\&' | \&'Set-Cookie\&' | \&'Set-Cookie2\&' | .br \&'X-Forwarded-For\&' | \&'Cookie\&' | \&'Keep-Alive\&' | .br \&'Proxy-Connection\&' | HttpString .br HttpString = string() | binary() .br .RE .RE .RS .LP Decodes the binary \fIBin\fR\& according to the packet protocol specified by \fIType\fR\&\&. Similar to the packet handling done by sockets with option \fI{packet,Type}\&.\fR\& .LP If an entire packet is contained in \fIBin\fR\&, it is returned together with the remainder of the binary as \fI{ok,Packet,Rest}\fR\&\&. .LP If \fIBin\fR\& does not contain the entire packet, \fI{more,Length}\fR\& is returned\&. \fILength\fR\& is either the expected \fItotal size\fR\& of the packet, or \fIundefined\fR\& if the expected packet size is unknown\&. \fIdecode_packet\fR\& can then be called again with more data added\&. .LP If the packet does not conform to the protocol format, \fI{error,Reason}\fR\& is returned\&. .LP \fIType\fR\&s: .RS 2 .TP 2 .B \fIraw | 0\fR\&: No packet handling is done\&. The entire binary is returned unless it is empty\&. .TP 2 .B \fI1 | 2 | 4\fR\&: Packets consist of a header specifying the number of bytes in the packet, followed by that number of bytes\&. The length of the header can be one, two, or four bytes; the order of the bytes is big-endian\&. The header is stripped off when the packet is returned\&. .TP 2 .B \fIline\fR\&: A packet is a line-terminated by a delimiter byte, default is the latin-1 newline character\&. The delimiter byte is included in the returned packet unless the line was truncated according to option \fIline_length\fR\&\&. .TP 2 .B \fIasn1 | cdr | sunrm | fcgi | tpkt\fR\&: The header is \fInot\fR\& stripped off\&. .RS 2 .LP The meanings of the packet types are as follows: .RE .RS 2 .TP 2 .B \fIasn1\fR\& - ASN\&.1 BER: .TP 2 .B \fIsunrm\fR\& - Sun\&'s RPC encoding: .TP 2 .B \fIcdr\fR\& - CORBA (GIOP 1\&.1): .TP 2 .B \fIfcgi\fR\& - Fast CGI: .TP 2 .B \fItpkt\fR\& - TPKT format [RFC1006]: .RE .TP 2 .B \fIhttp | httph | http_bin | httph_bin\fR\&: The Hypertext Transfer Protocol\&. The packets are returned with the format according to \fIHttpPacket\fR\& described earlier\&. A packet is either a request, a response, a header, or an end of header mark\&. Invalid lines are returned as \fIHttpError\fR\&\&. .RS 2 .LP Recognized request methods and header fields are returned as atoms\&. Others are returned as strings\&. Strings of unrecognized header fields are formatted with only capital letters first and after hyphen characters, for example, \fI"Sec-Websocket-Key"\fR\&\&. Header field names are also returned in \fIUnmodifiedField\fR\& as strings, without any conversion or formatting\&. .RE .RS 2 .LP The protocol type \fIhttp\fR\& is only to be used for the first line when an \fIHttpRequest\fR\& or an \fIHttpResponse\fR\& is expected\&. The following calls are to use \fIhttph\fR\& to get \fIHttpHeader\fR\&s until \fIhttp_eoh\fR\& is returned, which marks the end of the headers and the beginning of any following message body\&. .RE .RS 2 .LP The variants \fIhttp_bin\fR\& and \fIhttph_bin\fR\& return strings (\fIHttpString\fR\&) as binaries instead of lists\&. .RE .RE .LP Options: .RS 2 .TP 2 .B \fI{packet_size, integer() >= 0}\fR\&: Sets the maximum allowed size of the packet body\&. If the packet header indicates that the length of the packet is longer than the maximum allowed length, the packet is considered invalid\&. Defaults to 0, which means no size limit\&. .TP 2 .B \fI{line_length, integer() >= 0}\fR\&: For packet type \fIline\fR\&, lines longer than the indicated length are truncated\&. .RS 2 .LP Option \fIline_length\fR\& also applies to \fIhttp*\fR\& packet types as an alias for option \fIpacket_size\fR\& if \fIpacket_size\fR\& itself is not set\&. This use is only intended for backward compatibility\&. .RE .TP 2 .B \fI{line_delimiter, 0 =< byte() =< 255}\fR\&: For packet type \fIline\fR\&, sets the delimiting byte\&. Default is the latin-1 character \fI$\\n\fR\&\&. .RE .LP Examples: .LP .nf > erlang:decode_packet(1,<<3,"abcd">>,[])\&. {ok,<<"abc">>,<<"d">>} > erlang:decode_packet(1,<<5,"abcd">>,[])\&. {more,6} .fi .RE .LP .nf .B erlang:delete_element(Index, Tuple1) -> Tuple2 .br .fi .br .RS .LP Types: .RS 3 Index = integer() >= 1 .br .RS 2 1\&.\&.tuple_size(Tuple1) .RE Tuple1 = Tuple2 = tuple() .br .RE .RE .RS .LP Returns a new tuple with element at \fIIndex\fR\& removed from tuple \fITuple1\fR\&, for example: .LP .nf > erlang:delete_element(2, {one, two, three})\&. {one,three} .fi .RE .LP .nf .B delete_module(Module) -> true | undefined .br .fi .br .RS .LP Types: .RS 3 Module = module() .br .RE .RE .RS .LP Makes the current code for \fIModule\fR\& become old code and deletes all references for this module from the export table\&. Returns \fIundefined\fR\& if the module does not exist, otherwise \fItrue\fR\&\&. .LP .RS -4 .B Warning: .RE This BIF is intended for the code server (see \fIcode(3erl)\fR\&) and is not to be used elsewhere\&. .LP Failure: \fIbadarg\fR\& if there already is an old version of \fIModule\fR\&\&. .RE .LP .nf .B demonitor(MonitorRef) -> true .br .fi .br .RS .LP Types: .RS 3 MonitorRef = reference() .br .RE .RE .RS .LP If \fIMonitorRef\fR\& is a reference that the calling process obtained by calling \fImonitor/2\fR\&, this monitoring is turned off\&. If the monitoring is already turned off, nothing happens\&. .LP Once \fIdemonitor(MonitorRef)\fR\& has returned, it is guaranteed that no \fI{\&'DOWN\&', MonitorRef, _, _, _}\fR\& message, because of the monitor, will be placed in the caller message queue in the future\&. However, a \fI{\&'DOWN\&', MonitorRef, _, _, _}\fR\& message can have been placed in the caller message queue before the call\&. It is therefore usually advisable to remove such a \fI\&'DOWN\&'\fR\& message from the message queue after monitoring has been stopped\&. \fIdemonitor(MonitorRef, [flush])\fR\& can be used instead of \fIdemonitor(MonitorRef)\fR\& if this cleanup is wanted\&. .LP .RS -4 .B Note: .RE Before Erlang/OTP R11B (ERTS 5\&.5) \fIdemonitor/1\fR\& behaved completely asynchronously, that is, the monitor was active until the "demonitor signal" reached the monitored entity\&. This had one undesirable effect\&. You could never know when you were guaranteed \fInot\fR\& to receive a \fIDOWN\fR\& message because of the monitor\&. .LP The current behavior can be viewed as two combined operations: asynchronously send a "demonitor signal" to the monitored entity and ignore any future results of the monitor\&. .LP Failure: It is an error if \fIMonitorRef\fR\& refers to a monitoring started by another process\&. Not all such cases are cheap to check\&. If checking is cheap, the call fails with \fIbadarg\fR\&, for example if \fIMonitorRef\fR\& is a remote reference\&. .RE .LP .nf .B demonitor(MonitorRef, OptionList) -> boolean() .br .fi .br .RS .LP Types: .RS 3 MonitorRef = reference() .br OptionList = [Option] .br Option = flush | info .br .RE .RE .RS .LP The returned value is \fItrue\fR\& unless \fIinfo\fR\& is part of \fIOptionList\fR\&\&. .LP \fIdemonitor(MonitorRef, [])\fR\& is equivalent to \fIdemonitor(MonitorRef)\fR\&\&. .LP \fIOption\fR\&s: .RS 2 .TP 2 .B \fIflush\fR\&: Removes (one) \fI{_, MonitorRef, _, _, _}\fR\& message, if there is one, from the caller message queue after monitoring has been stopped\&. .RS 2 .LP Calling \fIdemonitor(MonitorRef, [flush])\fR\& is equivalent to the following, but more efficient: .RE .LP .nf demonitor(MonitorRef), receive {_, MonitorRef, _, _, _} -> true after 0 -> true end .fi .TP 2 .B \fIinfo\fR\&: The returned value is one of the following: .RS 2 .TP 2 .B \fItrue\fR\&: The monitor was found and removed\&. In this case, no \fI\&'DOWN\&'\fR\& message corresponding to this monitor has been delivered and will not be delivered\&. .TP 2 .B \fIfalse\fR\&: The monitor was not found and could not be removed\&. This probably because someone already has placed a \fI\&'DOWN\&'\fR\& message corresponding to this monitor in the caller message queue\&. .RE .RS 2 .LP If option \fIinfo\fR\& is combined with option \fIflush\fR\&, \fIfalse\fR\& is returned if a flush was needed, otherwise \fItrue\fR\&\&. .RE .RE .LP .RS -4 .B Note: .RE More options can be added in a future release\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIOptionList\fR\& is not a list\&. .TP 2 .B \fIbadarg\fR\&: If \fIOption\fR\& is an invalid option\&. .TP 2 .B \fIbadarg\fR\&: The same failure as for \fIdemonitor/1\fR\&\&. .RE .RE .LP .nf .B disconnect_node(Node) -> boolean() | ignored .br .fi .br .RS .LP Types: .RS 3 Node = node() .br .RE .RE .RS .LP Forces the disconnection of a node\&. This appears to the node \fINode\fR\& as if the local node has crashed\&. This BIF is mainly used in the Erlang network authentication protocols\&. .LP Returns \fItrue\fR\& if disconnection succeeds, otherwise \fIfalse\fR\&\&. If the local node is not alive, \fIignored\fR\& is returned\&. .LP .RS -4 .B Note: .RE This function may return before \fInodedown\fR\& messages have been delivered\&. .RE .LP .nf .B erlang:display(Term) -> true .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Prints a text representation of \fITerm\fR\& on the standard output\&. .LP .RS -4 .B Warning: .RE This BIF is intended for debugging only\&. The printed representation may contain internal details that do not match the high-level representation of the term in Erlang\&. .RE .LP .nf .B erlang:dist_ctrl_get_data(DHandle) -> {Size, Data} | Data | none .br .fi .br .RS .LP Types: .RS 3 Size = integer() >= 0 .br DHandle = dist_handle() .br Data = iovec() .br .RE .RE .RS .LP Get distribution channel data from the local node that is to be passed to the remote node\&. The distribution channel is identified by \fIDHandle\fR\&\&. If no data is available, the atom \fInone\fR\& is returned\&. One can request to be informed by a message when more data is available by calling \fIerlang:dist_ctrl_get_data_notification(DHandle)\fR\&\&. .LP The returned value when there are data available depends on the value of the \fIget_size\fR\& option configured on the distribution channel identified by \fIDHandle\fR\&\&. For more information see the documentation of the \fIget_size\fR\& option for the \fIerlang:dist_ctrl_set_opt/3\fR\& function\&. .LP .RS -4 .B Note: .RE Only the process registered as distribution controller for the distribution channel identified by \fIDHandle\fR\& is allowed to call this function\&. .LP This function is used when implementing an alternative distribution carrier using processes as distribution controllers\&. \fIDHandle\fR\& is retrieved via the callback \fIf_handshake_complete\fR\&\&. More information can be found in the documentation of ERTS User\&'s Guide ➜ How to implement an Alternative Carrier for the Erlang Distribution ➜ Distribution Module\&. .RE .LP .nf .B erlang:dist_ctrl_get_opt(DHandle, Opt :: get_size) -> Value .br .fi .br .RS .LP Types: .RS 3 DHandle = dist_handle() .br Value = boolean() .br .RE .RE .RS .LP Returns the value of the \fIget_size\fR\& option on the distribution channel identified by \fIDHandle\fR\&\&. For more information see the documentation of the \fIget_size\fR\& option for the \fIerlang:dist_ctrl_set_opt/3\fR\& function\&. .LP .RS -4 .B Note: .RE Only the process registered as distribution controller for the distribution channel identified by \fIDHandle\fR\& is allowed to call this function\&. .LP This function is used when implementing an alternative distribution carrier using processes as distribution controllers\&. \fIDHandle\fR\& is retrieved via the callback \fIf_handshake_complete\fR\&\&. More information can be found in the documentation of ERTS User\&'s Guide ➜ How to implement an Alternative Carrier for the Erlang Distribution ➜ Distribution Module\&. .RE .LP .nf .B erlang:dist_ctrl_get_data_notification(DHandle) -> ok .br .fi .br .RS .LP Types: .RS 3 DHandle = dist_handle() .br .RE .RE .RS .LP Request notification when more data is available to fetch using \fIerlang:dist_ctrl_get_data(DHandle)\fR\& for the distribution channel identified by \fIDHandle\fR\&\&. When more data is present, the caller will be sent the message \fIdist_data\fR\&\&. Once a \fIdist_data\fR\& messages has been sent, no more \fIdist_data\fR\& messages will be sent until the \fIdist_ctrl_get_data_notification/1\fR\& function has been called again\&. .LP .RS -4 .B Note: .RE Only the process registered as distribution controller for the distribution channel identified by \fIDHandle\fR\& is allowed to call this function\&. .LP This function is used when implementing an alternative distribution carrier using processes as distribution controllers\&. \fIDHandle\fR\& is retrieved via the callback \fIf_handshake_complete\fR\&\&. More information can be found in the documentation of ERTS User\&'s Guide ➜ How to implement an Alternative Carrier for the Erlang Distribution ➜ Distribution Module\&. .RE .LP .nf .B erlang:dist_ctrl_input_handler(DHandle, InputHandler) -> ok .br .fi .br .RS .LP Types: .RS 3 DHandle = dist_handle() .br InputHandler = pid() .br .RE .RE .RS .LP Register an alternate input handler process for the distribution channel identified by \fIDHandle\fR\&\&. Once this function has been called, \fIInputHandler\fR\& is the only process allowed to call \fIerlang:dist_ctrl_put_data(DHandle, Data)\fR\& with the \fIDHandle\fR\& identifying this distribution channel\&. .LP .RS -4 .B Note: .RE Only the process registered as distribution controller for the distribution channel identified by \fIDHandle\fR\& is allowed to call this function\&. .LP This function is used when implementing an alternative distribution carrier using processes as distribution controllers\&. \fIDHandle\fR\& is retrieved via the callback \fIf_handshake_complete\fR\&\&. More information can be found in the documentation of ERTS User\&'s Guide ➜ How to implement an Alternative Carrier for the Erlang Distribution ➜ Distribution Module\&. .RE .LP .nf .B erlang:dist_ctrl_put_data(DHandle, Data) -> ok .br .fi .br .RS .LP Types: .RS 3 DHandle = dist_handle() .br Data = iodata() .br .RE .RE .RS .LP Deliver distribution channel data from a remote node to the local node\&. .LP .RS -4 .B Note: .RE Only the process registered as distribution controller for the distribution channel identified by \fIDHandle\fR\& is allowed to call this function unless an alternate input handler process has been registered using \fIerlang:dist_ctrl_input_handler(DHandle, InputHandler)\fR\&\&. If an alternate input handler has been registered, only the registered input handler process is allowed to call this function\&. .LP This function is used when implementing an alternative distribution carrier using processes as distribution controllers\&. \fIDHandle\fR\& is retrieved via the callback \fIf_handshake_complete\fR\&\&. More information can be found in the documentation of ERTS User\&'s Guide ➜ How to implement an Alternative Carrier for the Erlang Distribution ➜ Distribution Module\&. .RE .LP .nf .B erlang:dist_ctrl_set_opt(DHandle, Opt :: get_size, Value) -> .B OldValue .br .fi .br .RS .LP Types: .RS 3 DHandle = dist_handle() .br Value = OldValue = boolean() .br .RE .RE .RS .LP Sets the value of the \fIget_size\fR\& option on the distribution channel identified by \fIDHandle\fR\&\&. This option controls the return value of calls to erlang:dist_ctrl_get_data(DHandle) where \fIDHandle\fR\& equals \fIDHandle\fR\& used when setting this option\&. When the \fIget_size\fR\& option is: .RS 2 .TP 2 .B \fIfalse\fR\&: and there are distribution data available, a call to \fIerlang:dist_ctrl_get_data(DHandle)\fR\& will just return \fIData\fR\& to pass over the channel\&. This is the default value of the \fIget_size\fR\& option\&. .TP 2 .B \fItrue\fR\&: and there are distribution data available, a call to \fIerlang:dist_ctrl_get_data(DHandle)\fR\& will return \fIData\fR\& to pass over the channel as well as the \fISize\fR\& of \fIData\fR\& in bytes\&. This is returned as a tuple on the form \fI{Size, Data}\fR\&\&. .RE .LP All options are set to default when a channel is closed\&. .LP .RS -4 .B Note: .RE Only the process registered as distribution controller for the distribution channel identified by \fIDHandle\fR\& is allowed to call this function\&. .LP This function is used when implementing an alternative distribution carrier using processes as distribution controllers\&. \fIDHandle\fR\& is retrieved via the callback \fIf_handshake_complete\fR\&\&. More information can be found in the documentation of ERTS User\&'s Guide ➜ How to implement an Alternative Carrier for the Erlang Distribution ➜ Distribution Module\&. .RE .LP .nf .B element(N, Tuple) -> term() .br .fi .br .RS .LP Types: .RS 3 N = integer() >= 1 .br .RS 2 1\&.\&.tuple_size(Tuple) .RE Tuple = tuple() .br .RE .RE .RS .LP Returns the \fIN\fR\&th element (numbering from 1) of \fITuple\fR\&, for example: .LP .nf > element(2, {a, b, c})\&. b .fi .LP Allowed in guard tests\&. .RE .LP .nf .B erase() -> [{Key, Val}] .br .fi .br .RS .LP Types: .RS 3 Key = Val = term() .br .RE .RE .RS .LP Returns the process dictionary and deletes it, for example: .LP .nf > put(key1, {1, 2, 3}), put(key2, [a, b, c]), erase()\&. [{key1,{1,2,3}},{key2,[a,b,c]}] .fi .RE .LP .nf .B erase(Key) -> Val | undefined .br .fi .br .RS .LP Types: .RS 3 Key = Val = term() .br .RE .RE .RS .LP Returns the value \fIVal\fR\& associated with \fIKey\fR\& and deletes it from the process dictionary\&. Returns \fIundefined\fR\& if no value is associated with \fIKey\fR\&\&. The average time complexity for the current implementation of this function is O(\fI1\fR\&) and the worst case time complexity is O(\fIN\fR\&), where \fIN\fR\& is the number of items in the process dictionary\&. Example: .LP .nf > put(key1, {merry, lambs, are, playing}), X = erase(key1), {X, erase(key1)}\&. {{merry,lambs,are,playing},undefined} .fi .RE .LP .nf .B error(Reason) -> no_return() .br .fi .br .RS .LP Types: .RS 3 Reason = term() .br .RE .RE .RS .LP Raises an exception of class \fIerror\fR\& with the reason \fIReason\fR\&\&. As evaluating this function causes an exception to be thrown, it has no return value\&. .LP The intent of the exception class \fIerror\fR\& is to signal that an unexpected error has happened (for example, a function is called with a parameter that has an incorrect type)\&. See the guide about errors and error handling for additional information\&. Example: .LP .nf > catch error(foobar)\&. {'EXIT',{foobar,[{shell,apply_fun,3, [{file,"shell.erl"},{line,906}]}, {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,677}]}, {erl_eval,expr,5,[{file,"erl_eval.erl"},{line,430}]}, {shell,exprs,7,[{file,"shell.erl"},{line,687}]}, {shell,eval_exprs,7,[{file,"shell.erl"},{line,642}]}, {shell,eval_loop,3,[{file,"shell.erl"},{line,627}]}]}} .fi .RE .LP .nf .B error(Reason, Args) -> no_return() .br .fi .br .RS .LP Types: .RS 3 Reason = term() .br Args = [term()] | none .br .RE .RE .RS .LP Raises an exception of class \fIerror\fR\& with the reason \fIReason\fR\&\&. \fIArgs\fR\& is expected to be the list of arguments for the current function or the atom \fInone\fR\&\&. If it is a list, it is used to provide the arguments for the current function in the stack back-trace\&. If it is \fInone\fR\&, the arity of the calling function is used in the stacktrace\&. As evaluating this function causes an exception to be raised, it has no return value\&. .LP The intent of the exception class \fIerror\fR\& is to signal that an unexpected error has happened (for example, a function is called with a parameter that has an incorrect type)\&. See the guide about errors and error handling for additional information\&. Example: .LP \fItest\&.erl\fR\&: .LP .nf -module(test). -export([example_fun/2]). example_fun(A1, A2) -> erlang:error(my_error, [A1, A2]). .fi .LP Erlang shell: .LP .nf 6> c(test)\&. {ok,test} 7> test:example_fun(arg1,"this is the second argument")\&. ** exception error: my_error in function test:example_fun/2 called as test:example_fun(arg1,"this is the second argument") .fi .RE .LP .nf .B error(Reason, Args, Options) -> no_return() .br .fi .br .RS .LP Types: .RS 3 Reason = term() .br Args = [term()] | none .br Options = [Option] .br Option = {error_info, ErrorInfoMap} .br ErrorInfoMap = .br #{cause => term(), module => module(), function => atom()} .br .RE .RE .RS .LP Raises an exception of class \fIerror\fR\& with the reason \fIReason\fR\&\&. \fIArgs\fR\& is expected to be the list of arguments for the current function or the atom \fInone\fR\&\&. If it is a list, it is used to provide the arguments for the current function in the stack back-trace\&. If it is \fInone\fR\&, the arity of the calling function is used in the stacktrace\&. As evaluating this function causes an exception to be raised, it has no return value\&. .LP If the \fIerror_info\fR\& option is given, the \fIErrorInfoMap\fR\& will be inserted into the stacktrace\&. The information given in the \fIErrorInfoMap\fR\& is to be used by error formatters such as \fIerl_error\fR\& to provide more context around an error\&. .LP The default \fImodule\fR\& of the \fIErrorInfoMap\fR\& is the module that the call to \fIerror/3\fR\& is made\&. The default \fIfunction\fR\& is \fIformat_error\fR\&\&. See \fIformat_error/2\fR\& for more details on how this Module:Function/2 is to be used .LP The intent of the exception class \fIerror\fR\& is to signal that an unexpected error has happened (for example, a function is called with a parameter that has an incorrect type)\&. See the guide about errors and error handling for additional information\&. .RE .LP .nf .B exit(Reason) -> no_return() .br .fi .br .RS .LP Types: .RS 3 Reason = term() .br .RE .RE .RS .LP Raises an exception of class \fIexit\fR\& with exit reason \fIReason\fR\&\&. As evaluating this function causes an exception to be raised, it has no return value\&. .LP The intent of the exception class \fIexit\fR\& is that the current process should be stopped (for example when a message telling a process to stop is received)\&. .LP This function differ from \fIerror/1,2,3\fR\& by causing an exception of a different class and by having a reason that does not include the list of functions from the call stack\&. .LP See the guide about errors and error handling for additional information\&. .LP Example: .LP .nf > exit(foobar)\&. ** exception exit: foobar > catch exit(foobar)\&. {'EXIT',foobar} .fi .LP .RS -4 .B Note: .RE If a process calls \fIexit(kill)\fR\& and does not catch the exception, it will terminate with exit reason \fIkill\fR\& and also emit exit signals with exit reason \fIkill\fR\& (not \fIkilled\fR\&) to all linked processes\&. Such exit signals with exit reason \fIkill\fR\& can be trapped by the linked processes\&. Note that this means that signals with exit reason \fIkill\fR\& behave differently depending on how they are sent because the signal will be untrappable if a process sends such a signal to another process with \fIerlang:exit/2\fR\&\&. .RE .LP .nf .B exit(Pid, Reason) -> true .br .fi .br .RS .LP Types: .RS 3 Pid = pid() | port() .br Reason = term() .br .RE .RE .RS .LP Sends an exit signal with exit reason \fIReason\fR\& to the process or port identified by \fIPid\fR\&\&. .LP The following behavior applies if \fIReason\fR\& is any term, except \fInormal\fR\& or \fIkill\fR\&, and \fIP\fR\& is the process or port identified by \fIPid\fR\&: .RS 2 .TP 2 * If \fIP\fR\& is not trapping exits, \fIP\fR\& exits with exit reason \fIReason\fR\&\&. .LP .TP 2 * If \fIP\fR\& is trapping exits, the exit signal is transformed into a message \fI{\&'EXIT\&', From, Reason}\fR\&, where \fIFrom\fR\& is the process identifier of the process that sent the exit signal, and delivered to the message queue of \fIP\fR\&\&. .LP .RE .LP The following behavior applies if \fIReason\fR\& is the term \fInormal\fR\& and \fIPid\fR\& is the identifier of a process \fIP\fR\& which is not the same as the process that invoked \fIerlang:exit(Pid, normal)\fR\& (the behavior when a process sends a signal with the \fInormal\fR\& reason to itself is described in the warning): .RS 2 .TP 2 * If \fIP\fR\& is trapping exits, the exit signal is transformed into a message \fI{\&'EXIT\&', From, normal}\fR\&, where \fIFrom\fR\& is the process identifier of the process that sent the exit signal, and delivered to \fIP\fR\&\&'s message queue\&. .LP .TP 2 * The signal has no effect if \fIP\fR\& is not trapping exits\&. .LP .RE .LP If \fIReason\fR\& is the atom \fIkill\fR\&, that is, if \fIexit(Pid, kill)\fR\& is called, an untrappable exit signal is sent to the process that is identified by \fIPid\fR\&, which unconditionally exits with exit reason \fIkilled\fR\&\&. The exit reason is changed from \fIkill\fR\& to \fIkilled\fR\& to hint to linked processes that the killed process got killed by a call to \fIexit(Pid, kill)\fR\&\&. .LP .RS -4 .B Note: .RE The functions \fIerlang:exit/1\fR\& and \fIerlang:exit/2\fR\& are named similarly but provide very different functionalities\&. The \fIerlang:exit/1\fR\& function should be used when the intent is to stop the current process while \fIerlang:exit/2\fR\& should be used when the intent is to send an exit signal to another process\&. Note also that \fIerlang:exit/1\fR\& raises an exception that can be caught while \fIerlang:exit/2\fR\& does not cause any exception to be raised\&. .LP .RS -4 .B Warning: .RE The only scenario that has not been covered by the description above is when a process \fIP\fR\& sends an exit signal with reason \fInormal\fR\& to itself, that is \fIerlang:exit(self(), normal)\fR\&\&. The behavior in this scenario is as follows: .RS 2 .TP 2 * If \fIP\fR\& is trapping exits, the exit signal is transformed into a message \fI{\&'EXIT\&', From, normal}\fR\&, where \fIFrom\fR\& is \fIP\fR\&\&'s process identifier, and delivered to \fIP\fR\&\&'s message queue\&. .LP .TP 2 * \fIP\fR\& exits with reason \fInormal\fR\& if \fIP\fR\& is not trapping exits\&. .LP .RE .LP Note that the behavior described above is different from when a process sends an exit signal with reason \fInormal\fR\& to another process\&. This is arguably strange but this behavior is kept for backward compatibility reasons\&. .RE .LP .nf .B erlang:external_size(Term) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Calculates, without doing the encoding, the maximum byte size for a term encoded in the Erlang external term format\&. The following condition applies always: .LP .nf > Size1 = byte_size(term_to_binary(Term)), > Size2 = erlang:external_size(Term), > true = Size1 =< Size2\&. true .fi .LP This is equivalent to a call to: .LP .nf erlang:external_size(Term, []) .fi .RE .LP .nf .B erlang:external_size(Term, Options) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Term = term() .br Options = [{minor_version, Version :: integer() >= 0}] .br .RE .RE .RS .LP Calculates, without doing the encoding, the maximum byte size for a term encoded in the Erlang external term format\&. The following condition applies always: .LP .nf > Size1 = byte_size(term_to_binary(Term, Options)), > Size2 = erlang:external_size(Term, Options), > true = Size1 =< Size2\&. true .fi .LP Option \fI{minor_version, Version}\fR\& specifies how floats are encoded\&. For a detailed description, see \fIterm_to_binary/2\fR\&\&. .RE .LP .nf .B float(Number) -> float() .br .fi .br .RS .LP Types: .RS 3 Number = number() .br .RE .RE .RS .LP Returns a float by converting \fINumber\fR\& to a float, for example: .LP .nf > float(55)\&. 55.0 .fi .LP Allowed in guard tests\&. .LP .RS -4 .B Note: .RE If used on the top level in a guard, it tests whether the argument is a floating point number; for clarity, use \fIis_float/1\fR\& instead\&. .LP When \fIfloat/1\fR\& is used in an expression in a guard, such as \&'\fIfloat(A) == 4\&.0\fR\&\&', it converts a number as described earlier\&. .RE .LP .nf .B float_to_binary(Float) -> binary() .br .fi .br .RS .LP Types: .RS 3 Float = float() .br .RE .RE .RS .LP The same as \fIfloat_to_binary(Float,[{scientific,20}])\fR\&\&. .RE .LP .nf .B float_to_binary(Float, Options) -> binary() .br .fi .br .RS .LP Types: .RS 3 Float = float() .br Options = [Option] .br Option = .br {decimals, Decimals :: 0\&.\&.253} | .br {scientific, Decimals :: 0\&.\&.249} | .br compact | short .br .RE .RE .RS .LP Returns a binary corresponding to the text representation of \fIFloat\fR\& using fixed decimal point formatting\&. \fIOptions\fR\& behaves in the same way as \fIfloat_to_list/2\fR\&\&. Examples: .LP .nf > float_to_binary(7\&.12, [{decimals, 4}])\&. <<"7.1200">> > float_to_binary(7\&.12, [{decimals, 4}, compact])\&. <<"7.12">> > float_to_binary(7\&.12, [{scientific, 3}])\&. <<"7.120e+00">> > float_to_binary(7\&.12, [short])\&. <<"7.12">> > float_to_binary(0\&.1+0\&.2, [short])\&. <<"0.30000000000000004">> > float_to_binary(0\&.1+0\&.2) <<"3.00000000000000044409e-01">> .fi .RE .LP .nf .B float_to_list(Float) -> string() .br .fi .br .RS .LP Types: .RS 3 Float = float() .br .RE .RE .RS .LP The same as \fIfloat_to_list(Float,[{scientific,20}])\fR\&\&. .RE .LP .nf .B float_to_list(Float, Options) -> string() .br .fi .br .RS .LP Types: .RS 3 Float = float() .br Options = [Option] .br Option = .br {decimals, Decimals :: 0\&.\&.253} | .br {scientific, Decimals :: 0\&.\&.249} | .br compact | short .br .RE .RE .RS .LP Returns a string corresponding to the text representation of \fIFloat\fR\& using fixed decimal point formatting\&. .LP Available options: .RS 2 .TP 2 * If option \fIdecimals\fR\& is specified, the returned value contains at most \fIDecimals\fR\& number of digits past the decimal point\&. If the number does not fit in the internal static buffer of 256 bytes, the function throws \fIbadarg\fR\&\&. .LP .TP 2 * If option \fIcompact\fR\& is specified, the trailing zeros at the end of the list are truncated\&. This option is only meaningful together with option \fIdecimals\fR\&\&. .LP .TP 2 * If option \fIscientific\fR\& is specified, the float is formatted using scientific notation with \fIDecimals\fR\& digits of precision\&. .LP .TP 2 * If option \fIshort\fR\& is specified, the float is formatted with the smallest number of digits that still guarantees that \fIF =:= list_to_float(float_to_list(F, [short]))\fR\&\&. When the float is inside the range (-2⁵³, 2⁵³), the notation that yields the smallest number of characters is used (scientific notation or normal decimal notation)\&. Floats outside the range (-2⁵³, 2⁵³) are always formatted using scientific notation to avoid confusing results when doing arithmetic operations\&. .LP .TP 2 * If \fIOptions\fR\& is \fI[]\fR\&, the function behaves as \fIfloat_to_list/1\fR\&\&. .LP .RE .LP Examples: .LP .nf > float_to_list(7\&.12, [{decimals, 4}])\&. "7.1200" > float_to_list(7\&.12, [{decimals, 4}, compact])\&. "7.12" > float_to_list(7\&.12, [{scientific, 3}])\&. "7.120e+00" > float_to_list(7\&.12, [short])\&. "7.12" > float_to_list(0\&.1+0\&.2, [short])\&. "0.30000000000000004" > float_to_list(0\&.1+0\&.2) "3.00000000000000044409e-01" .fi .LP In the last example, \fIfloat_to_list(0\&.1+0\&.2)\fR\& evaluates to \fI"3\&.00000000000000044409e-01"\fR\&\&. The reason for this is explained in Representation of Floating Point Numbers\&. .RE .LP .nf .B floor(Number) -> integer() .br .fi .br .RS .LP Types: .RS 3 Number = number() .br .RE .RE .RS .LP Returns the largest integer not greater than \fINumber\fR\&\&. For example: .LP .nf > floor(-10\&.5)\&. -11 .fi .LP Allowed in guard tests\&. .RE .LP .nf .B erlang:fun_info(Fun) -> [{Item, Info}] .br .fi .br .RS .LP Types: .RS 3 Fun = function() .br Item = .br arity | env | index | name | module | new_index | new_uniq | .br pid | type | uniq .br Info = term() .br .RE .RE .RS .LP Returns a list with information about the fun \fIFun\fR\&\&. Each list element is a tuple\&. The order of the tuples is undefined, and more tuples can be added in a future release\&. .LP .RS -4 .B Warning: .RE This BIF is mainly intended for debugging, but it can sometimes be useful in library functions that need to verify, for example, the arity of a fun\&. .LP Two types of funs have slightly different semantics: .RS 2 .TP 2 * A fun created by \fIfun M:F/A\fR\& is called an \fIexternal\fR\& fun\&. Calling it will always call the function \fIF\fR\& with arity \fIA\fR\& in the latest code for module \fIM\fR\&\&. Notice that module \fIM\fR\& does not even need to be loaded when the fun \fIfun M:F/A\fR\& is created\&. .LP .TP 2 * All other funs are called \fIlocal\fR\&\&. When a local fun is called, the same version of the code that created the fun is called (even if a newer version of the module has been loaded)\&. .LP .RE .LP The following elements are always present in the list for both local and external funs: .RS 2 .TP 2 .B \fI{type, Type}\fR\&: \fIType\fR\& is \fIlocal\fR\& or \fIexternal\fR\&\&. .TP 2 .B \fI{module, Module}\fR\&: \fIModule\fR\& (an atom) is the module name\&. .RS 2 .LP If \fIFun\fR\& is a local fun, \fIModule\fR\& is the module in which the fun is defined\&. .RE .RS 2 .LP If \fIFun\fR\& is an external fun, \fIModule\fR\& is the module that the fun refers to\&. .RE .TP 2 .B \fI{name, Name}\fR\&: \fIName\fR\& (an atom) is a function name\&. .RS 2 .LP If \fIFun\fR\& is a local fun, \fIName\fR\& is the name of the local function that implements the fun\&. (This name was generated by the compiler, and is only of informational use\&. As it is a local function, it cannot be called directly\&.) If no code is currently loaded for the fun, \fI[]\fR\& is returned instead of an atom\&. .RE .RS 2 .LP If \fIFun\fR\& is an external fun, \fIName\fR\& is the name of the exported function that the fun refers to\&. .RE .TP 2 .B \fI{arity, Arity}\fR\&: \fIArity\fR\& is the number of arguments that the fun is to be called with\&. .TP 2 .B \fI{env, Env}\fR\&: \fIEnv\fR\& (a list) is the environment or free variables for the fun\&. For external funs, the returned list is always empty\&. .RE .LP The following elements are only present in the list if \fIFun\fR\& is local: .RS 2 .TP 2 .B \fI{pid, Pid}\fR\&: \fIPid\fR\& is the process identifier of the process that originally created the fun\&. .RS 2 .LP It might point to the \fIinit\fR\& process if the \fIFun\fR\& was statically allocated when module was loaded (this optimisation is performed for local functions that do not capture the environment)\&. .RE .TP 2 .B \fI{index, Index}\fR\&: \fIIndex\fR\& (an integer) is an index into the module fun table\&. .TP 2 .B \fI{new_index, Index}\fR\&: \fIIndex\fR\& (an integer) is an index into the module fun table\&. .TP 2 .B \fI{new_uniq, Uniq}\fR\&: \fIUniq\fR\& (a binary) is a unique value for this fun\&. It is calculated from the compiled code for the entire module\&. .TP 2 .B \fI{uniq, Uniq}\fR\&: \fIUniq\fR\& (an integer) is a unique value for this fun\&. As from Erlang/OTP R15, this integer is calculated from the compiled code for the entire module\&. Before Erlang/OTP R15, this integer was based on only the body of the fun\&. .RE .RE .LP .nf .B erlang:fun_info(Fun, Item) -> {Item, Info} .br .fi .br .RS .LP Types: .RS 3 Fun = function() .br Item = fun_info_item() .br Info = term() .br .nf \fBfun_info_item()\fR\& = .br arity | env | index | name | module | new_index | new_uniq | .br pid | type | uniq .fi .br .RE .RE .RS .LP Returns information about \fIFun\fR\& as specified by \fIItem\fR\&, in the form \fI{Item,Info}\fR\&\&. .LP For any fun, \fIItem\fR\& can be any of the atoms \fImodule\fR\&, \fIname\fR\&, \fIarity\fR\&, \fIenv\fR\&, or \fItype\fR\&\&. .LP For a local fun, \fIItem\fR\& can also be any of the atoms \fIindex\fR\&, \fInew_index\fR\&, \fInew_uniq\fR\&, \fIuniq\fR\&, and \fIpid\fR\&\&. For an external fun, the value of any of these items is always the atom \fIundefined\fR\&\&. .LP See \fIerlang:fun_info/1\fR\&\&. .RE .LP .nf .B erlang:fun_to_list(Fun) -> String :: string() .br .fi .br .RS .LP Types: .RS 3 Fun = function() .br .RE .RE .RS .LP Returns \fIString\fR\& that represents the code that created \fIFun\fR\&\&. .LP \fIString\fR\& has the following form, if \fIFun\fR\& was created by a fun expression of the form \fIfun ModuleName:FuncName/Arity\fR\&: .LP \fI"fun ModuleName:FuncName/Arity"\fR\& .LP The form of \fIString\fR\& when \fIFun\fR\& is created from other types of fun expressions differs depending on if the fun expression was executed while executing compiled code or if the fun expression was executed while executing uncompiled code (uncompiled escripts, the Erlang shell, and other code executed by the erl_eval module): .RS 2 .TP 2 .B compiled code: \fI"#Fun"\fR\&, where M, I and U correspond to the values named \fImodule\fR\&, \fIindex\fR\& and \fIuniq\fR\& in the result of \fIerlang:fun_info(Fun)\fR\&\&. .TP 2 .B uncompiled code: All funs created from fun expressions in uncompiled code with the same arity are mapped to the same list by \fIfun_to_list/1\fR\&\&. .RE .LP .RS -4 .B Note: .RE Generally, one can not use \fIfun_to_list/1\fR\& to check if two funs are equal as \fIfun_to_list/1\fR\& does not take the fun\&'s environment into account\&. See \fIerlang:fun_info/1\fR\& for how to get the environment of a fun\&. .LP .RS -4 .B Note: .RE The output of \fIfun_to_list/1\fR\& can differ between Erlang implementations and may change in future versions\&. .LP Examples: .LP .nf -module(test). -export([add/1, add2/0, fun_tuple/0]). add(A) -> fun(B) -> A + B end. add2() -> fun add/1. fun_tuple() -> {fun() -> 1 end, fun() -> 1 end}. .fi .LP .nf > {fun test:add/1, test:add2()}\&. {fun test:add/1,#Fun} .fi .LP Explanation: \fIfun test:add/1\fR\& is upgradable but \fItest:add2()\fR\& is not upgradable\&. .LP .nf > {test:add(1), test:add(42)}\&. {#Fun,#Fun} .fi .LP Explanation: \fItest:add(1)\fR\& and \fItest:add(42)\fR\& has the same string representation as the environment is not taken into account\&. .LP .nf >test:fun_tuple()\&. {#Fun,#Fun} .fi .LP Explanation: The string representations differ because the funs come from different fun expressions\&. .LP .nf > {fun() -> 1 end, fun() -> 1 end}\&. > {#Fun,#Fun} .fi .LP Explanation: All funs created from fun expressions of this form in uncompiled code with the same arity are mapped to the same list by \fIfun_to_list/1\fR\&\&. .RE .LP .nf .B erlang:function_exported(Module, Function, Arity) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Arity = arity() .br .RE .RE .RS .LP Returns \fItrue\fR\& if the module \fIModule\fR\& is current and contains an exported function \fIFunction/Arity\fR\&, or if there is a BIF (a built-in function implemented in C) with the specified name, otherwise returns \fIfalse\fR\&\&. .RE .LP .nf .B garbage_collect() -> true .br .fi .br .RS .LP Forces an immediate garbage collection of the executing process\&. The function is not to be used unless it has been noticed (or there are good reasons to suspect) that the spontaneous garbage collection will occur too late or not at all\&. .LP .RS -4 .B Warning: .RE Improper use can seriously degrade system performance\&. .RE .LP .nf .B garbage_collect(Pid) -> GCResult .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br GCResult = boolean() .br .RE .RE .RS .LP The same as \fIgarbage_collect(Pid, [])\fR\&\&. .RE .LP .nf .B garbage_collect(Pid, OptionList) -> GCResult | async .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br RequestId = term() .br Option = {async, RequestId} | {type, major | minor} .br OptionList = [Option] .br GCResult = boolean() .br .RE .RE .RS .LP Garbage collects the node local process identified by \fIPid\fR\&\&. .LP \fIOption\fR\&: .RS 2 .TP 2 .B \fI{async, RequestId}\fR\&: The function \fIgarbage_collect/2\fR\& returns the value \fIasync\fR\& immediately after the request has been sent\&. When the request has been processed, the process that called this function is passed a message on the form \fI{garbage_collect, RequestId, GCResult}\fR\&\&. .TP 2 .B \fI{type, \&'major\&' | \&'minor\&'}\fR\&: Triggers garbage collection of requested type\&. Default value is \fI\&'major\&'\fR\&, which would trigger a fullsweep GC\&. The option \fI\&'minor\&'\fR\& is considered a hint and may lead to either minor or major GC run\&. .RE .LP If \fIPid\fR\& equals \fIself()\fR\&, and no \fIasync\fR\& option has been passed, the garbage collection is performed at once, that is, the same as calling \fIgarbage_collect/0\fR\&\&. Otherwise a request for garbage collection is sent to the process identified by \fIPid\fR\&, and will be handled when appropriate\&. If no \fIasync\fR\& option has been passed, the caller blocks until \fIGCResult\fR\& is available and can be returned\&. .LP \fIGCResult\fR\& informs about the result of the garbage collection request as follows: .RS 2 .TP 2 .B \fItrue\fR\&: The process identified by \fIPid\fR\& has been garbage collected\&. .TP 2 .B \fIfalse\fR\&: No garbage collection was performed, as the process identified by \fIPid\fR\& terminated before the request could be satisfied\&. .RE .LP Notice that the same caveats apply as for \fIgarbage_collect/0\fR\&\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIPid\fR\& is not a node local process identifier\&. .TP 2 .B \fIbadarg\fR\&: If \fIOptionList\fR\& is an invalid list of options\&. .RE .RE .LP .nf .B get() -> [{Key, Val}] .br .fi .br .RS .LP Types: .RS 3 Key = Val = term() .br .RE .RE .RS .LP Returns the process dictionary as a list of \fI{Key, Val}\fR\& tuples\&. The items in the returned list can be in any order\&. Example: .LP .nf > put(key1, merry), put(key2, lambs), put(key3, {are, playing}), get()\&. [{key1,merry},{key2,lambs},{key3,{are,playing}}] .fi .RE .LP .nf .B get(Key) -> Val | undefined .br .fi .br .RS .LP Types: .RS 3 Key = Val = term() .br .RE .RE .RS .LP Returns the value \fIVal\fR\& associated with \fIKey\fR\& in the process dictionary, or \fIundefined\fR\& if \fIKey\fR\& does not exist\&. The expected time complexity for the current implementation of this function is O(\fI1\fR\&) and the worst case time complexity is O(\fIN\fR\&), where \fIN\fR\& is the number of items in the process dictionary\&. Example: .LP .nf > put(key1, merry), put(key2, lambs), put({any, [valid, term]}, {are, playing}), get({any, [valid, term]})\&. {are,playing} .fi .RE .LP .nf .B erlang:get_cookie() -> Cookie | nocookie .br .fi .br .RS .LP Types: .RS 3 Cookie = atom() .br .RE .RE .RS .LP Returns the magic cookie of the local node if the node is alive, otherwise the atom \fInocookie\fR\&\&. This value is set by \fIset_cookie/1\fR\&\&. .RE .LP .nf .B erlang:get_cookie(Node) -> Cookie | nocookie .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Cookie = atom() .br .RE .RE .RS .LP Returns the magic cookie for node \fINode\fR\& if the local node is alive, otherwise the atom \fInocookie\fR\&\&. This value is set by \fIset_cookie/2\fR\&\&. .RE .LP .nf .B get_keys() -> [Key] .br .fi .br .RS .LP Types: .RS 3 Key = term() .br .RE .RE .RS .LP Returns a list of all keys present in the process dictionary\&. The items in the returned list can be in any order\&. Example: .LP .nf > put(dog, {animal,1}), put(cow, {animal,2}), put(lamb, {animal,3}), get_keys()\&. [dog,cow,lamb] .fi .RE .LP .nf .B get_keys(Val) -> [Key] .br .fi .br .RS .LP Types: .RS 3 Val = Key = term() .br .RE .RE .RS .LP Returns a list of keys that are associated with the value \fIVal\fR\& in the process dictionary\&. The items in the returned list can be in any order\&. Example: .LP .nf > put(mary, {1, 2}), put(had, {1, 2}), put(a, {1, 2}), put(little, {1, 2}), put(dog, {1, 3}), put(lamb, {1, 2}), get_keys({1, 2})\&. [mary,had,a,little,lamb] .fi .RE .LP .nf .B group_leader() -> pid() .br .fi .br .RS .LP Returns the process identifier of the group leader for the process evaluating the function\&. .LP Every process is a member of some process group and all groups have a \fIgroup leader\fR\&\&. All I/O from the group is channeled to the group leader\&. When a new process is spawned, it gets the same group leader as the spawning process\&. Initially, at system startup, \fIinit\fR\& is both its own group leader and the group leader of all processes\&. .RE .LP .nf .B group_leader(GroupLeader, Pid) -> true .br .fi .br .RS .LP Types: .RS 3 GroupLeader = Pid = pid() .br .RE .RE .RS .LP Sets the group leader of \fIPid\fR\& to \fIGroupLeader\fR\&\&. Typically, this is used when a process started from a certain shell is to have another group leader than \fIinit\fR\&\&. .LP The group leader should be rarely changed in applications with a supervision tree, because OTP assumes the group leader of their processes is their application master\&. .LP Setting the group leader follows the signal ordering guarantees described in the Processes Chapter in the \fIErlang Reference Manual\fR\& \&. .LP See also \fIgroup_leader/0\fR\& and OTP design principles related to starting and stopping applications\&. .RE .LP .nf .B halt() -> no_return() .br .fi .br .RS .LP The same as \fIhalt(0, [])\fR\&\&. Example: .LP .nf > halt()\&. os_prompt% .fi .RE .LP .nf .B halt(Status) -> no_return() .br .fi .br .RS .LP Types: .RS 3 Status = integer() >= 0 | abort | string() .br .RE .RE .RS .LP The same as \fIhalt(Status, [])\fR\&\&. Example: .LP .nf > halt(17)\&. os_prompt% echo $? 17 os_prompt% .fi .RE .LP .nf .B halt(Status, Options) -> no_return() .br .fi .br .RS .LP Types: .RS 3 Status = integer() >= 0 | abort | string() .br Options = [Option] .br Option = {flush, boolean()} .br .RE .RE .RS .LP \fIStatus\fR\& must be a non-negative integer, a string, or the atom \fIabort\fR\&\&. Halts the Erlang runtime system\&. Has no return value\&. Depending on \fIStatus\fR\&, the following occurs: .RS 2 .TP 2 .B integer(): The runtime system exits with integer value \fIStatus\fR\& as status code to the calling environment (OS)\&. .LP .RS -4 .B Note: .RE On many platforms, the OS supports only status codes 0-255\&. A too large status code is truncated by clearing the high bits\&. .TP 2 .B string(): An Erlang crash dump is produced with \fIStatus\fR\& as slogan\&. Then the runtime system exits with status code \fI1\fR\&\&. The string will be truncated if longer than 200 characters\&. .LP .RS -4 .B Note: .RE Before ERTS 9\&.1 (OTP-20\&.1) only code points in the range 0-255 was accepted in the string\&. Now any unicode string is valid\&. .TP 2 .B \fIabort\fR\&: The runtime system aborts producing a core dump, if that is enabled in the OS\&. .RE .LP For integer \fIStatus\fR\&, the Erlang runtime system closes all ports and allows async threads to finish their operations before exiting\&. To exit without such flushing, use \fIOption\fR\& as \fI{flush,false}\fR\&\&. .LP For statuses \fIstring()\fR\& and \fIabort\fR\&, option \fIflush\fR\& is ignored and flushing is \fInot\fR\& done\&. .RE .LP .nf .B hd(List) -> term() .br .fi .br .RS .LP Types: .RS 3 List = [term(), \&.\&.\&.] .br .RE .RE .RS .LP Returns the head of \fIList\fR\&, that is, the first element, for example: .LP .nf > hd([1,2,3,4,5])\&. 1 .fi .LP Allowed in guard tests\&. .LP Failure: \fIbadarg\fR\& if \fIList\fR\& is the empty list \fI[]\fR\&\&. .RE .LP .nf .B erlang:hibernate(Module, Function, Args) -> no_return() .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Puts the calling process into a wait state where its memory allocation has been reduced as much as possible\&. This is useful if the process does not expect to receive any messages soon\&. .LP The process is awaken when a message is sent to it, and control resumes in \fIModule:Function\fR\& with the arguments specified by \fIArgs\fR\& with the call stack emptied, meaning that the process terminates when that function returns\&. Thus \fIerlang:hibernate/3\fR\& never returns to its caller\&. The resume function \fIModule:Function/Arity\fR\& must be exported (\fIArity\fR\& =:= \fIlength(Args)\fR\&)\&. .LP If the process has any message in its message queue, the process is awakened immediately in the same way as described earlier\&. .LP In more technical terms, \fIerlang:hibernate/3\fR\& discards the call stack for the process, and then garbage collects the process\&. After this, all live data is in one continuous heap\&. The heap is then shrunken to the exact same size as the live data that it holds (even if that size is less than the minimum heap size for the process)\&. .LP If the size of the live data in the process is less than the minimum heap size, the first garbage collection occurring after the process is awakened ensures that the heap size is changed to a size not smaller than the minimum heap size\&. .LP Notice that emptying the call stack means that any surrounding \fIcatch\fR\& is removed and must be re-inserted after hibernation\&. One effect of this is that processes started using \fIproc_lib\fR\& (also indirectly, such as \fIgen_server\fR\& processes), are to use \fIproc_lib:hibernate/3\fR\& instead, to ensure that the exception handler continues to work when the process wakes up\&. .RE .LP .nf .B erlang:insert_element(Index, Tuple1, Term) -> Tuple2 .br .fi .br .RS .LP Types: .RS 3 Index = integer() >= 1 .br .RS 2 1\&.\&.tuple_size(Tuple1) + 1 .RE Tuple1 = Tuple2 = tuple() .br Term = term() .br .RE .RE .RS .LP Returns a new tuple with element \fITerm\fR\& inserted at position \fIIndex\fR\& in tuple \fITuple1\fR\&\&. All elements from position \fIIndex\fR\& and upwards are pushed one step higher in the new tuple \fITuple2\fR\&\&. Example: .LP .nf > erlang:insert_element(2, {one, two, three}, new)\&. {one,new,two,three} .fi .RE .LP .nf .B integer_to_binary(Integer) -> binary() .br .fi .br .RS .LP Types: .RS 3 Integer = integer() .br .RE .RE .RS .LP Returns a binary corresponding to the text representation of \fIInteger\fR\&, for example: .LP .nf > integer_to_binary(77)\&. <<"77">> .fi .RE .LP .nf .B integer_to_binary(Integer, Base) -> binary() .br .fi .br .RS .LP Types: .RS 3 Integer = integer() .br Base = 2\&.\&.36 .br .RE .RE .RS .LP Returns a binary corresponding to the text representation of \fIInteger\fR\& in base \fIBase\fR\&, for example: .LP .nf > integer_to_binary(1023, 16)\&. <<"3FF">> .fi .RE .LP .nf .B integer_to_list(Integer) -> string() .br .fi .br .RS .LP Types: .RS 3 Integer = integer() .br .RE .RE .RS .LP Returns a string corresponding to the text representation of \fIInteger\fR\&, for example: .LP .nf > integer_to_list(77)\&. "77" .fi .RE .LP .nf .B integer_to_list(Integer, Base) -> string() .br .fi .br .RS .LP Types: .RS 3 Integer = integer() .br Base = 2\&.\&.36 .br .RE .RE .RS .LP Returns a string corresponding to the text representation of \fIInteger\fR\& in base \fIBase\fR\&, for example: .LP .nf > integer_to_list(1023, 16)\&. "3FF" .fi .RE .LP .nf .B iolist_size(Item) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Item = iolist() | binary() .br .RE .RE .RS .LP Returns an integer, that is the size in bytes, of the binary that would be the result of \fIiolist_to_binary(Item)\fR\&, for example: .LP .nf > iolist_size([1,2|<<3,4>>])\&. 4 .fi .RE .LP .nf .B iolist_to_binary(IoListOrBinary) -> binary() .br .fi .br .RS .LP Types: .RS 3 IoListOrBinary = iolist() | binary() .br .RE .RE .RS .LP Returns a binary that is made from the integers and binaries in \fIIoListOrBinary\fR\&, for example: .LP .nf > Bin1 = <<1,2,3>>\&. <<1,2,3>> > Bin2 = <<4,5>>\&. <<4,5>> > Bin3 = <<6>>\&. <<6>> > iolist_to_binary([Bin1,1,[2,3,Bin2],4|Bin3])\&. <<1,2,3,1,2,3,4,5,4,6>> .fi .RE .LP .nf .B erlang:iolist_to_iovec(IoListOrBinary) -> iovec() .br .fi .br .RS .LP Types: .RS 3 IoListOrBinary = iolist() | binary() .br .RE .RE .RS .LP Returns an iovec that is made from the integers and binaries in \fIIoListOrBinary\fR\&\&. This function is useful when you want to flatten an iolist but you do not need a single binary\&. This can be useful for passing the data to nif functions such as \fIenif_inspect_iovec\fR\& or do more efficient message passing\&. The advantage of using this function over \fIiolist_to_binary/1\fR\& is that it does not have to copy off-heap binaries\&. Example: .LP .nf > Bin1 = <<1,2,3>>\&. <<1,2,3>> > Bin2 = <<4,5>>\&. <<4,5>> > Bin3 = <<6>>\&. <<6>> %% If you pass small binaries and integers it works as iolist_to_binary > erlang:iolist_to_iovec([Bin1,1,[2,3,Bin2],4|Bin3])\&. [<<1,2,3,1,2,3,4,5,4,6>>] %% If you pass larger binaries, they are split and returned in a form %% optimized for calling the C function writev. > erlang:iolist_to_iovec([<<1>>,<<2:8096>>,<<3:8096>>])\&. [<<1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,...>>, <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, ...>>, <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...>>] .fi .RE .LP .nf .B is_alive() -> boolean() .br .fi .br .RS .LP Returns \fItrue\fR\& if the local node is alive (that is, if the node can be part of a distributed system), otherwise \fIfalse\fR\&\&. A node is alive if it is started with: .RS 2 .TP 2 * \fI"erl -name LONGNAME"\fR\& or, .LP .TP 2 * \fI"erl -sname SHORTNAME"\fR\&\&. .LP .RE .LP A node can also be alive if it has got a name from a call to \fInet_kernel:start/1\fR\& and has not been stopped by a call to \fInet_kernel:stop/0\fR\&\&. .RE .LP .nf .B is_atom(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is an atom, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_binary(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a binary, otherwise \fIfalse\fR\&\&. .LP A binary always contains a complete number of bytes\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_bitstring(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a bitstring (including a binary), otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_boolean(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is the atom \fItrue\fR\& or the atom \fIfalse\fR\& (that is, a boolean)\&. Otherwise returns \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B erlang:is_builtin(Module, Function, Arity) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Arity = arity() .br .RE .RE .RS .LP This BIF is useful for builders of cross-reference tools\&. .LP Returns \fItrue\fR\& if \fIModule:Function/Arity\fR\& is a BIF implemented in C, otherwise \fIfalse\fR\&\&. .RE .LP .nf .B is_float(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a floating point number, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_function(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a fun, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_function(Term, Arity) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br Arity = arity() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a fun that can be applied with \fIArity\fR\& number of arguments, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_integer(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is an integer, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_list(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a list with zero or more elements, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_map(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a map, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_map_key(Key, Map) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Key = term() .br Map = map() .br .RE .RE .RS .LP Returns \fItrue\fR\& if map \fIMap\fR\& contains \fIKey\fR\& and returns \fIfalse\fR\& if it does not contain the \fIKey\fR\&\&. .LP The call fails with a \fI{badmap,Map}\fR\& exception if \fIMap\fR\& is not a map\&. .LP \fIExample:\fR\& .LP .nf > Map = #{"42" => value}. #{"42" => value} > is_map_key("42",Map). true > is_map_key(value,Map). false .fi .LP Allowed in guard tests\&. .RE .LP .nf .B is_number(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is an integer or a floating point number\&. Otherwise returns \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_pid(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a process identifier, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_port(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a port identifier, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_process_alive(Pid) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br .RE .RE .RS .LP \fIPid\fR\& must refer to a process at the local node\&. .LP Returns \fItrue\fR\& if the process exists and is alive, that is, is not exiting and has not exited\&. Otherwise returns \fIfalse\fR\&\&. .LP If process \fIP1\fR\& calls \fIis_process_alive(P2Pid)\fR\& it is guaranteed that all signals, sent from \fIP1\fR\& to \fIP2\fR\& (\fIP2\fR\& is the process with identifier \fIP2Pid\fR\&) before the call, will be delivered to \fIP2\fR\& before the aliveness of \fIP2\fR\& is checked\&. This guarantee means that one can use \fIis_process_alive/1\fR\& to let a process \fIP1\fR\& wait until a process \fIP2\fR\&, which has got an exit signal with reason \fIkill\fR\& from P1, is killed\&. Example: .LP .nf exit(P2Pid, kill), % P2 might not be killed is_process_alive(P2Pid), % P2 is not alive (the call above always return false) .fi .LP See the documentation about signals and erlang:exit/2 for more information about signals and exit signals\&. .RE .LP .nf .B is_record(Term, RecordTag) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br RecordTag = atom() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a tuple and its first element is \fIRecordTag\fR\&\&. Otherwise returns \fIfalse\fR\&\&. .LP .RS -4 .B Note: .RE Normally the compiler treats calls to \fIis_record/2\fR\& especially\&. It emits code to verify that \fITerm\fR\& is a tuple, that its first element is \fIRecordTag\fR\&, and that the size is correct\&. However, if \fIRecordTag\fR\& is not a literal atom, the BIF \fIis_record/2\fR\& is called instead and the size of the tuple is not verified\&. .LP Allowed in guard tests, if \fIRecordTag\fR\& is a literal atom\&. .RE .LP .nf .B is_record(Term, RecordTag, Size) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br RecordTag = atom() .br Size = integer() >= 0 .br .RE .RE .RS .LP \fIRecordTag\fR\& must be an atom\&. .LP Returns \fItrue\fR\& if \fITerm\fR\& is a tuple, its first element is \fIRecordTag\fR\&, and its size is \fISize\fR\&\&. Otherwise returns \fIfalse\fR\&\&. .LP Allowed in guard tests if \fIRecordTag\fR\& is a literal atom and \fISize\fR\& is a literal integer\&. .LP .RS -4 .B Note: .RE This BIF is documented for completeness\&. Usually \fIis_record/2\fR\& is to be used\&. .RE .LP .nf .B is_reference(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a reference, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B is_tuple(Term) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns \fItrue\fR\& if \fITerm\fR\& is a tuple, otherwise \fIfalse\fR\&\&. .LP Allowed in guard tests\&. .RE .LP .nf .B length(List) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 List = [term()] .br .RE .RE .RS .LP Returns the length of \fIList\fR\&, for example: .LP .nf > length([1,2,3,4,5,6,7,8,9])\&. 9 .fi .LP Allowed in guard tests\&. .RE .LP .nf .B link(PidOrPort) -> true .br .fi .br .RS .LP Types: .RS 3 PidOrPort = pid() | port() .br .RE .RE .RS .LP Sets up and activates a link between the calling process and another process or a port identified by \fIPidOrPort\fR\&\&. We will from here on call the identified process or port linkee\&. If the linkee is a port, it must reside on the same node as the caller\&. .LP If one of the participants of a link terminates, it will send an exit signal to the other participant\&. The exit signal will contain the exit reason of the terminated participant\&. Other cases when exit signals are triggered due to a link are when no linkee exist (\fInoproc\fR\& exit reason) and when the connection between linked processes on different nodes is lost or cannot be established (\fInoconnection\fR\& exit reason)\&. .LP An existing link can be removed by calling \fIunlink/1\fR\&\&. For more information on links and exit signals due to links, see the \fIProcesses\fR\& chapter in the \fIErlang Reference Manual\fR\& : .RS 2 .TP 2 * Links .LP .TP 2 * Sending Exit Signals .LP .TP 2 * Receiving Exit Signals .LP .RE .LP For historical reasons, \fIlink/1\fR\& has a strange semi-synchronous behavior when it is "cheap" to check if the linkee exists or not, and the caller does not trap exits\&. If the above is true and the linkee does not exist, \fIlink/1\fR\& will raise a \fInoproc\fR\& error \fIexception\fR\&\&. The expected behavior would instead have been that \fIlink/1\fR\& returned \fItrue\fR\&, and the caller later was sent an exit signal with \fInoproc\fR\& exit reason, but this is unfortunately not the case\&. The \fInoproc\fR\& exception is not to be confused with an exit signal with exit reason \fInoproc\fR\&\&. Currently it is "cheap" to check if the linkee exists when it is supposed to reside on the same node as the calling process\&. .LP The link setup and activation is performed asynchronously\&. If the link already exists, or if the caller attempts to create a link to itself, nothing is done\&. A detailed description of the link protocol can be found in the \fIDistribution Protocol\fR\& chapter of the \fIERTS User\&'s Guide\fR\& \&. .LP Failure: .RS 2 .TP 2 * \fIbadarg\fR\& if \fIPidOrPort\fR\& does not identify a process or a node local port\&. .LP .TP 2 * \fInoproc\fR\& linkee does not exist and it is "cheap" to check if it exists as described above\&. .LP .RE .RE .LP .nf .B list_to_atom(String) -> atom() .br .fi .br .RS .LP Types: .RS 3 String = string() .br .RE .RE .RS .LP Returns the atom whose text representation is \fIString\fR\&\&. .LP As from Erlang/OTP 20, \fIString\fR\& may contain any Unicode character\&. Earlier versions allowed only ISO-latin-1 characters as the implementation did not allow Unicode characters above 255\&. .LP .RS -4 .B Note: .RE The number of characters that are permitted in an atom name is limited\&. The default limits can be found in the efficiency guide (section Advanced)\&. .LP .RS -4 .B Note: .RE There is configurable limit on how many atoms that can exist and atoms are not garbage collected\&. Therefore, it is recommended to consider if \fIlist_to_existing_atom/1\fR\& is a better option than \fIlist_to_atom/1\fR\&\&. The default limits can be found in the efficiency guide (section Advanced)\&. .LP Example: .LP .nf > list_to_atom("Erlang")\&. \&'Erlang' .fi .RE .LP .nf .B list_to_binary(IoList) -> binary() .br .fi .br .RS .LP Types: .RS 3 IoList = iolist() .br .RE .RE .RS .LP Returns a binary that is made from the integers and binaries in \fIIoList\fR\&, for example: .LP .nf > Bin1 = <<1,2,3>>\&. <<1,2,3>> > Bin2 = <<4,5>>\&. <<4,5>> > Bin3 = <<6>>\&. <<6>> > list_to_binary([Bin1,1,[2,3,Bin2],4|Bin3])\&. <<1,2,3,1,2,3,4,5,4,6>> .fi .RE .LP .nf .B list_to_bitstring(BitstringList) -> bitstring() .br .fi .br .RS .LP Types: .RS 3 BitstringList = bitstring_list() .br .nf \fBbitstring_list()\fR\& = .br maybe_improper_list(byte() | bitstring() | bitstring_list(), .br bitstring() | []) .fi .br .RE .RE .RS .LP Returns a bitstring that is made from the integers and bitstrings in \fIBitstringList\fR\&\&. (The last tail in \fIBitstringList\fR\& is allowed to be a bitstring\&.) Example: .LP .nf > Bin1 = <<1,2,3>>\&. <<1,2,3>> > Bin2 = <<4,5>>\&. <<4,5>> > Bin3 = <<6,7:4>>\&. <<6,7:4>> > list_to_bitstring([Bin1,1,[2,3,Bin2],4|Bin3])\&. <<1,2,3,1,2,3,4,5,4,6,7:4>> .fi .RE .LP .nf .B list_to_existing_atom(String) -> atom() .br .fi .br .RS .LP Types: .RS 3 String = string() .br .RE .RE .RS .LP Returns the atom whose text representation is \fIString\fR\&, but only if there already exists such atom\&. An atom exists if it has been created by the run-time system by either loading code or creating a term in which the atom is part\&. .LP Failure: \fIbadarg\fR\& if there does not already exist an atom whose text representation is \fIString\fR\&\&. .LP .RS -4 .B Note: .RE Note that the compiler may optimize away atoms\&. For example, the compiler will rewrite \fIatom_to_list(some_atom)\fR\& to \fI"some_atom"\fR\&\&. If that expression is the only mention of the atom \fIsome_atom\fR\& in the containing module, the atom will not be created when the module is loaded, and a subsequent call to \fIlist_to_existing_atom("some_atom")\fR\& will fail\&. .RE .LP .nf .B list_to_float(String) -> float() .br .fi .br .RS .LP Types: .RS 3 String = string() .br .RE .RE .RS .LP Returns the float whose text representation is \fIString\fR\&, for example: .LP .nf > list_to_float("2\&.2017764e+0")\&. 2.2017764 .fi .LP The float string format is the same as the format for Erlang float literals except for that underscores are not permitted\&. .LP Failure: \fIbadarg\fR\& if \fIString\fR\& contains a bad representation of a float\&. .RE .LP .nf .B list_to_integer(String) -> integer() .br .fi .br .RS .LP Types: .RS 3 String = string() .br .RE .RE .RS .LP Returns an integer whose text representation is \fIString\fR\&, for example: .LP .nf > list_to_integer("123")\&. 123 .fi .LP .nf > list_to_integer("-123")\&. -123 .fi .LP .nf > list_to_integer("+123234982304982309482093833234234")\&. 123234982304982309482093833234234 .fi .LP \fIString\fR\& must contain at least one digit character and can have an optional prefix consisting of a single "\fI+\fR\&" or "\fI-\fR\&" character (that is, \fIString\fR\& must match the regular expression \fI"^[+-]?[0-9]+$"\fR\&)\&. .LP Failure: \fIbadarg\fR\& if \fIString\fR\& contains a bad representation of an integer\&. .RE .LP .nf .B list_to_integer(String, Base) -> integer() .br .fi .br .RS .LP Types: .RS 3 String = string() .br Base = 2\&.\&.36 .br .RE .RE .RS .LP Returns an integer whose text representation in base \fIBase\fR\& is \fIString\fR\&, for example: .LP .nf > list_to_integer("3FF", 16)\&. 1023 .fi .LP .nf > list_to_integer("+3FF", 16)\&. 1023 .fi .LP .nf > list_to_integer("3ff", 16)\&. 1023 .fi .LP .nf > list_to_integer("3fF", 16)\&. 1023 .fi .LP .nf > list_to_integer("-3FF", 16)\&. -1023 .fi .LP For example, when \fIBase\fR\& is 16, \fIString\fR\& must match the regular expression \fI"^[+-]?([0-9]|[A-F]|[a-f])+$"\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIString\fR\& contains a bad representation of an integer\&. .RE .LP .nf .B list_to_pid(String) -> pid() .br .fi .br .RS .LP Types: .RS 3 String = string() .br .RE .RE .RS .LP Returns a process identifier whose text representation is a \fIString\fR\&, for example: .LP .nf > list_to_pid("<0\&.4\&.1>")\&. <0.4.1> .fi .LP Failure: \fIbadarg\fR\& if \fIString\fR\& contains a bad representation of a process identifier\&. .LP .RS -4 .B Warning: .RE This BIF is intended for debugging and is not to be used in application programs\&. .RE .LP .nf .B list_to_port(String) -> port() .br .fi .br .RS .LP Types: .RS 3 String = string() .br .RE .RE .RS .LP Returns a port identifier whose text representation is a \fIString\fR\&, for example: .LP .nf > list_to_port("#Port<0\&.4>")\&. #Port<0.4> .fi .LP Failure: \fIbadarg\fR\& if \fIString\fR\& contains a bad representation of a port identifier\&. .LP .RS -4 .B Warning: .RE This BIF is intended for debugging and is not to be used in application programs\&. .RE .LP .nf .B list_to_ref(String) -> reference() .br .fi .br .RS .LP Types: .RS 3 String = string() .br .RE .RE .RS .LP Returns a reference whose text representation is a \fIString\fR\&, for example: .LP .nf > list_to_ref("#Ref<0\&.4192537678\&.4073193475\&.71181>")\&. #Ref<0.4192537678.4073193475.71181> .fi .LP Failure: \fIbadarg\fR\& if \fIString\fR\& contains a bad representation of a reference\&. .LP .RS -4 .B Warning: .RE This BIF is intended for debugging and is not to be used in application programs\&. .RE .LP .nf .B list_to_tuple(List) -> tuple() .br .fi .br .RS .LP Types: .RS 3 List = [term()] .br .RE .RE .RS .LP Returns a tuple corresponding to \fIList\fR\&, for example .LP .nf > list_to_tuple([share, [\&'Ericsson_B\&', 163]])\&. {share, ['Ericsson_B', 163]} .fi .LP \fIList\fR\& can contain any Erlang terms\&. .RE .LP .nf .B load_module(Module, Binary) -> {module, Module} | {error, Reason} .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Binary = binary() .br Reason = .br badfile | not_purged | on_load | .br {features_not_allowed, [atom()]} .br .RE .RE .RS .LP If \fIBinary\fR\& contains the object code for module \fIModule\fR\&, this BIF loads that object code\&. If the code for module \fIModule\fR\& already exists, all export references are replaced so they point to the newly loaded code\&. The previously loaded code is kept in the system as old code, as there can still be processes executing that code\&. .LP Returns either \fI{module, Module}\fR\&, or \fI{error, Reason}\fR\& if loading fails\&. \fIReason\fR\& is one of the following: .RS 2 .TP 2 .B \fIbadfile\fR\&: The object code in \fIBinary\fR\& has an incorrect format \fIor\fR\& the object code contains code for another module than \fIModule\fR\&\&. .TP 2 .B \fInot_purged\fR\&: \fIBinary\fR\& contains a module that cannot be loaded because old code for this module already exists\&. .TP 2 .B \fIon_load\fR\&: The code in \fIBinary\fR\& contains an \fIon_load\fR\& declaration that must be executed before \fIBinary\fR\& can become the current code\&. Any previous current code for \fIModule\fR\& will remain until the \fIon_load\fR\& call has finished\&. .TP 2 .B not_allowed: The code in \fIBinary\fR\& has been compiled with features that are currently not enabled in the runtime system\&. .RE .LP .RS -4 .B Warning: .RE This BIF is intended for the code server (see \fIcode(3erl)\fR\&) and is not to be used elsewhere\&. .RE .LP .nf .B erlang:load_nif(Path, LoadInfo) -> ok | Error .br .fi .br .RS .LP Types: .RS 3 Path = string() .br LoadInfo = term() .br Error = {error, {Reason, Text :: string()}} .br Reason = .br load_failed | bad_lib | load | reload | upgrade | old_code .br .RE .RE .RS .LP Loads and links a dynamic library containing native implemented functions (NIFs) for a module\&. \fIPath\fR\& is a file path to the shareable object/dynamic library file minus the OS-dependent file extension (\fI\&.so\fR\& for Unix and \fI\&.dll\fR\& for Windows)\&. Notice that on most OSs the library has to have a different name on disc when an upgrade of the nif is done\&. If the name is the same, but the contents differ, the old library may be loaded instead\&. For information on how to implement a NIF library, see \fIerl_nif(3erl)\fR\&\&. .LP \fILoadInfo\fR\& can be any term\&. It is passed on to the library as part of the initialization\&. A good practice is to include a module version number to support future code upgrade scenarios\&. .LP The call to \fIload_nif/2\fR\& must be made \fIdirectly\fR\& from the Erlang code of the module that the NIF library belongs to\&. It returns either \fIok\fR\&, or \fI{error,{Reason,Text}}\fR\& if loading fails\&. \fIReason\fR\& is one of the following atoms while \fIText\fR\& is a human readable string that can give more information about the failure: .RS 2 .TP 2 .B \fIload_failed\fR\&: The OS failed to load the NIF library\&. .TP 2 .B \fIbad_lib\fR\&: The library did not fulfill the requirements as a NIF library of the calling module\&. .TP 2 .B \fIload | upgrade\fR\&: The corresponding library callback was unsuccessful\&. .TP 2 .B \fIreload\fR\&: A NIF library is already loaded for this module instance\&. The previously deprecated \fIreload\fR\& feature was removed in OTP 20\&. .TP 2 .B \fIold_code\fR\&: The call to \fIload_nif/2\fR\& was made from the old code of a module that has been upgraded; this is not allowed\&. .RE .LP If the \fI-nifs()\fR\& attribute is used (which is recommended), all NIFs in the dynamic library much be declared as such for \fIload_nif/2\fR\& to succeed\&. On the other hand, all functions declared with the \fI-nifs()\fR\& attribute do not have to be implemented by the dynamic library\&. This allows a target independent Erlang file to contain fallback implementations for functions that may lack NIF support depending on target OS/hardware platform\&. .RE .LP .nf .B erlang:loaded() -> [Module] .br .fi .br .RS .LP Types: .RS 3 Module = module() .br .RE .RE .RS .LP Returns a list of all loaded Erlang modules (current and old code), including preloaded modules\&. .LP See also \fIcode(3erl)\fR\&\&. .RE .LP .nf .B erlang:localtime() -> DateTime .br .fi .br .RS .LP Types: .RS 3 DateTime = calendar:datetime() .br .RE .RE .RS .LP Returns the current local date and time, \fI{{Year, Month, Day}, {Hour, Minute, Second}}\fR\&, for example: .LP .nf > erlang:localtime()\&. {{1996,11,6},{14,45,17}} .fi .LP The time zone and Daylight Saving Time correction depend on the underlying OS\&. The return value is based on the OS System Time\&. .RE .LP .nf .B erlang:localtime_to_universaltime(Localtime) -> Universaltime .br .fi .br .RS .LP Types: .RS 3 Localtime = Universaltime = calendar:datetime() .br .RE .RE .RS .LP Converts local date and time to Universal Time Coordinated (UTC), if supported by the underlying OS\&. Otherwise no conversion is done and \fILocaltime\fR\& is returned\&. Example: .LP .nf > erlang:localtime_to_universaltime({{1996,11,6},{14,45,17}})\&. {{1996,11,6},{13,45,17}} .fi .LP Failure: \fIbadarg\fR\& if \fILocaltime\fR\& denotes an invalid date and time\&. .RE .LP .nf .B erlang:localtime_to_universaltime(Localtime, IsDst) -> .B Universaltime .br .fi .br .RS .LP Types: .RS 3 Localtime = Universaltime = calendar:datetime() .br IsDst = true | false | undefined .br .RE .RE .RS .LP Converts local date and time to Universal Time Coordinated (UTC) as \fIerlang:localtime_to_universaltime/1\fR\&, but the caller decides if Daylight Saving Time is active\&. .LP If \fIIsDst == true\fR\&, \fILocaltime\fR\& is during Daylight Saving Time, if \fIIsDst == false\fR\& it is not\&. If \fIIsDst == undefined\fR\&, the underlying OS can guess, which is the same as calling \fIerlang:localtime_to_universaltime(Localtime)\fR\&\&. .LP Examples: .LP .nf > erlang:localtime_to_universaltime({{1996,11,6},{14,45,17}}, true)\&. {{1996,11,6},{12,45,17}} > erlang:localtime_to_universaltime({{1996,11,6},{14,45,17}}, false)\&. {{1996,11,6},{13,45,17}} > erlang:localtime_to_universaltime({{1996,11,6},{14,45,17}}, undefined)\&. {{1996,11,6},{13,45,17}} .fi .LP Failure: \fIbadarg\fR\& if \fILocaltime\fR\& denotes an invalid date and time\&. .RE .LP .nf .B make_ref() -> reference() .br .fi .br .RS .LP Returns a unique reference\&. The reference is unique among connected nodes\&. .LP .RS -4 .B Warning: .RE Before OTP-23 when a node is restarted multiple times with the same node name, references created on a newer node can be mistaken for a reference created on an older node with the same node name\&. .RE .LP .nf .B erlang:make_tuple(Arity, InitialValue) -> tuple() .br .fi .br .RS .LP Types: .RS 3 Arity = arity() .br InitialValue = term() .br .RE .RE .RS .LP Creates a new tuple of the specified \fIArity\fR\&, where all elements are \fIInitialValue\fR\&, for example: .LP .nf > erlang:make_tuple(4, [])\&. {[],[],[],[]} .fi .RE .LP .nf .B erlang:make_tuple(Arity, DefaultValue, InitList) -> tuple() .br .fi .br .RS .LP Types: .RS 3 Arity = arity() .br DefaultValue = term() .br InitList = [{Position :: integer() >= 1, term()}] .br .RE .RE .RS .LP Creates a tuple of size \fIArity\fR\&, where each element has value \fIDefaultValue\fR\&, and then fills in values from \fIInitList\fR\&\&. Each list element in \fIInitList\fR\& must be a two-tuple, where the first element is a position in the newly created tuple and the second element is any term\&. If a position occurs more than once in the list, the term corresponding to the last occurrence is used\&. Example: .LP .nf > erlang:make_tuple(5, [], [{2,ignored},{5,zz},{2,aa}])\&. {[],aa,[],[],zz} .fi .RE .LP .nf .B map_get(Key, Map) -> Value .br .fi .br .RS .LP Types: .RS 3 Map = map() .br Key = Value = any() .br .RE .RE .RS .LP Returns value \fIValue\fR\& associated with \fIKey\fR\& if \fIMap\fR\& contains \fIKey\fR\&\&. .LP The call fails with a \fI{badmap,Map}\fR\& exception if \fIMap\fR\& is not a map, or with a \fI{badkey,Key}\fR\& exception if no value is associated with \fIKey\fR\&\&. .LP \fIExample:\fR\& .LP .nf > Key = 1337, Map = #{42 => value_two,1337 => "value one","a" => 1}, map_get(Key,Map). "value one" .fi .LP Allowed in guard tests\&. .RE .LP .nf .B map_size(Map) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Map = map() .br .RE .RE .RS .LP Returns an integer, which is the number of key-value pairs in \fIMap\fR\&, for example: .LP .nf > map_size(#{a=>1, b=>2, c=>3})\&. 3 .fi .LP Allowed in guard tests\&. .RE .LP .nf .B erlang:match_spec_test(MatchAgainst, MatchSpec, Type) -> .B TestResult .br .fi .br .RS .LP Types: .RS 3 MatchAgainst = [term()] | tuple() .br MatchSpec = term() .br Type = table | trace .br TestResult = .br {ok, term(), [return_trace], [{error | warning, string()}]} | .br {error, [{error | warning, string()}]} .br .RE .RE .RS .LP Tests a match specification used in calls to \fIets:select/2\fR\& and \fIerlang:trace_pattern/3\fR\&\&. The function tests both a match specification for "syntactic" correctness and runs the match specification against the object\&. If the match specification contains errors, the tuple \fI{error, Errors}\fR\& is returned, where \fIErrors\fR\& is a list of natural language descriptions of what was wrong with the match specification\&. .LP If \fIType\fR\& is \fItable\fR\&, the object to match against is to be a tuple\&. The function then returns \fI{ok,Result,[],Warnings}\fR\&, where \fIResult\fR\& is what would have been the result in a real \fIets:select/2\fR\& call, or \fIfalse\fR\& if the match specification does not match the object tuple\&. .LP If \fIType\fR\& is \fItrace\fR\&, the object to match against is to be a list\&. The function returns \fI{ok, Result, Flags, Warnings}\fR\&, where \fIResult\fR\& is one of the following: .RS 2 .TP 2 * \fItrue\fR\& if a trace message is to be emitted .LP .TP 2 * \fIfalse\fR\& if a trace message is not to be emitted .LP .TP 2 * The message term to be appended to the trace message .LP .RE .LP \fIFlags\fR\& is a list containing all the trace flags to be enabled, currently this is only \fIreturn_trace\fR\&\&. .LP This is a useful debugging and test tool, especially when writing complicated match specifications\&. .LP See also \fIets:test_ms/2\fR\&\&. .RE .LP .nf .B max(Term1, Term2) -> Maximum .br .fi .br .RS .LP Types: .RS 3 Term1 = Term2 = Maximum = term() .br .RE .RE .RS .LP Returns the largest of \fITerm1\fR\& and \fITerm2\fR\&\&. If the terms compare equal with the \fI==\fR\& operator, \fITerm1\fR\& is returned\&. .LP The Expressions section contains descriptions of the \fI==\fR\& operator and how terms are ordered\&. .LP Examples: .LP .nf > max(1, 2)\&. 2 .fi .LP .nf > max(1\&.0, 1)\&. 1.0 .fi .LP .nf > max(1, 1\&.0)\&. 1 .fi .LP .nf > max("abc", "b")\&. "b" .fi .RE .LP .nf .B erlang:md5(Data) -> Digest .br .fi .br .RS .LP Types: .RS 3 Data = iodata() .br Digest = binary() .br .RE .RE .RS .LP Computes an MD5 message digest from \fIData\fR\&, where the length of the digest is 128 bits (16 bytes)\&. \fIData\fR\& is a binary or a list of small integers and binaries\&. .LP For more information about MD5, see RFC 1321 - The MD5 Message-Digest Algorithm\&. .LP .RS -4 .B Warning: .RE The MD5 Message-Digest Algorithm is \fInot\fR\& considered safe for code-signing or software-integrity purposes\&. .RE .LP .nf .B erlang:md5_final(Context) -> Digest .br .fi .br .RS .LP Types: .RS 3 Context = Digest = binary() .br .RE .RE .RS .LP Finishes the update of an MD5 \fIContext\fR\& and returns the computed \fIMD5\fR\& message digest\&. .RE .LP .nf .B erlang:md5_init() -> Context .br .fi .br .RS .LP Types: .RS 3 Context = binary() .br .RE .RE .RS .LP Creates an MD5 context, to be used in the following calls to \fImd5_update/2\fR\&\&. .RE .LP .nf .B erlang:md5_update(Context, Data) -> NewContext .br .fi .br .RS .LP Types: .RS 3 Context = binary() .br Data = iodata() .br NewContext = binary() .br .RE .RE .RS .LP Update an MD5 \fIContext\fR\& with \fIData\fR\& and returns a \fINewContext\fR\&\&. .RE .LP .nf .B erlang:memory() -> [{Type, Size}] .br .fi .br .RS .LP Types: .RS 3 Type = memory_type() .br Size = integer() >= 0 .br .nf \fBmemory_type()\fR\& = .br total | processes | processes_used | system | atom | .br atom_used | binary | code | ets .fi .br .RE .RE .RS .LP Returns a list with information about memory dynamically allocated by the Erlang emulator\&. Each list element is a tuple \fI{Type, Size}\fR\&\&. The first element \fIType\fR\& is an atom describing memory type\&. The second element \fISize\fR\& is the memory size in bytes\&. .LP Memory types: .RS 2 .TP 2 .B \fItotal\fR\&: The total amount of memory currently allocated\&. This is the same as the sum of the memory size for \fIprocesses\fR\& and \fIsystem\fR\&\&. .TP 2 .B \fIprocesses\fR\&: The total amount of memory currently allocated for the Erlang processes\&. .TP 2 .B \fIprocesses_used\fR\&: The total amount of memory currently used by the Erlang processes\&. This is part of the memory presented as \fIprocesses\fR\& memory\&. .TP 2 .B \fIsystem\fR\&: The total amount of memory currently allocated for the emulator that is not directly related to any Erlang process\&. Memory presented as \fIprocesses\fR\& is not included in this memory\&. \fIinstrument(3erl)\fR\& can be used to get a more detailed breakdown of what memory is part of this type\&. .TP 2 .B \fIatom\fR\&: The total amount of memory currently allocated for atoms\&. This memory is part of the memory presented as \fIsystem\fR\& memory\&. .TP 2 .B \fIatom_used\fR\&: The total amount of memory currently used for atoms\&. This memory is part of the memory presented as \fIatom\fR\& memory\&. .TP 2 .B \fIbinary\fR\&: The total amount of memory currently allocated for binaries\&. This memory is part of the memory presented as \fIsystem\fR\& memory\&. .TP 2 .B \fIcode\fR\&: The total amount of memory currently allocated for Erlang code\&. This memory is part of the memory presented as \fIsystem\fR\& memory\&. .TP 2 .B \fIets\fR\&: The total amount of memory currently allocated for ETS tables\&. This memory is part of the memory presented as \fIsystem\fR\& memory\&. .TP 2 .B \fImaximum\fR\&: The maximum total amount of memory allocated since the emulator was started\&. This tuple is only present when the emulator is run with instrumentation\&. .RS 2 .LP For information on how to run the emulator with instrumentation, see \fIinstrument(3erl)\fR\& and/or \fIerl(1)\fR\&\&. .RE .RE .LP .RS -4 .B Note: .RE The \fIsystem\fR\& value is not complete\&. Some allocated memory that is to be part of this value is not\&. .LP When the emulator is run with instrumentation, the \fIsystem\fR\& value is more accurate, but memory directly allocated for \fImalloc\fR\& (and friends) is still not part of the \fIsystem\fR\& value\&. Direct calls to \fImalloc\fR\& are only done from OS-specific runtime libraries and perhaps from user-implemented Erlang drivers that do not use the memory allocation functions in the driver interface\&. .LP As the \fItotal\fR\& value is the sum of \fIprocesses\fR\& and \fIsystem\fR\&, the error in \fIsystem\fR\& propagates to the \fItotal\fR\& value\&. .LP The different amounts of memory that are summed are \fInot\fR\& gathered atomically, which introduces an error in the result\&. .LP The different values have the following relation to each other\&. Values beginning with an uppercase letter is not part of the result\&. .LP .nf total = processes + system processes = processes_used + ProcessesNotUsed system = atom + binary + code + ets + OtherSystem atom = atom_used + AtomNotUsed RealTotal = processes + RealSystem RealSystem = system + MissedSystem .fi .LP More tuples in the returned list can be added in a future release\&. .LP .RS -4 .B Note: .RE The \fItotal\fR\& value is supposed to be the total amount of memory dynamically allocated by the emulator\&. Shared libraries, the code of the emulator itself, and the emulator stacks are not supposed to be included\&. That is, the \fItotal\fR\& value is \fInot\fR\& supposed to be equal to the total size of all pages mapped to the emulator\&. .LP Also, because of fragmentation and prereservation of memory areas, the size of the memory segments containing the dynamically allocated memory blocks can be much larger than the total size of the dynamically allocated memory blocks\&. .LP .RS -4 .B Note: .RE As from ERTS 5\&.6\&.4, \fIerlang:memory/0\fR\& requires that all \fIerts_alloc(3erl)\fR\& allocators are enabled (default behavior)\&. .LP Failure: \fInotsup\fR\& if an \fIerts_alloc(3erl)\fR\& allocator has been disabled\&. .RE .LP .nf .B erlang:memory(Type :: memory_type()) -> integer() >= 0 .br .fi .br .nf .B erlang:memory(TypeList :: [memory_type()]) -> .B [{memory_type(), integer() >= 0}] .br .fi .br .RS .LP Types: .RS 3 .nf \fBmemory_type()\fR\& = .br total | processes | processes_used | system | atom | .br atom_used | binary | code | ets .fi .br .RE .RE .RS .LP Returns the memory size in bytes allocated for memory of type \fIType\fR\&\&. The argument can also be specified as a list of \fImemory_type()\fR\& atoms, in which case a corresponding list of \fI{memory_type(), Size :: integer >= 0}\fR\& tuples is returned\&. .LP .RS -4 .B Note: .RE As from ERTS 5\&.6\&.4, \fIerlang:memory/1\fR\& requires that all \fIerts_alloc(3erl)\fR\& allocators are enabled (default behavior)\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIType\fR\& is not one of the memory types listed in the description of \fIerlang:memory/0\fR\&\&. .TP 2 .B \fIbadarg\fR\&: If \fImaximum\fR\& is passed as \fIType\fR\& and the emulator is not run in instrumented mode\&. .TP 2 .B \fInotsup\fR\&: If an \fIerts_alloc(3erl)\fR\& allocator has been disabled\&. .RE .LP See also \fIerlang:memory/0\fR\&\&. .RE .LP .nf .B min(Term1, Term2) -> Minimum .br .fi .br .RS .LP Types: .RS 3 Term1 = Term2 = Minimum = term() .br .RE .RE .RS .LP Returns the smallest of \fITerm1\fR\& and \fITerm2\fR\&\&. If the terms compare equal with the \fI==\fR\& operator, \fITerm1\fR\& is returned\&. .LP The Expressions section contains descriptions of the \fI==\fR\& operator and how terms are ordered\&. .LP Examples: .LP .nf > min(1, 2)\&. 1 .fi .LP .nf > min(1\&.0, 1)\&. 1.0 .fi .LP .nf > min(1, 1\&.0)\&. 1 .fi .LP .nf > min("abc", "b")\&. "abc" .fi .RE .LP .nf .B module_loaded(Module) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Module = module() .br .RE .RE .RS .LP Returns \fItrue\fR\& if the module \fIModule\fR\& is loaded as \fIcurrent code\fR\& ; otherwise, \fIfalse\fR\&\&. It does not attempt to load the module\&. .RE .LP .nf .B monitor(Type :: process, Item :: monitor_process_identifier()) -> .B MonitorRef .br .fi .br .nf .B monitor(Type :: port, Item :: monitor_port_identifier()) -> .B MonitorRef .br .fi .br .nf .B monitor(Type :: time_offset, Item :: clock_service) -> MonitorRef .br .fi .br .RS .LP Types: .RS 3 MonitorRef = reference() .br .nf \fBregistered_name()\fR\& = atom() .fi .br .nf \fBregistered_process_identifier()\fR\& = .br registered_name() | {registered_name(), node()} .fi .br .nf \fBmonitor_process_identifier()\fR\& = .br pid() | registered_process_identifier() .fi .br .nf \fBmonitor_port_identifier()\fR\& = port() | registered_name() .fi .br .RE .RE .RS .LP Sends a monitor request of type \fIType\fR\& to the entity identified by \fIItem\fR\&\&. If the monitored entity does not exist or it changes monitored state, the caller of \fImonitor/2\fR\& is notified by a message on the following format: .LP .nf {Tag, MonitorRef, Type, Object, Info} .fi .LP .RS -4 .B Note: .RE The monitor request is an asynchronous signal\&. That is, it takes time before the signal reaches its destination\&. .LP \fIType\fR\& can be one of the following atoms: \fIprocess\fR\&, \fIport\fR\& or \fItime_offset\fR\&\&. .LP A \fIprocess\fR\& or \fIport\fR\& monitor is triggered only once, after that it is removed from both monitoring process and the monitored entity\&. Monitors are fired when the monitored process or port terminates, does not exist at the moment of creation, or if the connection to it is lost\&. If the connection to it is lost, we do not know if it still exists\&. The monitoring is also turned off when demonitor/1 is called\&. .LP A \fIprocess\fR\& or \fIport\fR\& monitor by name resolves the \fIRegisteredName\fR\& to \fIpid()\fR\& or \fIport()\fR\& only once at the moment of monitor instantiation, later changes to the name registration will not affect the existing monitor\&. .LP When a \fIprocess\fR\& or \fIport\fR\& monitor is triggered, a \fI\&'DOWN\&'\fR\& message is sent that has the following pattern: .LP .nf {'DOWN', MonitorRef, Type, Object, Info} .fi .LP In the monitor message \fIMonitorRef\fR\& and \fIType\fR\& are the same as described earlier, and: .RS 2 .TP 2 .B \fIObject\fR\&: The monitored entity, which triggered the event\&. When monitoring a process or a local port, \fIObject\fR\& will be equal to the \fIpid()\fR\& or \fIport()\fR\& that was being monitored\&. When monitoring process or port by name, \fIObject\fR\& will have format \fI{RegisteredName, Node}\fR\& where \fIRegisteredName\fR\& is the name which has been used with \fImonitor/2\fR\& call and \fINode\fR\& is local or remote node name (for ports monitored by name, \fINode\fR\& is always local node name)\&. .TP 2 .B \fIInfo\fR\&: Either the exit reason of the process, \fInoproc\fR\& (process or port did not exist at the time of monitor creation), or \fInoconnection\fR\& (no connection to the node where the monitored process resides)\&. .RE .RS 2 .TP 2 .B Monitoring a \fIprocess\fR\&: Creates monitor between the current process and another process identified by \fIItem\fR\&, which can be a \fIpid()\fR\& (local or remote), an atom \fIRegisteredName\fR\& or a tuple \fI{RegisteredName, Node}\fR\& for a registered process, located elsewhere\&. .LP .RS -4 .B Note: .RE Before ERTS 10\&.0 (OTP 21\&.0), monitoring a process could fail with \fIbadarg\fR\& if the monitored process resided on a primitive node (such as erl_interface or jinterface), where remote process monitoring is not implemented\&. .LP Now, such a call to \fImonitor\fR\& will instead succeed and a monitor is created\&. But the monitor will only supervise the connection\&. That is, a \fI{\&'DOWN\&', _, process, _, noconnection}\fR\& is the only message that may be received, as the primitive node have no way of reporting the status of the monitored process\&. .TP 2 .B Monitoring a \fIport\fR\&: Creates monitor between the current process and a port identified by \fIItem\fR\&, which can be a \fIport()\fR\& (only local), an atom \fIRegisteredName\fR\& or a tuple \fI{RegisteredName, Node}\fR\& for a registered port, located on this node\&. Note, that attempt to monitor a remote port will result in \fIbadarg\fR\&\&. .TP 2 .B Monitoring a \fItime_offset\fR\&: Monitors changes in \fItime offset\fR\& between Erlang monotonic time and Erlang system time\&. One valid \fIItem\fR\& exists in combination with the \fItime_offset Type\fR\&, namely the atom \fIclock_service\fR\&\&. Notice that the atom \fIclock_service\fR\& is \fInot\fR\& the registered name of a process\&. In this case it serves as an identifier of the runtime system internal clock service at current runtime system instance\&. .RS 2 .LP The monitor is triggered when the time offset is changed\&. This either if the time offset value is changed, or if the offset is changed from preliminary to final during finalization of the time offset when the single time warp mode is used\&. When a change from preliminary to final time offset is made, the monitor is triggered once regardless of whether the time offset value was changed or not\&. .RE .RS 2 .LP If the runtime system is in multi time warp mode, the time offset is changed when the runtime system detects that the OS system time has changed\&. The runtime system does, however, not detect this immediately when it occurs\&. A task checking the time offset is scheduled to execute at least once a minute, so under normal operation this is to be detected within a minute, but during heavy load it can take longer time\&. .RE .RS 2 .LP The monitor is \fInot\fR\& automatically removed after it has been triggered\&. That is, repeated changes of the time offset trigger the monitor repeatedly\&. .RE .RS 2 .LP When the monitor is triggered a \fI\&'CHANGE\&'\fR\& message is sent to the monitoring process\&. A \fI\&'CHANGE\&'\fR\& message has the following pattern: .RE .LP .nf {'CHANGE', MonitorRef, Type, Item, NewTimeOffset} .fi .RS 2 .LP where \fIMonitorRef\fR\&, \fIType\fR\&, and \fIItem\fR\& are the same as described above, and \fINewTimeOffset\fR\& is the new time offset\&. .RE .RS 2 .LP When the \fI\&'CHANGE\&'\fR\& message has been received you are guaranteed not to retrieve the old time offset when calling \fIerlang:time_offset()\fR\&\&. Notice that you can observe the change of the time offset when calling \fIerlang:time_offset()\fR\& before you get the \fI\&'CHANGE\&'\fR\& message\&. .RE .RE .LP Making several calls to \fImonitor/2\fR\& for the same \fIItem\fR\& and/or \fIType\fR\& is not an error; it results in as many independent monitoring instances\&. .LP The monitor functionality is expected to be extended\&. That is, other \fIType\fR\&s and \fIItem\fR\&s are expected to be supported in a future release\&. .LP .RS -4 .B Note: .RE If or when \fImonitor/2\fR\& is extended, other possible values for \fITag\fR\&, \fIObject\fR\&, and \fIInfo\fR\& in the monitor message will be introduced\&. .RE .LP .nf .B monitor(Type :: process, .B Item :: monitor_process_identifier(), .B Opts :: [monitor_option()]) -> .B MonitorRef .br .fi .br .nf .B monitor(Type :: port, .B Item :: monitor_port_identifier(), .B Opts :: [monitor_option()]) -> .B MonitorRef .br .fi .br .nf .B monitor(Type :: time_offset, .B Item :: clock_service, .B Opts :: [monitor_option()]) -> .B MonitorRef .br .fi .br .RS .LP Types: .RS 3 MonitorRef = reference() .br .nf \fBregistered_name()\fR\& = atom() .fi .br .nf \fBregistered_process_identifier()\fR\& = .br registered_name() | {registered_name(), node()} .fi .br .nf \fBmonitor_process_identifier()\fR\& = .br pid() | registered_process_identifier() .fi .br .nf \fBmonitor_port_identifier()\fR\& = port() | registered_name() .fi .br .RE .RE .RS .LP Provides an option list for modification of monitoring functionality provided by \fImonitor/2\fR\&\&. The \fIType\fR\& and \fIItem\fR\& arguments have the same meaning as when passed to \fImonitor/2\fR\&\&. Currently available options: .RS 2 .TP 2 .B \fI{alias, UnaliasOpt}\fR\&: The returned monitor reference will also become an alias for the calling process\&. That is, the returned reference can be used for sending messages to the calling process\&. See also \fIalias/0\fR\&\&. The \fIUnaliasOpt\fR\& determines how the alias should be deactivated\&. .RS 2 .TP 2 .B \fIexplicit_unalias\fR\&: Only an explicit call to \fIunalias/1\fR\& will deactivate the alias\&. .TP 2 .B \fIdemonitor\fR\&: The alias will be automatically deactivated when the monitor is removed\&. This either via an explicit call to \fIdemonitor/1\fR\& or when it is automatically removed at the same time as a \fI\&'DOWN\&'\fR\& message is delivered due to the monitor\&. The alias can also still be deactivated via a call to \fIunalias/1\fR\&\&. .TP 2 .B \fIreply_demonitor\fR\&: The alias will be automatically deactivated when the monitor is removed (see \fIdemonitor\fR\& option above) or a reply message sent via the alias is received\&. When a reply message is received via the alias the monitor will also be automatically removed\&. This is useful in client/server scenarios when a client monitors the server and will get the reply via the alias\&. Once the response is received both the alias and the monitor will be automatically removed regardless of whether the response is a reply or a \fI\&'DOWN\&'\fR\& message\&. The alias can also still be deactivated via a call to \fIunalias/1\fR\&\&. Note that if the alias is removed using the \fIunalias/1\fR\& BIF, the monitor will still be left active\&. .RE .RS 2 .LP Example: .RE .LP .nf server() -> receive {request, AliasReqId, Request} -> Result = perform_request(Request), AliasReqId ! {reply, AliasReqId, Result} end, server(). client(ServerPid, Request) -> AliasMonReqId = monitor(process, ServerPid, [{alias, reply_demonitor}]), ServerPid ! {request, AliasMonReqId, Request}, %% Alias as well as monitor will be automatically deactivated if we %% receive a reply or a 'DOWN' message since we used 'reply_demonitor' %% as unalias option... receive {reply, AliasMonReqId, Result} -> Result; {'DOWN', AliasMonReqId, process, ServerPid, ExitReason} -> error(ExitReason) end. .fi .RS 2 .LP Note that both the server and the client in this example must be executing on at least OTP 24 systems in order for this to work\&. .RE .RS 2 .LP For more information on process aliases see the \fIProcess Aliases\fR\& section of the \fIErlang Reference Manual\fR\& \&. .RE .TP 2 .B \fI{tag, UserDefinedTag}\fR\&: Replace the default \fITag\fR\& with \fIUserDefinedTag\fR\& in the monitor message delivered when the monitor is triggered\&. For example, when monitoring a process, the \fI\&'DOWN\&'\fR\& tag in the down message will be replaced by \fIUserDefinedTag\fR\&\&. .RS 2 .LP An example of how the \fI{tag, UserDefinedTag}\fR\& option can be used in order to enable the new selective receive optimization, introduced in OTP 24, when making multiple requests to different servers: .RE .LP .nf server() -> receive {request, From, ReqId, Request} -> Result = perform_request(Request), From ! {reply, self(), ReqId, Result} end, server(). client(ServerPids, Request) when is_list(ServerPids) -> ReqId = make_ref(), lists:foreach(fun (ServerPid) -> _ = monitor(process, ServerPid, [{tag, {'DOWN', ReqId}}]), ServerPid ! {request, self(), ReqId, Request} end, ServerPids), receive_replies(ReqId, length(ServerPids), []). receive_replies(_ReqId, 0, Acc) -> Acc; receive_replies(ReqId, N, Acc) -> %% The compiler will detect that we match on the 'ReqId' %% reference in all clauses, and will enable the selective %% receive optimization which makes the receive able to %% skip past all messages present in the message queue at %% the time when the 'ReqId' reference was created... Res = receive {reply, ServerPid, ReqId, Result} -> %% Here we typically would have deactivated the %% monitor by a call to demonitor(Mon, [flush]) but %% we ignore this in this example for simplicity... {ok, ServerPid, Result}; {{'DOWN', ReqId}, _Mon, process, ServerPid, ExitReason} -> {error, ServerPid, ExitReason} end, receive_replies(ReqId, N-1, [Res | Acc]). .fi .RS 2 .LP In order for this example to work as intended, the client must be executing on at least an OTP 24 system, but the servers may execute on older systems\&. .RE .RE .RE .LP .nf .B monitor_node(Node, Flag) -> true .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Flag = boolean() .br .RE .RE .RS .LP Monitor the status of the node \fINode\fR\&\&. If \fIFlag\fR\& is \fItrue\fR\&, monitoring is turned on\&. If \fIFlag\fR\& is \fIfalse\fR\&, monitoring is turned off\&. .LP Making several calls to \fImonitor_node(Node, true)\fR\& for the same \fINode\fR\& is not an error; it results in as many independent monitoring instances\&. .LP If \fINode\fR\& fails or does not exist, the message \fI{nodedown, Node}\fR\& is delivered to the process\&. If a process has made two calls to \fImonitor_node(Node, true)\fR\& and \fINode\fR\& terminates, two \fInodedown\fR\& messages are delivered to the process\&. If there is no connection to \fINode\fR\&, an attempt is made to create one\&. If this fails, a \fInodedown\fR\& message is delivered\&. .LP The delivery of the \fInodedown\fR\& signal is not ordered with respect to other link or monitor signals from the node that goes down\&. If you need a guarantee that all signals from the remote node has been delivered before the \fInodedown\fR\& signal is sent, you should use \fInet_kernel:monitor_nodes/1\fR\&\&. .LP Nodes connected through hidden connections can be monitored as any other nodes\&. .LP Failure: \fInotalive\fR\& if the local node is not alive\&. .RE .LP .nf .B erlang:monitor_node(Node, Flag, Options) -> true .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Flag = boolean() .br Options = [Option] .br Option = allow_passive_connect .br .RE .RE .RS .LP Behaves as \fImonitor_node/2\fR\& except that it allows an extra option to be specified, namely \fIallow_passive_connect\fR\&\&. This option allows the BIF to wait the normal network connection time-out for the \fImonitored node\fR\& to connect itself, even if it cannot be actively connected from this node (that is, it is blocked)\&. The state where this can be useful can only be achieved by using the Kernel option \fIdist_auto_connect once\fR\&\&. If that option is not used, option \fIallow_passive_connect\fR\& has no effect\&. .LP .RS -4 .B Note: .RE Option \fIallow_passive_connect\fR\& is used internally and is seldom needed in applications where the network topology and the Kernel options in effect are known in advance\&. .LP Failure: \fIbadarg\fR\& if the local node is not alive or the option list is malformed\&. .RE .LP .nf .B erlang:monotonic_time() -> integer() .br .fi .br .RS .LP Returns the current Erlang monotonic time in \fInative\fR\& time unit\&. This is a monotonically increasing time since some unspecified point in time\&. .LP .RS -4 .B Note: .RE This is a monotonically increasing time, but \fInot\fR\& a strictly monotonically increasing time\&. That is, consecutive calls to \fIerlang:monotonic_time/0\fR\& can produce the same result\&. .LP Different runtime system instances will use different unspecified points in time as base for their Erlang monotonic clocks\&. That is, it is \fIpointless\fR\& comparing monotonic times from different runtime system instances\&. Different runtime system instances can also place this unspecified point in time different relative runtime system start\&. It can be placed in the future (time at start is a negative value), the past (time at start is a positive value), or the runtime system start (time at start is zero)\&. The monotonic time at runtime system start can be retrieved by calling \fIerlang:system_info(start_time)\fR\&\&. .RE .LP .nf .B erlang:monotonic_time(Unit) -> integer() .br .fi .br .RS .LP Types: .RS 3 Unit = time_unit() .br .RE .RE .RS .LP Returns the current Erlang monotonic time converted into the \fIUnit\fR\& passed as argument\&. .LP Same as calling \fIerlang:convert_time_unit\fR\&\fI(\fR\&\fIerlang:monotonic_time()\fR\&\fI, native, Unit)\fR\&, however optimized for commonly used \fIUnit\fR\&s\&. .RE .LP .nf .B erlang:nif_error(Reason) -> no_return() .br .fi .br .RS .LP Types: .RS 3 Reason = term() .br .RE .RE .RS .LP Works exactly like \fIerror/1\fR\&, but Dialyzer thinks that this BIF will return an arbitrary term\&. When used in a stub function for a NIF to generate an exception when the NIF library is not loaded, Dialyzer does not generate false warnings\&. .RE .LP .nf .B erlang:nif_error(Reason, Args) -> no_return() .br .fi .br .RS .LP Types: .RS 3 Reason = term() .br Args = [term()] .br .RE .RE .RS .LP Works exactly like \fIerror/2\fR\&, but Dialyzer thinks that this BIF will return an arbitrary term\&. When used in a stub function for a NIF to generate an exception when the NIF library is not loaded, Dialyzer does not generate false warnings\&. .RE .LP .nf .B node() -> Node .br .fi .br .RS .LP Types: .RS 3 Node = node() .br .RE .RE .RS .LP Returns the name of the local node\&. If the node is not alive, \fInonode@nohost\fR\& is returned instead\&. .LP Allowed in guard tests\&. .RE .LP .nf .B node(Arg) -> Node .br .fi .br .RS .LP Types: .RS 3 Arg = pid() | port() | reference() .br Node = node() .br .RE .RE .RS .LP Returns the node where \fIArg\fR\& originates\&. \fIArg\fR\& can be a process identifier, a reference, or a port\&. If \fIArg\fR\& originates from the local node and the local node is not alive, \fInonode@nohost\fR\& is returned\&. .LP Allowed in guard tests\&. .RE .LP .nf .B nodes() -> Nodes .br .fi .br .RS .LP Types: .RS 3 Nodes = [node()] .br .RE .RE .RS .LP Returns a list of all nodes connected to this node through normal connections (that is, hidden nodes are not listed)\&. Same as nodes(visible)\&. .RE .LP .nf .B nodes(Arg) -> Nodes .br .fi .br .RS .LP Types: .RS 3 Arg = NodeType | [NodeType] .br NodeType = visible | hidden | connected | this | known .br Nodes = [node()] .br .RE .RE .RS .LP Returns a list of nodes according to the argument specified\&. The returned result, when the argument is a list, is the list of nodes satisfying the disjunction(s) of the list elements\&. .LP \fINodeType\fR\&s: .RS 2 .TP 2 .B \fIvisible\fR\&: Nodes connected to this node through normal connections\&. .TP 2 .B \fIhidden\fR\&: Nodes connected to this node through hidden connections\&. .TP 2 .B \fIconnected\fR\&: All nodes connected to this node\&. .TP 2 .B \fIthis\fR\&: This node\&. .TP 2 .B \fIknown\fR\&: Nodes that are known to this node\&. That is, connected nodes and nodes referred to by process identifiers, port identifiers, and references located on this node\&. The set of known nodes is garbage collected\&. Notice that this garbage collection can be delayed\&. For more information, see \fIerlang:system_info(delayed_node_table_gc)\fR\&\&. .RE .LP Some equalities: \fI[node()] = nodes(this)\fR\&, \fInodes(connected) = nodes([visible, hidden])\fR\&, and \fInodes() = nodes(visible)\fR\&\&. .RE .LP .nf .B nodes(Arg, InfoOpts) -> [NodeInfo] .br .fi .br .RS .LP Types: .RS 3 NodeType = visible | hidden | connected | this | known .br Arg = NodeType | [NodeType] .br InfoOpts = .br #{connection_id => boolean(), node_type => boolean()} .br NodeTypeInfo = visible | hidden | this | known .br ConnectionId = undefined | integer() .br Info = .br #{connection_id => ConnectionId, node_type => NodeTypeInfo} .br NodeInfo = {node(), Info} .br .RE .RE .RS .LP Returns a list of \fINodeInfo\fR\& tuples\&. The first element is the node name\&. Nodes to be included in the list are determined by the first argument \fIArg\fR\& in the same way as for \fInodes(Arg)\fR\&\&. The second element of \fINodeInfo\fR\& tuples is a map containing further information about the node identified by the first element\&. The information present in this map is determined by the \fIInfoOpts\fR\& map passed as the second argument\&. Currently the following associations are allowed in the \fIInfoOpts\fR\& map: .RS 2 .TP 2 .B \fIconnection_id => boolean()\fR\&: If the value of the association equals \fItrue\fR\&, the \fIInfo\fR\& map in the returned result will contain the key \fIconnection_id\fR\& associated with the value \fIConnectionId\fR\&\&. If \fIConnectionId\fR\& equals \fIundefined\fR\&, the node is not connected to the node which the caller is executing on, or is the node which the caller is executing on\&. If \fIConnectionId\fR\& is an integer, the node is currently connected to the node which the caller is executing on\&. .RS 2 .LP The integer connection identifier value together with a node name identifies a specific connection instance to the node with that node name\&. The connection identifier value is node local\&. That is, on the other node the connection identifier will \fInot\fR\& be the same value\&. If a connection is taken down and then taken up again, the connection identifier value will change for the connection to that node\&. The amount of values for connection identifiers are limited, so it is possible to see the same value for different instances, but quite unlikely\&. It is undefined how the value change between two consecutive connection instances\&. .RE .TP 2 .B \fInode_type => boolean()\fR\&: If the value of the association equals \fItrue\fR\&, the \fIInfo\fR\& map in the returned result will contain the key \fInode_type\fR\& associated with the value \fINodeTypeInfo\fR\&\&. Currently the following node types exist: .RS 2 .TP 2 .B \fIvisible\fR\&: The node is connected to the node of the calling process through an ordinary visible connection\&. That is, the node name would appear in the result returned by \fInodes/0\fR\&\&. .TP 2 .B \fIhidden\fR\&: The node is connected to the node of the calling process through a hidden connection\&. That is, the node name would \fInot\fR\& appear in the result returned by \fInodes/0\fR\&\&. .TP 2 .B \fIthis\fR\&: This is the node of the calling process\&. .TP 2 .B \fIknown\fR\&: The node is not connected but known to the node of the calling process\&. .RE .RE .LP Example: .LP .nf (a@localhost)1> nodes([this, connected], #{connection_id=>true, node_type=>true}). [{c@localhost,#{connection_id => 13892108,node_type => hidden}}, {b@localhost,#{connection_id => 3067553,node_type => visible}}, {a@localhost,#{connection_id => undefined,node_type => this}}] (a@localhost)2> .fi .RE .LP .nf .B now() -> Timestamp .br .fi .br .RS .LP Types: .RS 3 Timestamp = timestamp() .br .nf \fBtimestamp()\fR\& = .br {MegaSecs :: integer() >= 0, .br Secs :: integer() >= 0, .br MicroSecs :: integer() >= 0} .fi .br .RE .RE .RS .LP .RS -4 .B Warning: .RE \fIThis function is deprecated\&. Do not use it\&.\fR\& .LP For more information, see section Time and Time Correction in the User\&'s Guide\&. Specifically, section Dos and Dont\&'s describes what to use instead of \fIerlang:now/0\fR\&\&. .LP Returns the tuple \fI{MegaSecs, Secs, MicroSecs}\fR\&, which is the elapsed time since 00:00 GMT, January 1, 1970 (zero hour), if provided by the underlying OS\&. Otherwise some other point in time is chosen\&. It is also guaranteed that the following calls to this BIF return continuously increasing values\&. Hence, the return value from \fIerlang:now/0\fR\& can be used to generate unique time stamps\&. If it is called in a tight loop on a fast machine, the time of the node can become skewed\&. .LP Can only be used to check the local time of day if the time-zone information of the underlying OS is properly configured\&. .RE .LP .nf .B open_port(PortName, PortSettings) -> port() .br .fi .br .RS .LP Types: .RS 3 PortName = .br {spawn, Command :: string() | binary()} | .br {spawn_driver, Command :: string() | binary()} | .br {spawn_executable, FileName :: file:name_all()} | .br {fd, In :: integer() >= 0, Out :: integer() >= 0} .br PortSettings = [Opt] .br Opt = .br {packet, N :: 1 | 2 | 4} | .br stream | .br {line, L :: integer() >= 0} | .br {cd, Dir :: string() | binary()} | .br {env, .br Env :: .br [{Name :: os:env_var_name(), .br Val :: os:env_var_value() | false}]} | .br {args, [string() | binary()]} | .br {arg0, string() | binary()} | .br exit_status | use_stdio | nouse_stdio | stderr_to_stdout | .br in | out | binary | eof | .br {parallelism, Boolean :: boolean()} | .br hide | .br {busy_limits_port, .br {integer() >= 0, integer() >= 0} | disabled} | .br {busy_limits_msgq, .br {integer() >= 0, integer() >= 0} | disabled} .br .RE .RE .RS .LP Returns a port identifier as the result of opening a new Erlang port\&. A port can be seen as an external Erlang process\&. .LP The name of the executable as well as the arguments specified in \fIcd\fR\&, \fIenv\fR\&, \fIargs\fR\&, and \fIarg0\fR\& are subject to Unicode filename translation if the system is running in Unicode filename mode\&. To avoid translation or to force, for example UTF-8, supply the executable and/or arguments as a binary in the correct encoding\&. For details, see the module \fIfile(3erl)\fR\&, the function \fIfile:native_name_encoding/0\fR\& in Kernel, and the \fIUsing Unicode in Erlang\fR\& User\&'s Guide\&. .LP .RS -4 .B Note: .RE The characters in the name (if specified as a list) can only be > 255 if the Erlang virtual machine is started in Unicode filename translation mode\&. Otherwise the name of the executable is limited to the ISO Latin-1 character set\&. .LP \fIPortName\fR\&s: .RS 2 .TP 2 .B \fI{spawn, Command}\fR\&: Starts an external program\&. \fICommand\fR\& is the name of the external program to be run\&. \fICommand\fR\& runs outside the Erlang work space unless an Erlang driver with the name \fICommand\fR\& is found\&. If found, that driver is started\&. A driver runs in the Erlang work space, which means that it is linked with the Erlang runtime system\&. .RS 2 .LP For external programs, \fIPATH\fR\& is searched (or an equivalent method is used to find programs, depending on the OS)\&. This is done by invoking the shell on certain platforms\&. The first space-separated token of the command is considered as the name of the executable (or driver)\&. This (among other things) makes this option unsuitable for running programs with spaces in filenames or directory names\&. If spaces in executable filenames are desired, use \fI{spawn_executable, Command}\fR\& instead\&. .RE .TP 2 .B \fI{spawn_driver, Command}\fR\&: Works like \fI{spawn, Command}\fR\&, but demands the first (space-separated) token of the command to be the name of a loaded driver\&. If no driver with that name is loaded, a \fIbadarg\fR\& error is raised\&. .TP 2 .B \fI{spawn_executable, FileName}\fR\&: Works like \fI{spawn, FileName}\fR\&, but only runs external executables\&. \fIFileName\fR\& in its whole is used as the name of the executable, including any spaces\&. If arguments are to be passed, the \fIPortSettings\fR\& \fIargs\fR\& and \fIarg0\fR\& can be used\&. .RS 2 .LP The shell is usually not invoked to start the program, it is executed directly\&. \fIPATH\fR\& (or equivalent) is not searched\&. To find a program in \fIPATH\fR\& to execute, use \fIos:find_executable/1\fR\&\&. .RE .RS 2 .LP Only if a shell script or \fI\&.bat\fR\& file is executed, the appropriate command interpreter is invoked implicitly, but there is still no command-argument expansion or implicit \fIPATH\fR\& search\&. .RE .RS 2 .LP If \fIFileName\fR\& cannot be run, an error exception is raised, with the POSIX error code as the reason\&. The error reason can differ between OSs\&. Typically the error \fIenoent\fR\& is raised when an attempt is made to run a program that is not found and \fIeacces\fR\& is raised when the specified file is not executable\&. .RE .TP 2 .B \fI{fd, In, Out}\fR\&: Allows an Erlang process to access any currently opened file descriptors used by Erlang\&. The file descriptor \fIIn\fR\& can be used for standard input, and the file descriptor \fIOut\fR\& for standard output\&. It is only used for various servers in the Erlang OS (\fIshell\fR\& and \fIuser\fR\&)\&. Hence, its use is limited\&. .RE .LP \fIPortSettings\fR\& is a list of settings for the port\&. The valid settings are as follows: .RS 2 .TP 2 .B \fI{packet, N}\fR\&: Messages are preceded by their length, sent in \fIN\fR\& bytes, with the most significant byte first\&. The valid values for \fIN\fR\& are 1, 2, and 4\&. .TP 2 .B \fIstream\fR\&: Output messages are sent without packet lengths\&. A user-defined protocol must be used between the Erlang process and the external object\&. .TP 2 .B \fI{line, L}\fR\&: Messages are delivered on a per line basis\&. Each line (delimited by the OS-dependent newline sequence) is delivered in a single message\&. The message data format is \fI{Flag, Line}\fR\&, where \fIFlag\fR\& is \fIeol\fR\& or \fInoeol\fR\&, and \fILine\fR\& is the data delivered (without the newline sequence)\&. .RS 2 .LP \fIL\fR\& specifies the maximum line length in bytes\&. Lines longer than this are delivered in more than one message, with \fIFlag\fR\& set to \fInoeol\fR\& for all but the last message\&. If end of file is encountered anywhere else than immediately following a newline sequence, the last line is also delivered with \fIFlag\fR\& set to \fInoeol\fR\&\&. Otherwise lines are delivered with \fIFlag\fR\& set to \fIeol\fR\&\&. .RE .RS 2 .LP The \fI{packet, N}\fR\& and \fI{line, L}\fR\& settings are mutually exclusive\&. .RE .TP 2 .B \fI{cd, Dir}\fR\&: Only valid for \fI{spawn, Command}\fR\& and \fI{spawn_executable, FileName}\fR\&\&. The external program starts using \fIDir\fR\& as its working directory\&. \fIDir\fR\& must be a string\&. .TP 2 .B \fI{env, Env}\fR\&: Types: .br \fIName = \fR\&\fIos:env_var_name()\fR\& .br \fIVal = \fR\&\fIos:env_var_value()\fR\&\fI | false\fR\& .br \fIEnv = [{Name, Val}]\fR\& .RS 2 .LP Only valid for \fI{spawn, Command}\fR\&, and \fI{spawn_executable, FileName}\fR\&\&. The environment of the started process is extended using the environment specifications in \fIEnv\fR\&\&. .RE .RS 2 .LP \fIEnv\fR\& is to be a list of tuples \fI{Name, Val}\fR\&, where \fIName\fR\& is the name of an environment variable, and \fIVal\fR\& is the value it is to have in the spawned port process\&. Both \fIName\fR\& and \fIVal\fR\& must be strings\&. The one exception is \fIVal\fR\& being the atom \fIfalse\fR\& (in analogy with \fIos:getenv/1\fR\&, which removes the environment variable\&. .RE .RS 2 .LP For information about encoding requirements, see documentation of the types for \fIName\fR\& and \fIVal\fR\&\&. .RE .TP 2 .B \fI{args, [ string() | binary() ]}\fR\&: Only valid for \fI{spawn_executable, FileName}\fR\& and specifies arguments to the executable\&. Each argument is specified as a separate string and (on Unix) eventually ends up as one element each in the argument vector\&. On other platforms, a similar behavior is mimicked\&. .RS 2 .LP The arguments are not expanded by the shell before they are supplied to the executable\&. Most notably this means that file wildcard expansion does not occur\&. To expand wildcards for the arguments, use \fIfilelib:wildcard/1\fR\&\&. Notice that even if the program is a Unix shell script, meaning that the shell ultimately is invoked, wildcard expansion does not occur, and the script is provided with the untouched arguments\&. On Windows, wildcard expansion is always up to the program itself, therefore this is not an issue\&. .RE .RS 2 .LP The executable name (also known as \fIargv[0]\fR\&) is not to be specified in this list\&. The proper executable name is automatically used as \fIargv[0]\fR\&, where applicable\&. .RE .RS 2 .LP If you explicitly want to set the program name in the argument vector, option \fIarg0\fR\& can be used\&. .RE .TP 2 .B \fI{arg0, string() | binary()}\fR\&: Only valid for \fI{spawn_executable, FileName}\fR\& and explicitly specifies the program name argument when running an executable\&. This can in some circumstances, on some OSs, be desirable\&. How the program responds to this is highly system-dependent and no specific effect is guaranteed\&. .TP 2 .B \fIexit_status\fR\&: Only valid for \fI{spawn, Command}\fR\&, where \fICommand\fR\& refers to an external program, and for \fI{spawn_executable, FileName}\fR\&\&. .RS 2 .LP When the external process connected to the port exits, a message of the form \fI{Port,{exit_status,Status}}\fR\& is sent to the connected process, where \fIStatus\fR\& is the exit status of the external process\&. If the program aborts on Unix, the same convention is used as the shells do (that is, 128+signal)\&. .RE .RS 2 .LP If option \fIeof\fR\& is specified also, the messages \fIeof\fR\& and \fIexit_status\fR\& appear in an unspecified order\&. .RE .RS 2 .LP If the port program closes its \fIstdout\fR\& without exiting, option \fIexit_status\fR\& does not work\&. .RE .TP 2 .B \fIuse_stdio\fR\&: Only valid for \fI{spawn, Command}\fR\& and \fI{spawn_executable, FileName}\fR\&\&. It allows the standard input and output (file descriptors 0 and 1) of the spawned (Unix) process for communication with Erlang\&. .TP 2 .B \fInouse_stdio\fR\&: The opposite of \fIuse_stdio\fR\&\&. It uses file descriptors 3 and 4 for communication with Erlang\&. .TP 2 .B \fIstderr_to_stdout\fR\&: Affects ports to external programs\&. The executed program gets its standard error file redirected to its standard output file\&. \fIstderr_to_stdout\fR\& and \fInouse_stdio\fR\& are mutually exclusive\&. .TP 2 .B \fIoverlapped_io\fR\&: Affects ports to external programs on Windows only\&. The standard input and standard output handles of the port program are, if this option is supplied, opened with flag \fIFILE_FLAG_OVERLAPPED\fR\&, so that the port program can (and must) do overlapped I/O on its standard handles\&. This is not normally the case for simple port programs, but an option of value for the experienced Windows programmer\&. \fIOn all other platforms, this option is silently discarded\&.\fR\& .TP 2 .B \fIin\fR\&: The port can only be used for input\&. .TP 2 .B \fIout\fR\&: The port can only be used for output\&. .TP 2 .B \fIbinary\fR\&: All I/O from the port is binary data objects as opposed to lists of bytes\&. .TP 2 .B \fIeof\fR\&: The port is not closed at the end of the file and does not produce an exit signal\&. Instead, it remains open and a \fI{Port, eof}\fR\& message is sent to the process holding the port\&. .TP 2 .B \fIhide\fR\&: When running on Windows, suppresses creation of a new console window when spawning the port program\&. (This option has no effect on other platforms\&.) .TP 2 .B \fI{parallelism, Boolean}\fR\&: .RS 2 .LP Sets scheduler hint for port parallelism\&. If set to \fItrue\fR\&, the virtual machine schedules port tasks; when doing so, it improves parallelism in the system\&. If set to \fIfalse\fR\&, the virtual machine tries to perform port tasks immediately, improving latency at the expense of parallelism\&. The default can be set at system startup by passing command-line argument \fI+spp\fR\& to \fIerl(1)\fR\&\&. .RE .TP 2 .B \fI{busy_limits_port, {Low, High} | disabled}\fR\&: Sets limits that will be used for controlling the busy state of the port\&. .RS 2 .LP When the ports internal output queue size becomes larger than or equal to \fIHigh\fR\& bytes, it enters the busy state\&. When it becomes less than \fILow\fR\& bytes it leaves the busy state\&. When the port is in the busy state, processes sending commands to it will be suspended until the port leaves the busy state\&. Commands are in this context either \fIPort ! {Owner, {command, Data}}\fR\& or \fIport_command/[2,3]\fR\&\&. .RE .RS 2 .LP The \fILow\fR\& limit is automatically adjusted to the same as \fIHigh\fR\& if it is set larger then \fIHigh\fR\&\&. Valid range of values for \fILow\fR\& and \fIHigh\fR\& is \fI[1, (1 bsl (8*erlang:system_info(wordsize)))-2]\fR\&\&. If the atom \fIdisabled\fR\& is passed, the port will never enter the busy state\&. .RE .RS 2 .LP The defaults are \fILow = 4096\fR\& and \fIHigh = 8192\fR\&\&. .RE .RS 2 .LP \fINote\fR\& that this option is only valid when spawning an executable (port program) by opening the spawn driver and when opening the \fIfd\fR\& driver\&. This option will cause a failure with a \fIbadarg\fR\& exception when opening other drivers\&. .RE .TP 2 .B \fI{busy_limits_msgq, {Low, High} | disabled}\fR\&: Sets limits that will be used for controlling the busy state of the port message queue\&. .RS 2 .LP When the ports message queue size becomes larger than or equal to \fIHigh\fR\& bytes it enters the busy state\&. When it becomes less than \fILow\fR\& bytes it leaves the busy state\&. When the port message queue is in the busy state, processes sending commands to it will be suspended until the port message queue leaves the busy state\&. Commands are in this context either \fIPort ! {Owner, {command, Data}}\fR\& or \fIport_command/[2,3]\fR\&\&. .RE .RS 2 .LP The \fILow\fR\& limit is automatically adjusted to the same as \fIHigh\fR\& if it is set larger then \fIHigh\fR\&\&. Valid range of values for \fILow\fR\& and \fIHigh\fR\& is \fI[1, (1 bsl (8*erlang:system_info(wordsize)))-2]\fR\&\&. If the atom \fIdisabled\fR\& is passed, the port message queue will never enter the busy state\&. .RE .RS 2 .LP \fINote\fR\& that if the driver statically has disabled the use of this feature, a failure with a \fIbadarg\fR\& exception will be raised unless this option also is set to \fIdisable\fR\& or not passed at all\&. .RE .RS 2 .LP The defaults are \fILow = 4096\fR\& and \fIHigh = 8192\fR\& unless the driver itself does modifications of these values\&. .RE .RS 2 .LP \fINote\fR\& that the driver might fail if it also adjust these limits by itself and you have disabled this feature\&. .RE .RS 2 .LP The spawn driver (used when spawning an executable) and the \fIfd\fR\& driver do not disable this feature and do not adjust these limits by themselves\&. .RE .RS 2 .LP For more information see the documentation \fIerl_drv_busy_msgq_limits()\fR\&\&. .RE .RE .LP Default is \fIstream\fR\& for all port types and \fIuse_stdio\fR\& for spawned ports\&. .LP Failure: if the port cannot be opened, the exit reason is \fIbadarg\fR\&, \fIsystem_limit\fR\&, or the POSIX error code that most closely describes the error, or \fIeinval\fR\& if no POSIX code is appropriate: .RS 2 .TP 2 .B \fIbadarg\fR\&: Bad input arguments to \fIopen_port\fR\&\&. .TP 2 .B \fIsystem_limit\fR\&: All available ports in the Erlang emulator are in use\&. .TP 2 .B \fIenomem\fR\&: Not enough memory to create the port\&. .TP 2 .B \fIeagain\fR\&: No more available OS processes\&. .TP 2 .B \fIenametoolong\fR\&: Too long external command\&. .TP 2 .B \fIemfile\fR\&: No more available file descriptors (for the OS process that the Erlang emulator runs in)\&. .TP 2 .B \fIenfile\fR\&: Full file table (for the entire OS)\&. .TP 2 .B \fIeacces\fR\&: \fICommand\fR\& specified in \fI{spawn_executable, Command}\fR\& does not point out an executable file\&. .TP 2 .B \fIenoent\fR\&: \fIFileName\fR\& specified in \fI{spawn_executable, FileName}\fR\& does not point out an existing file\&. .RE .LP During use of a port opened using \fI{spawn, Name}\fR\&, \fI{spawn_driver, Name}\fR\&, or \fI{spawn_executable, Name}\fR\&, errors arising when sending messages to it are reported to the owning process using signals of the form \fI{\&'EXIT\&', Port, PosixCode}\fR\&\&. For the possible values of \fIPosixCode\fR\&, see \fIfile(3erl)\fR\&\&. .LP The maximum number of ports that can be open at the same time can be configured by passing command-line flag \fI+Q\fR\& to \fIerl(1)\fR\&\&. .RE .LP .nf .B erlang:phash(Term, Range) -> Hash .br .fi .br .RS .LP Types: .RS 3 Term = term() .br Range = Hash = integer() >= 1 .br .RS 2 Range = 1\&.\&.2^32, Hash = 1\&.\&.Range .RE .RE .RE .RS .LP .RS -4 .B Warning: .RE This function is deprecated as \fIerlang:phash2/2\fR\& should be used for new code\&. Note that \fIerlang:phash(X,N)\fR\& is not necessary equal to \fIerlang:phash2(X,N)\fR\& .LP Portable hash function that gives the same hash for the same Erlang term regardless of machine architecture and ERTS version (the BIF was introduced in ERTS 4\&.9\&.1\&.1)\&. The function returns a hash value for \fITerm\fR\& within the range \fI1\&.\&.Range\fR\&\&. The maximum value for \fIRange\fR\& is 2^32\&. .RE .LP .nf .B erlang:phash2(Term) -> Hash .br .fi .br .nf .B erlang:phash2(Term, Range) -> Hash .br .fi .br .RS .LP Types: .RS 3 Term = term() .br Range = integer() >= 1 .br .RS 2 1\&.\&.2^32 .RE Hash = integer() >= 0 .br .RS 2 0\&.\&.Range-1 .RE .RE .RE .RS .LP Portable hash function that gives the same hash for the same Erlang term regardless of machine architecture and ERTS version (the BIF was introduced in ERTS 5\&.2)\&. The function returns a hash value for \fITerm\fR\& within the range \fI0\&.\&.Range-1\fR\&\&. The maximum value for \fIRange\fR\& is 2^32\&. When without argument \fIRange\fR\&, a value in the range 0\&.\&.2^27-1 is returned\&. .LP This BIF is always to be used for hashing terms\&. It distributes small integers better than \fIphash/2\fR\&, and it is faster for bignums and binaries\&. .LP Notice that the range \fI0\&.\&.Range-1\fR\& is different from the range of \fIphash/2\fR\&, which is \fI1\&.\&.Range\fR\&\&. .RE .LP .nf .B pid_to_list(Pid) -> string() .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br .RE .RE .RS .LP Returns a string corresponding to the text representation of \fIPid\fR\&\&. Example: .LP .nf > erlang:pid_to_list(self())\&. "<0.85.0>" .fi .LP .RS -4 .B Note: .RE The creation for the node is not included in the list representation of \fIPid\fR\&\&. This means that processes in different incarnations of a node with a specific name can get the same list representation\&. .RE .LP .nf .B erlang:port_call(Port, Operation, Data) -> term() .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Operation = integer() .br Data = term() .br .RE .RE .RS .LP Performs a synchronous call to a port\&. The meaning of \fIOperation\fR\& and \fIData\fR\& depends on the port, that is, on the port driver\&. Not all port drivers support this feature\&. .LP \fIPort\fR\& is a port identifier, referring to a driver\&. .LP \fIOperation\fR\& is an integer, which is passed on to the driver\&. .LP \fIData\fR\& is any Erlang term\&. This data is converted to binary term format and sent to the port\&. .LP Returns a term from the driver\&. The meaning of the returned data also depends on the port driver\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIPort\fR\& is not an identifier of an open port, or the registered name of an open port\&. If the calling process was previously linked to the closed port, identified by \fIPort\fR\&, the exit signal from the port is guaranteed to be delivered before this \fIbadarg\fR\& exception occurs\&. .TP 2 .B \fIbadarg\fR\&: If \fIOperation\fR\& does not fit in a 32-bit integer\&. .TP 2 .B \fIbadarg\fR\&: If the port driver does not support synchronous control operations\&. .TP 2 .B \fIbadarg\fR\&: If the port driver so decides for any reason (probably something wrong with \fIOperation\fR\& or \fIData\fR\&)\&. .LP .RS -4 .B Warning: .RE Do not call \fIport_call\fR\& with an unknown \fIPort\fR\& identifier and expect \fIbadarg\fR\& exception\&. Any undefined behavior is possible (including node crash) depending on how the port driver interprets the supplied arguments\&. .RE .RE .LP .nf .B port_close(Port) -> true .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br .RE .RE .RS .LP Closes an open port\&. Roughly the same as \fIPort ! {self(), close}\fR\& except for the error behavior (see below), being synchronous, and that the port does \fInot\fR\& reply with \fI{Port, closed}\fR\&\&. Any process can close a port with \fIport_close/1\fR\&, not only the port owner (the connected process)\&. If the calling process is linked to the port identified by \fIPort\fR\&, the exit signal from the port is guaranteed to be delivered before \fIport_close/1\fR\& returns\&. .LP For comparison: \fIPort ! {self(), close}\fR\& only fails with \fIbadarg\fR\& if \fIPort\fR\& does not refer to a port or a process\&. If \fIPort\fR\& is a closed port, nothing happens\&. If \fIPort\fR\& is an open port and the calling process is the port owner, the port replies with \fI{Port, closed}\fR\& when all buffers have been flushed and the port really closes\&. If the calling process is not the port owner, the \fIport owner\fR\& fails with \fIbadsig\fR\&\&. .LP Notice that any process can close a port using \fIPort ! {PortOwner, close}\fR\& as if it itself was the port owner, but the reply always goes to the port owner\&. .LP As from Erlang/OTP R16, \fIPort ! {PortOwner, close}\fR\& is truly asynchronous\&. Notice that this operation has always been documented as an asynchronous operation, while the underlying implementation has been synchronous\&. \fIport_close/1\fR\& is however still fully synchronous because of its error behavior\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not an identifier of an open port, or the registered name of an open port\&. If the calling process was previously linked to the closed port, identified by \fIPort\fR\&, the exit signal from the port is guaranteed to be delivered before this \fIbadarg\fR\& exception occurs\&. .RE .LP .nf .B port_command(Port, Data) -> true .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Data = iodata() .br .RE .RE .RS .LP Sends data to a port\&. Same as \fIPort ! {PortOwner, {command, Data}}\fR\& except for the error behavior and being synchronous (see below)\&. Any process can send data to a port with \fIport_command/2\fR\&, not only the port owner (the connected process)\&. .LP For comparison: \fIPort ! {PortOwner, {command, Data}}\fR\& only fails with \fIbadarg\fR\& if \fIPort\fR\& does not refer to a port or a process\&. If \fIPort\fR\& is a closed port, the data message disappears without a sound\&. If \fIPort\fR\& is open and the calling process is not the port owner, the \fIport owner\fR\& fails with \fIbadsig\fR\&\&. The port owner fails with \fIbadsig\fR\& also if \fIData\fR\& is an invalid I/O list\&. .LP Notice that any process can send to a port using \fIPort ! {PortOwner, {command, Data}}\fR\& as if it itself was the port owner\&. .LP If the port is busy, the calling process is suspended until the port is not busy any more\&. .LP As from Erlang/OTP R16, \fIPort ! {PortOwner, {command, Data}}\fR\& is truly asynchronous\&. Notice that this operation has always been documented as an asynchronous operation, while the underlying implementation has been synchronous\&. \fIport_command/2\fR\& is however still fully synchronous because of its error behavior\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIPort\fR\& is not an identifier of an open port, or the registered name of an open port\&. If the calling process was previously linked to the closed port, identified by \fIPort\fR\&, the exit signal from the port is guaranteed to be delivered before this \fIbadarg\fR\& exception occurs\&. .TP 2 .B \fIbadarg\fR\&: If \fIData\fR\& is an invalid I/O list\&. .RE .LP .RS -4 .B Warning: .RE Do not send data to an unknown port\&. Any undefined behavior is possible (including node crash) depending on how the port driver interprets the data\&. .RE .LP .nf .B port_command(Port, Data, OptionList) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Data = iodata() .br Option = force | nosuspend .br OptionList = [Option] .br .RE .RE .RS .LP Sends data to a port\&. \fIport_command(Port, Data, [])\fR\& equals \fIport_command(Port, Data)\fR\&\&. .LP If the port command is aborted, \fIfalse\fR\& is returned, otherwise \fItrue\fR\&\&. .LP If the port is busy, the calling process is suspended until the port is not busy anymore\&. .LP \fIOption\fR\&s: .RS 2 .TP 2 .B \fIforce\fR\&: The calling process is not suspended if the port is busy, instead the port command is forced through\&. The call fails with a \fInotsup\fR\& exception if the driver of the port does not support this\&. For more information, see driver flag \fIERL_DRV_FLAG_SOFT_BUSY\fR\&\&. .TP 2 .B \fInosuspend\fR\&: The calling process is not suspended if the port is busy, instead the port command is aborted and \fIfalse\fR\& is returned\&. .RE .LP .RS -4 .B Note: .RE More options can be added in a future release\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIPort\fR\& is not an identifier of an open port, or the registered name of an open port\&. If the calling process was previously linked to the closed port, identified by \fIPort\fR\&, the exit signal from the port is guaranteed to be delivered before this \fIbadarg\fR\& exception occurs\&. .TP 2 .B \fIbadarg\fR\&: If \fIData\fR\& is an invalid I/O list\&. .TP 2 .B \fIbadarg\fR\&: If \fIOptionList\fR\& is an invalid option list\&. .TP 2 .B \fInotsup\fR\&: If option \fIforce\fR\& has been passed, but the driver of the port does not allow forcing through a busy port\&. .RE .LP .RS -4 .B Warning: .RE Do not send data to an unknown port\&. Any undefined behavior is possible (including node crash) depending on how the port driver interprets the data\&. .RE .LP .nf .B port_connect(Port, Pid) -> true .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Pid = pid() .br .RE .RE .RS .LP Sets the port owner (the connected port) to \fIPid\fR\&\&. Roughly the same as \fIPort ! {Owner, {connect, Pid}}\fR\& except for the following: .RS 2 .TP 2 * The error behavior differs, see below\&. .LP .TP 2 * The port does \fInot\fR\& reply with \fI{Port,connected}\fR\&\&. .LP .TP 2 * \fIport_connect/1\fR\& is synchronous, see below\&. .LP .TP 2 * The new port owner gets linked to the port\&. .LP .RE .LP The old port owner stays linked to the port and must call \fIunlink(Port)\fR\& if this is not desired\&. Any process can set the port owner to be any process with \fIport_connect/2\fR\&\&. .LP For comparison: \fIPort ! {self(), {connect, Pid}}\fR\& only fails with \fIbadarg\fR\& if \fIPort\fR\& does not refer to a port or a process\&. If \fIPort\fR\& is a closed port, nothing happens\&. If \fIPort\fR\& is an open port and the calling process is the port owner, the port replies with \fI{Port, connected}\fR\& to the old port owner\&. Notice that the old port owner is still linked to the port, while the new is not\&. If \fIPort\fR\& is an open port and the calling process is not the port owner, the \fIport owner\fR\& fails with \fIbadsig\fR\&\&. The port owner fails with \fIbadsig\fR\& also if \fIPid\fR\& is not an existing local process identifier\&. .LP Notice that any process can set the port owner using \fIPort ! {PortOwner, {connect, Pid}}\fR\& as if it itself was the port owner, but the reply always goes to the port owner\&. .LP As from Erlang/OTP R16, \fIPort ! {PortOwner, {connect, Pid}}\fR\& is truly asynchronous\&. Notice that this operation has always been documented as an asynchronous operation, while the underlying implementation has been synchronous\&. \fIport_connect/2\fR\& is however still fully synchronous because of its error behavior\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIPort\fR\& is not an identifier of an open port, or the registered name of an open port\&. If the calling process was previously linked to the closed port, identified by \fIPort\fR\&, the exit signal from the port is guaranteed to be delivered before this \fIbadarg\fR\& exception occurs\&. .TP 2 .B \fIbadarg\fR\&: If the process identified by \fIPid\fR\& is not an existing local process\&. .RE .RE .LP .nf .B port_control(Port, Operation, Data) -> iodata() | binary() .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Operation = integer() .br Data = iodata() .br .RE .RE .RS .LP Performs a synchronous control operation on a port\&. The meaning of \fIOperation\fR\& and \fIData\fR\& depends on the port, that is, on the port driver\&. Not all port drivers support this control feature\&. .LP Returns a list of integers in the range 0\&.\&.255, or a binary, depending on the port driver\&. The meaning of the returned data also depends on the port driver\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIPort\fR\& is not an open port or the registered name of an open port\&. .TP 2 .B \fIbadarg\fR\&: If \fIOperation\fR\& cannot fit in a 32-bit integer\&. .TP 2 .B \fIbadarg\fR\&: If the port driver does not support synchronous control operations\&. .TP 2 .B \fIbadarg\fR\&: If the port driver so decides for any reason (probably something wrong with \fIOperation\fR\& or \fIData\fR\&)\&. .LP .RS -4 .B Warning: .RE Do not call \fIport_control/3\fR\& with an unknown \fIPort\fR\& identifier and expect \fIbadarg\fR\& exception\&. Any undefined behavior is possible (including node crash) depending on how the port driver interprets the supplied arguments\&. .RE .RE .LP .nf .B erlang:port_info(Port) -> Result .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br ResultItem = .br {registered_name, RegisteredName :: atom()} | .br {id, Index :: integer() >= 0} | .br {connected, Pid :: pid()} | .br {links, Pids :: [pid()]} | .br {name, String :: string()} | .br {input, Bytes :: integer() >= 0} | .br {output, Bytes :: integer() >= 0} | .br {os_pid, OsPid :: integer() >= 0 | undefined} .br Result = [ResultItem] | undefined .br .RE .RE .RS .LP Returns a list containing tuples with information about \fIPort\fR\&, or \fIundefined\fR\& if the port is not open\&. The order of the tuples is undefined, and all the tuples are not mandatory\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/1\fR\& returns \fIundefined\fR\&\&. .LP The result contains information about the following \fIItem\fR\&s: .RS 2 .TP 2 * \fIregistered_name\fR\& (if the port has a registered name) .LP .TP 2 * \fIid\fR\& .LP .TP 2 * \fIconnected\fR\& .LP .TP 2 * \fIlinks\fR\& .LP .TP 2 * \fIname\fR\& .LP .TP 2 * \fIinput\fR\& .LP .TP 2 * \fIoutput\fR\& .LP .RE .LP For more information about the different \fIItem\fR\&s, see \fIport_info/2\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: connected) -> .B {connected, Pid} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Pid = pid() .br .RE .RE .RS .LP \fIPid\fR\& is the process identifier of the process connected to the port\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: id) -> {id, Index} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Index = integer() >= 0 .br .RE .RE .RS .LP \fIIndex\fR\& is the internal index of the port\&. This index can be used to separate ports\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: input) -> .B {input, Bytes} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Bytes = integer() >= 0 .br .RE .RE .RS .LP \fIBytes\fR\& is the total number of bytes read from the port\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: links) -> {links, Pids} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Pids = [pid()] .br .RE .RE .RS .LP \fIPids\fR\& is a list of the process identifiers of the processes that the port is linked to\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: locking) -> .B {locking, Locking} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Locking = false | port_level | driver_level .br .RE .RE .RS .LP \fILocking\fR\& is one of the following: .RS 2 .TP 2 * \fIport_level\fR\& (port-specific locking) .LP .TP 2 * \fIdriver_level\fR\& (driver-specific locking) .LP .RE .LP Notice that these results are highly implementation-specific and can change in a future release\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: memory) -> .B {memory, Bytes} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Bytes = integer() >= 0 .br .RE .RE .RS .LP \fIBytes\fR\& is the total number of bytes allocated for this port by the runtime system\&. The port itself can have allocated memory that is not included in \fIBytes\fR\&\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: monitors) -> .B {monitors, Monitors} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Monitors = [{process, pid()}] .br .RE .RE .RS .LP \fIMonitors\fR\& represent processes monitored by this port\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: monitored_by) -> .B {monitored_by, MonitoredBy} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br MonitoredBy = [pid()] .br .RE .RE .RS .LP Returns list of pids that are monitoring given port at the moment\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: name) -> {name, Name} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Name = string() .br .RE .RE .RS .LP \fIName\fR\& is the command name set by \fIopen_port/2\fR\&\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: os_pid) -> .B {os_pid, OsPid} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br OsPid = integer() >= 0 | undefined .br .RE .RE .RS .LP \fIOsPid\fR\& is the process identifier (or equivalent) of an OS process created with \fIopen_port({spawn | spawn_executable, Command}, Options)\fR\&\&. If the port is not the result of spawning an OS process, the value is \fIundefined\fR\&\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: output) -> .B {output, Bytes} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Bytes = integer() >= 0 .br .RE .RE .RS .LP \fIBytes\fR\& is the total number of bytes written to the port from Erlang processes using \fIport_command/2\fR\&, \fIport_command/3\fR\&, or \fIPort ! {Owner, {command, Data}\fR\&\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: parallelism) -> .B {parallelism, Boolean} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Boolean = boolean() .br .RE .RE .RS .LP \fIBoolean\fR\& corresponds to the port parallelism hint used by this port\&. For more information, see option \fIparallelism\fR\& of \fIopen_port/2\fR\&\&. .RE .LP .nf .B erlang:port_info(Port, Item :: queue_size) -> .B {queue_size, Bytes} | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br Bytes = integer() >= 0 .br .RE .RE .RS .LP \fIBytes\fR\& is the total number of bytes queued by the port using the ERTS driver queue implementation\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B erlang:port_info(Port, Item :: registered_name) -> .B {registered_name, RegisteredName} | .B [] | undefined .br .fi .br .RS .LP Types: .RS 3 Port = port() | atom() .br RegisteredName = atom() .br .RE .RE .RS .LP \fIRegisteredName\fR\& is the registered name of the port\&. If the port has no registered name, \fI[]\fR\& is returned\&. .LP If the port identified by \fIPort\fR\& is not open, \fIundefined\fR\& is returned\&. If the port is closed and the calling process was previously linked to the port, the exit signal from the port is guaranteed to be delivered before \fIport_info/2\fR\& returns \fIundefined\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPort\fR\& is not a local port identifier, or an atom\&. .RE .LP .nf .B port_to_list(Port) -> string() .br .fi .br .RS .LP Types: .RS 3 Port = port() .br .RE .RE .RS .LP Returns a string corresponding to the text representation of the port identifier \fIPort\fR\&\&. .RE .LP .nf .B erlang:ports() -> [port()] .br .fi .br .RS .LP Returns a list of port identifiers corresponding to all the ports existing on the local node\&. .LP Notice that an exiting port exists, but is not open\&. .RE .LP .nf .B pre_loaded() -> [module()] .br .fi .br .RS .LP Returns a list of Erlang modules that are preloaded in the run-time system\&. Pre-loaded modules are Erlang modules that are needed to bootstrap the system to load the first Erlang modules from either disk or by using \fIerl_boot_server\fR\&\&. .RE .LP .nf .B erlang:process_display(Pid, Type) -> true .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br Type = backtrace .br .RE .RE .RS .LP Writes information about the local process \fIPid\fR\& on standard error\&. The only allowed value for the atom \fIType\fR\& is \fIbacktrace\fR\&, which shows the contents of the call stack, including information about the call chain, with the current function printed first\&. The format of the output is not further defined\&. .RE .LP .nf .B process_flag(Flag :: async_dist, Boolean) -> OldBoolean .br .fi .br .RS .LP Types: .RS 3 Boolean = OldBoolean = boolean() .br .RE .RE .RS .LP Enable or disable \fIfully asynchronous distributed signaling\fR\& for the calling process\&. When disabled, which is the default, the process sending a distributed signal will block in the send operation if the buffer for the distribution channel reach the distribution buffer busy limit\&. The process will remain blocked until the buffer shrinks enough\&. This might in some cases take a substantial amount of time\&. When \fIasync_dist\fR\& is enabled, send operations of distributed signals will always buffer the signal on the outgoing distribution channel and then immediately return\&. That is, these send operations will \fInever\fR\& block the sending process\&. .LP .RS -4 .B Note: .RE Since no flow control is enforced by the runtime system when \fIasync_dist\fR\& process flag is enabled, you need to make sure that flow control for such data is implemented, or that the amount of such data is known to always be limited\&. Unlimited signaling with \fIasync_dist\fR\& enabled in the absence of flow control will typically cause the sending runtime system to crash on an out of memory condition\&. .LP Blocking due to disabled \fIasync_dist\fR\& can be monitored by \fIerlang:system_montor()\fR\& using the \fIbusy_dist_port\fR\& option\&. Only data buffered by processes which (at the time of sending a signal) have disabled \fIasync_dist\fR\& will be counted when determining whether or not an operation should block the caller\&. .LP The \fIasync_dist\fR\& flag can also be set on a new process when spawning it using the \fIspawn_opt()\fR\& BIF with the option \fI{async_dist, Enable}\fR\&\&. The default \fIasync_dist\fR\& flag to use on newly spawned processes can be set by passing the command line argument \fI+pad \fR\& when starting the runtime system\&. If the \fI+pad \fR\& command line argument is not passed, the default value of the \fIasync_dist\fR\& flag will be \fIfalse\fR\&\&. .LP You can inspect the state of the \fIasync_dist\fR\& process flag of a process by calling \fIprocess_info(Pid, async_dist)\fR\&\&. .LP Returns the old value of the \fIasync_dist\fR\& flag\&. .RE .LP .nf .B process_flag(Flag :: trap_exit, Boolean) -> OldBoolean .br .fi .br .RS .LP Types: .RS 3 Boolean = OldBoolean = boolean() .br .RE .RE .RS .LP When \fItrap_exit\fR\& is set to \fItrue\fR\&, exit signals arriving to a process are converted to \fI{\&'EXIT\&', From, Reason}\fR\& messages, which can be received as ordinary messages\&. If \fItrap_exit\fR\& is set to \fIfalse\fR\&, the process exits if it receives an exit signal other than \fInormal\fR\& and the exit signal is propagated to its linked processes\&. Application processes are normally not to trap exits\&. .LP Returns the old value of the flag\&. .LP See also \fIexit/2\fR\&\&. .RE .LP .nf .B process_flag(Flag :: error_handler, Module) -> OldModule .br .fi .br .RS .LP Types: .RS 3 Module = OldModule = atom() .br .RE .RE .RS .LP Used by a process to redefine the error handler for undefined function calls and undefined registered processes\&. Inexperienced users are not to use this flag, as code auto-loading depends on the correct operation of the error handling module\&. .LP Returns the old value of the flag\&. .RE .LP .nf .B process_flag(Flag :: fullsweep_after, FullsweepAfter) -> .B OldFullsweepAfter .br .fi .br .RS .LP Types: .RS 3 FullsweepAfter = OldFullsweepAfter = integer() >= 0 .br .RE .RE .RS .LP Changes the maximum number of generational collections before forcing a fullsweep for the calling process\&. .LP Returns the old value of the flag\&. .RE .LP .nf .B process_flag(Flag :: min_heap_size, MinHeapSize) -> OldMinHeapSize .br .fi .br .RS .LP Types: .RS 3 MinHeapSize = OldMinHeapSize = integer() >= 0 .br .RE .RE .RS .LP Changes the minimum heap size for the calling process\&. .LP Returns the old value of the flag\&. .RE .LP .nf .B process_flag(Flag :: min_bin_vheap_size, MinBinVHeapSize) -> .B OldMinBinVHeapSize .br .fi .br .RS .LP Types: .RS 3 MinBinVHeapSize = OldMinBinVHeapSize = integer() >= 0 .br .RE .RE .RS .LP Changes the minimum binary virtual heap size for the calling process\&. .LP Returns the old value of the flag\&. .RE .LP .nf .B process_flag(Flag :: max_heap_size, MaxHeapSize) -> OldMaxHeapSize .br .fi .br .RS .LP Types: .RS 3 MaxHeapSize = OldMaxHeapSize = max_heap_size() .br .nf \fBmax_heap_size()\fR\& = .br integer() >= 0 | .br #{size => integer() >= 0, .br kill => boolean(), .br error_logger => boolean()} .fi .br .RE .RE .RS .LP This flag sets the maximum heap size for the calling process\&. If \fIMaxHeapSize\fR\& is an integer, the system default values for \fIkill\fR\& and \fIerror_logger\fR\& are used\&. .LP For details on how the heap grows, see Sizing the heap in the ERTS internal documentation\&. .RS 2 .TP 2 .B \fIsize\fR\&: The maximum size in words of the process\&. If set to zero, the heap size limit is disabled\&. \fIbadarg\fR\& is be thrown if the value is smaller than \fImin_heap_size\fR\&\&. The size check is only done when a garbage collection is triggered\&. .RS 2 .LP \fIsize\fR\& is the entire heap of the process when garbage collection is triggered\&. This includes all generational heaps, the process stack, any messages that are considered to be part of the heap, and any extra memory that the garbage collector needs during collection\&. .RE .RS 2 .LP \fIsize\fR\& is the same as can be retrieved using \fIerlang:process_info(Pid, total_heap_size)\fR\&, or by adding \fIheap_block_size\fR\&, \fIold_heap_block_size\fR\& and \fImbuf_size\fR\& from \fIerlang:process_info(Pid, garbage_collection_info)\fR\&\&. .RE .TP 2 .B \fIkill\fR\&: When set to \fItrue\fR\&, the runtime system sends an untrappable exit signal with reason \fIkill\fR\& to the process if the maximum heap size is reached\&. The garbage collection that triggered the \fIkill\fR\& is not completed, instead the process exits as soon as possible\&. When set to \fIfalse\fR\&, no exit signal is sent to the process, instead it continues executing\&. .RS 2 .LP If \fIkill\fR\& is not defined in the map, the system default will be used\&. The default system default is \fItrue\fR\&\&. It can be changed by either option +hmaxk in \fIerl(1)\fR\&, or \fIerlang:system_flag(max_heap_size, MaxHeapSize)\fR\&\&. .RE .TP 2 .B \fIerror_logger\fR\&: When set to \fItrue\fR\&, the runtime system logs an error event via \fIlogger\fR\&, containing details about the process when the maximum heap size is reached\&. One log event is sent each time the limit is reached\&. .RS 2 .LP If \fIerror_logger\fR\& is not defined in the map, the system default is used\&. The default system default is \fItrue\fR\&\&. It can be changed by either the option +hmaxel int \fIerl(1)\fR\&, or \fIerlang:system_flag(max_heap_size, MaxHeapSize)\fR\&\&. .RE .RE .LP The heap size of a process is quite hard to predict, especially the amount of memory that is used during the garbage collection\&. When contemplating using this option, it is recommended to first run it in production with \fIkill\fR\& set to \fIfalse\fR\& and inspect the log events to see what the normal peak sizes of the processes in the system is and then tune the value accordingly\&. .RE .LP .nf .B process_flag(Flag :: message_queue_data, MQD) -> OldMQD .br .fi .br .RS .LP Types: .RS 3 MQD = OldMQD = message_queue_data() .br .nf \fBmessage_queue_data()\fR\& = off_heap | on_heap .fi .br .RE .RE .RS .LP Determines how messages in the message queue are stored, as follows: .RS 2 .TP 2 .B \fIoff_heap\fR\&: \fIAll\fR\& messages in the message queue will be stored outside the process heap\&. This implies that \fIno\fR\& messages in the message queue will be part of a garbage collection of the process\&. .TP 2 .B \fIon_heap\fR\&: All messages in the message queue will eventually be placed on the process heap\&. They can, however, be temporarily stored off the heap\&. This is how messages have always been stored up until ERTS 8\&.0\&. .RE .LP The default value of the \fImessage_queue_data\fR\& process flag is determined by the command-line argument \fI+hmqd\fR\& in \fIerl(1)\fR\&\&. .LP If the process may potentially accumulate a large number of messages in its queue it is recommended to set the flag value to \fIoff_heap\fR\&\&. This is due to the fact that the garbage collection of a process that has a large number of messages stored on the heap can become extremely expensive and the process can consume large amounts of memory\&. The performance of the actual message passing is, however, generally better when the flag value is \fIon_heap\fR\&\&. .LP Changing the flag value causes any existing messages to be moved\&. The move operation is initiated, but not necessarily completed, by the time the function returns\&. .LP Returns the old value of the flag\&. .RE .LP .nf .B process_flag(Flag :: priority, Level) -> OldLevel .br .fi .br .RS .LP Types: .RS 3 Level = OldLevel = priority_level() .br .nf \fBpriority_level()\fR\& = low | normal | high | max .fi .br .RE .RE .RS .LP Sets the process priority\&. \fILevel\fR\& is an atom\&. Four priority levels exist: \fIlow\fR\&, \fInormal\fR\&, \fIhigh\fR\&, and \fImax\fR\&\&. Default is \fInormal\fR\&\&. .LP .RS -4 .B Note: .RE Priority level \fImax\fR\& is reserved for internal use in the Erlang runtime system, and is \fInot\fR\& to be used by others\&. .LP Internally in each priority level, processes are scheduled in a round robin fashion\&. .LP Execution of processes on priority \fInormal\fR\& and \fIlow\fR\& are interleaved\&. Processes on priority \fIlow\fR\& are selected for execution less frequently than processes on priority \fInormal\fR\&\&. .LP When runnable processes on priority \fIhigh\fR\& exist, no processes on priority \fIlow\fR\& or \fInormal\fR\& are selected for execution\&. Notice however that this does \fInot\fR\& mean that no processes on priority \fIlow\fR\& or \fInormal\fR\& can run when processes are running on priority \fIhigh\fR\&\&. When using multiple schedulers, more processes can be running in parallel than processes on priority \fIhigh\fR\&\&. That is, a \fIlow\fR\& and a \fIhigh\fR\& priority process can execute at the same time\&. .LP When runnable processes on priority \fImax\fR\& exist, no processes on priority \fIlow\fR\&, \fInormal\fR\&, or \fIhigh\fR\& are selected for execution\&. As with priority \fIhigh\fR\&, processes on lower priorities can execute in parallel with processes on priority \fImax\fR\&\&. .LP Scheduling is pre-emptive\&. Regardless of priority, a process is pre-empted when it has consumed more than a certain number of reductions since the last time it was selected for execution\&. .LP .RS -4 .B Note: .RE Do not depend on the scheduling to remain exactly as it is today\&. Scheduling is likely to be changed in a future release to use available processor cores better\&. .LP There is \fIno\fR\& automatic mechanism for avoiding priority inversion, such as priority inheritance or priority ceilings\&. When using priorities, take this into account and handle such scenarios by yourself\&. .LP Making calls from a \fIhigh\fR\& priority process into code that you has no control over can cause the \fIhigh\fR\& priority process to wait for a process with lower priority\&. That is, effectively decreasing the priority of the \fIhigh\fR\& priority process during the call\&. Even if this is not the case with one version of the code that you have no control over, it can be the case in a future version of it\&. This can, for example, occur if a \fIhigh\fR\& priority process triggers code loading, as the code server runs on priority \fInormal\fR\&\&. .LP Other priorities than \fInormal\fR\& are normally not needed\&. When other priorities are used, use them with care, \fIespecially\fR\& priority \fIhigh\fR\&\&. A process on priority \fIhigh\fR\& is only to perform work for short periods\&. Busy looping for long periods in a \fIhigh\fR\& priority process causes most likely problems, as important OTP servers run on priority \fInormal\fR\&\&. .LP Returns the old value of the flag\&. .RE .LP .nf .B process_flag(Flag :: save_calls, N) -> OldN .br .fi .br .RS .LP Types: .RS 3 N = OldN = 0\&.\&.10000 .br .RE .RE .RS .LP \fIN\fR\& must be an integer in the interval 0\&.\&.10000\&. If \fIN\fR\& > 0, call saving is made active for the process\&. This means that information about the \fIN\fR\& most recent global function calls, BIF calls, sends, and receives made by the process are saved in a list, which can be retrieved with \fIprocess_info(Pid, last_calls)\fR\&\&. A global function call is one in which the module of the function is explicitly mentioned\&. Only a fixed amount of information is saved, as follows: .RS 2 .TP 2 * A tuple \fI{Module, Function, Arity}\fR\& for function calls .LP .TP 2 * The atoms \fIsend\fR\&, \fI\&'receive\&'\fR\&, and \fItimeout\fR\& for sends and receives (\fI\&'receive\&'\fR\& when a message is received and \fItimeout\fR\& when a receive times out) .LP .RE .LP If \fIN\fR\& = 0, call saving is disabled for the process, which is the default\&. Whenever the size of the call saving list is set, its contents are reset\&. .LP Returns the old value of the flag\&. .RE .LP .nf .B process_flag(Flag :: sensitive, Boolean) -> OldBoolean .br .fi .br .RS .LP Types: .RS 3 Boolean = OldBoolean = boolean() .br .RE .RE .RS .LP Sets or clears flag \fIsensitive\fR\& for the current process\&. When a process has been marked as sensitive by calling \fIprocess_flag(sensitive, true)\fR\&, features in the runtime system that can be used for examining the data or inner working of the process are silently disabled\&. .LP Features that are disabled include (but are not limited to) the following: .RS 2 .TP 2 * Tracing\&. Trace flags can still be set for the process, but no trace messages of any kind are generated\&. (If flag \fIsensitive\fR\& is turned off, trace messages are again generated if any trace flags are set\&.) .LP .TP 2 * Sequential tracing\&. The sequential trace token is propagated as usual, but no sequential trace messages are generated\&. .LP .RE .LP \fIprocess_info/1,2\fR\& cannot be used to read out the message queue or the process dictionary (both are returned as empty lists)\&. .LP Stack back-traces cannot be displayed for the process\&. .LP In crash dumps, the stack, messages, and the process dictionary are omitted\&. .LP If \fI{save_calls,N}\fR\& has been set for the process, no function calls are saved to the call saving list\&. (The call saving list is not cleared\&. Also, send, receive, and time-out events are still added to the list\&.) .LP Returns the old value of the flag\&. .RE .LP .nf .B process_flag(Pid, Flag, Value) -> OldValue .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br Flag = save_calls .br Value = OldValue = integer() >= 0 .br .RE .RE .RS .LP Sets certain flags for the process \fIPid\fR\&, in the same manner as \fIprocess_flag/2\fR\&\&. Returns the old value of the flag\&. The valid values for \fIFlag\fR\& are only a subset of those allowed in \fIprocess_flag/2\fR\&, namely \fIsave_calls\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPid\fR\& is not a local process\&. .RE .LP .nf .B process_info(Pid) -> Info .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br Info = [InfoTuple] | undefined .br InfoTuple = process_info_result_item() .br .nf \fBprocess_info_result_item()\fR\& = .br {async_dist, Enabled :: boolean()} | .br {backtrace, Bin :: binary()} | .br {binary, .br BinInfo :: .br [{integer() >= 0, .br integer() >= 0, .br integer() >= 0}]} | .br {catchlevel, CatchLevel :: integer() >= 0} | .br {current_function, .br {Module :: module(), Function :: atom(), Arity :: arity()} | .br undefined} | .br {current_location, .br {Module :: module(), .br Function :: atom(), .br Arity :: arity(), .br Location :: .br [{file, Filename :: string()} | .br {line, Line :: integer() >= 1}]}} | .br {current_stacktrace, Stack :: [stack_item()]} | .br {dictionary, Dictionary :: [{Key :: term(), Value :: term()}]} | .br {error_handler, Module :: module()} | .br {garbage_collection, GCInfo :: [{atom(), integer() >= 0}]} | .br {garbage_collection_info, .br GCInfo :: [{atom(), integer() >= 0}]} | .br {group_leader, GroupLeader :: pid()} | .br {heap_size, Size :: integer() >= 0} | .br {initial_call, mfa()} | .br {links, PidsAndPorts :: [pid() | port()]} | .br {last_calls, false | (Calls :: [mfa()])} | .br {memory, Size :: integer() >= 0} | .br {message_queue_len, MessageQueueLen :: integer() >= 0} | .br {messages, MessageQueue :: [term()]} | .br {min_heap_size, MinHeapSize :: integer() >= 0} | .br {min_bin_vheap_size, MinBinVHeapSize :: integer() >= 0} | .br {max_heap_size, MaxHeapSize :: max_heap_size()} | .br {monitored_by, .br MonitoredBy :: [pid() | port() | nif_resource()]} | .br {monitors, .br Monitors :: .br [{process | port, .br Pid :: .br pid() | .br port() | .br {RegName :: atom(), Node :: node()}}]} | .br {message_queue_data, MQD :: message_queue_data()} | .br {parent, pid() | undefined} | .br {priority, Level :: priority_level()} | .br {reductions, Number :: integer() >= 0} | .br {registered_name, [] | (Atom :: atom())} | .br {sequential_trace_token, .br [] | (SequentialTraceToken :: term())} | .br {stack_size, Size :: integer() >= 0} | .br {status, .br Status :: .br exiting | garbage_collecting | waiting | running | .br runnable | suspended} | .br {suspending, .br SuspendeeList :: .br [{Suspendee :: pid(), .br ActiveSuspendCount :: integer() >= 0, .br OutstandingSuspendCount :: integer() >= 0}]} | .br {total_heap_size, Size :: integer() >= 0} | .br {trace, InternalTraceFlags :: integer() >= 0} | .br {trap_exit, Boolean :: boolean()} .fi .br .nf \fBpriority_level()\fR\& = low | normal | high | max .fi .br .nf \fBstack_item()\fR\& = .br {Module :: module(), .br Function :: atom(), .br Arity :: arity() | (Args :: [term()]), .br Location :: .br [{file, Filename :: string()} | .br {line, Line :: integer() >= 1}]} .fi .br .nf \fBmax_heap_size()\fR\& = .br integer() >= 0 | .br #{size => integer() >= 0, .br kill => boolean(), .br error_logger => boolean()} .fi .br .nf \fBmessage_queue_data()\fR\& = off_heap | on_heap .fi .br .RE .RE .RS .LP Returns a list containing \fIInfoTuple\fR\&s with miscellaneous information about the process identified by \fIPid\fR\&, or \fIundefined\fR\& if the process is not alive\&. .LP The order of the \fIInfoTuple\fR\&s is undefined and all \fIInfoTuple\fR\&s are not mandatory\&. The \fIInfoTuple\fR\&s part of the result can be changed without prior notice\&. .LP The \fIInfoTuple\fR\&s with the following items are part of the result: .RS 2 .TP 2 * \fIcurrent_function\fR\& .LP .TP 2 * \fIinitial_call\fR\& .LP .TP 2 * \fIstatus\fR\& .LP .TP 2 * \fImessage_queue_len\fR\& .LP .TP 2 * \fIlinks\fR\& .LP .TP 2 * \fIdictionary\fR\& .LP .TP 2 * \fItrap_exit\fR\& .LP .TP 2 * \fIerror_handler\fR\& .LP .TP 2 * \fIpriority\fR\& .LP .TP 2 * \fIgroup_leader\fR\& .LP .TP 2 * \fItotal_heap_size\fR\& .LP .TP 2 * \fIheap_size\fR\& .LP .TP 2 * \fIstack_size\fR\& .LP .TP 2 * \fIreductions\fR\& .LP .TP 2 * \fIgarbage_collection\fR\& .LP .RE .LP If the process identified by \fIPid\fR\& has a registered name, also an \fIInfoTuple\fR\& with item \fIregistered_name\fR\& is included\&. .LP For information about specific \fIInfoTuple\fR\&s, see \fIprocess_info/2\fR\&\&. .LP .RS -4 .B Warning: .RE This BIF is intended for \fIdebugging only\fR\&\&. For all other purposes, use \fIprocess_info/2\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fIPid\fR\& is not a local process\&. .RE .LP .nf .B process_info(Pid, Item) -> InfoTuple | [] | undefined .br .fi .br .nf .B process_info(Pid, ItemList) -> InfoTupleList | [] | undefined .br .fi .br .RS .LP Types: .RS 3 Pid = pid() .br ItemList = [Item] .br Item = process_info_item() .br InfoTupleList = [InfoTuple] .br InfoTuple = process_info_result_item() .br .nf \fBprocess_info_item()\fR\& = .br async_dist | backtrace | binary | catchlevel | .br current_function | current_location | current_stacktrace | .br dictionary | error_handler | garbage_collection | .br garbage_collection_info | group_leader | heap_size | .br initial_call | links | last_calls | memory | .br message_queue_len | messages | min_heap_size | .br min_bin_vheap_size | monitored_by | monitors | .br message_queue_data | parent | priority | reductions | .br registered_name | sequential_trace_token | stack_size | .br status | suspending | total_heap_size | trace | trap_exit .fi .br .nf \fBprocess_info_result_item()\fR\& = .br {async_dist, Enabled :: boolean()} | .br {backtrace, Bin :: binary()} | .br {binary, .br BinInfo :: .br [{integer() >= 0, .br integer() >= 0, .br integer() >= 0}]} | .br {catchlevel, CatchLevel :: integer() >= 0} | .br {current_function, .br {Module :: module(), Function :: atom(), Arity :: arity()} | .br undefined} | .br {current_location, .br {Module :: module(), .br Function :: atom(), .br Arity :: arity(), .br Location :: .br [{file, Filename :: string()} | .br {line, Line :: integer() >= 1}]}} | .br {current_stacktrace, Stack :: [stack_item()]} | .br {dictionary, Dictionary :: [{Key :: term(), Value :: term()}]} | .br {error_handler, Module :: module()} | .br {garbage_collection, GCInfo :: [{atom(), integer() >= 0}]} | .br {garbage_collection_info, .br GCInfo :: [{atom(), integer() >= 0}]} | .br {group_leader, GroupLeader :: pid()} | .br {heap_size, Size :: integer() >= 0} | .br {initial_call, mfa()} | .br {links, PidsAndPorts :: [pid() | port()]} | .br {last_calls, false | (Calls :: [mfa()])} | .br {memory, Size :: integer() >= 0} | .br {message_queue_len, MessageQueueLen :: integer() >= 0} | .br {messages, MessageQueue :: [term()]} | .br {min_heap_size, MinHeapSize :: integer() >= 0} | .br {min_bin_vheap_size, MinBinVHeapSize :: integer() >= 0} | .br {max_heap_size, MaxHeapSize :: max_heap_size()} | .br {monitored_by, .br MonitoredBy :: [pid() | port() | nif_resource()]} | .br {monitors, .br Monitors :: .br [{process | port, .br Pid :: .br pid() | .br port() | .br {RegName :: atom(), Node :: node()}}]} | .br {message_queue_data, MQD :: message_queue_data()} | .br {parent, pid() | undefined} | .br {priority, Level :: priority_level()} | .br {reductions, Number :: integer() >= 0} | .br {registered_name, [] | (Atom :: atom())} | .br {sequential_trace_token, .br [] | (SequentialTraceToken :: term())} | .br {stack_size, Size :: integer() >= 0} | .br {status, .br Status :: .br exiting | garbage_collecting | waiting | running | .br runnable | suspended} | .br {suspending, .br SuspendeeList :: .br [{Suspendee :: pid(), .br ActiveSuspendCount :: integer() >= 0, .br OutstandingSuspendCount :: integer() >= 0}]} | .br {total_heap_size, Size :: integer() >= 0} | .br {trace, InternalTraceFlags :: integer() >= 0} | .br {trap_exit, Boolean :: boolean()} .fi .br .nf \fBstack_item()\fR\& = .br {Module :: module(), .br Function :: atom(), .br Arity :: arity() | (Args :: [term()]), .br Location :: .br [{file, Filename :: string()} | .br {line, Line :: integer() >= 1}]} .fi .br .nf \fBpriority_level()\fR\& = low | normal | high | max .fi .br .nf \fBmax_heap_size()\fR\& = .br integer() >= 0 | .br #{size => integer() >= 0, .br kill => boolean(), .br error_logger => boolean()} .fi .br .nf \fBmessage_queue_data()\fR\& = off_heap | on_heap .fi .br .RE .RE .RS .LP Returns information about the process identified by \fIPid\fR\&, as specified by \fIItem\fR\& or \fIItemList\fR\&\&. Returns \fIundefined\fR\& if the process is not alive\&. .LP If the process is alive and a single \fIItem\fR\& is specified, the returned value is the corresponding \fIInfoTuple\fR\&, unless \fIItem =:= registered_name\fR\& and the process has no registered name\&. In this case, \fI[]\fR\& is returned\&. This strange behavior is because of historical reasons, and is kept for backward compatibility\&. .LP If \fIItemList\fR\& is specified, the result is \fIInfoTupleList\fR\&\&. The \fIInfoTuple\fR\&s in \fIInfoTupleList\fR\& are included with the corresponding \fIItem\fR\&s in the same order as the \fIItem\fR\&s were included in \fIItemList\fR\&\&. Valid \fIItem\fR\&s can be included multiple times in \fIItemList\fR\&\&. .LP Getting process information follows the signal ordering guarantees described in the Processes Chapter in the \fIErlang Reference Manual\fR\& \&. .LP .RS -4 .B Note: .RE If \fIregistered_name\fR\& is part of \fIItemList\fR\& and the process has no name registered, a \fI{registered_name, []}\fR\&, \fIInfoTuple\fR\& \fIwill\fR\& be included in the resulting \fIInfoTupleList\fR\&\&. This behavior is different when a single \fIItem =:= registered_name\fR\& is specified, and when \fIprocess_info/1\fR\& is used\&. .LP Valid \fIInfoTuple\fR\&s with corresponding \fIItem\fR\&s: .RS 2 .TP 2 .B \fI{async_dist, Enabled}\fR\&: Since: OTP 25\&.3 .RS 2 .LP Current value of the \fIasync_dist\fR\& process flag\&. .RE .TP 2 .B \fI{backtrace, Bin}\fR\&: Binary \fIBin\fR\& contains the same information as the output from \fIerlang:process_display(Pid, backtrace)\fR\&\&. Use \fIbinary_to_list/1\fR\& to obtain the string of characters from the binary\&. .TP 2 .B \fI{binary, BinInfo}\fR\&: \fIBinInfo\fR\& is a list containing miscellaneous information about binaries on the heap of this process\&. This \fIInfoTuple\fR\& can be changed or removed without prior notice\&. In the current implementation \fIBinInfo\fR\& is a list of tuples\&. The tuples contain; \fIBinaryId\fR\&, \fIBinarySize\fR\&, \fIBinaryRefcCount\fR\&\&. .RS 2 .LP Depending on the value of the \fImessage_queue_data\fR\& process flag the message queue may be stored on the heap\&. .RE .TP 2 .B \fI{catchlevel, CatchLevel}\fR\&: \fICatchLevel\fR\& is the number of currently active catches in this process\&. This \fIInfoTuple\fR\& can be changed or removed without prior notice\&. .TP 2 .B \fI{current_function, {Module, Function, Arity} | undefined}\fR\&: \fIModule\fR\&, \fIFunction\fR\&, \fIArity\fR\& is the current function call of the process\&. The value \fIundefined\fR\& can be returned if the process is currently executing native compiled code\&. .TP 2 .B \fI{current_location, {Module, Function, Arity, Location}}\fR\&: \fIModule\fR\&, \fIFunction\fR\&, \fIArity\fR\& is the current function call of the process\&. \fILocation\fR\& is a list of two-tuples describing the location in the source code\&. .TP 2 .B \fI{current_stacktrace, Stack}\fR\&: Returns the current call stack back-trace (\fIstacktrace\fR\&) of the process\&. The stack has the same format as in the \fIcatch\fR\& part of a \fItry\fR\&\&. See The call-stack back trace (stacktrace)\&. The depth of the stacktrace is truncated according to the \fIbacktrace_depth\fR\& system flag setting\&. .TP 2 .B \fI{dictionary, Dictionary}\fR\&: \fIDictionary\fR\& is the process dictionary\&. .TP 2 .B \fI{error_handler, Module}\fR\&: \fIModule\fR\& is the error handler module used by the process (for undefined function calls, for example)\&. .TP 2 .B \fI{garbage_collection, GCInfo}\fR\&: \fIGCInfo\fR\& is a list containing miscellaneous information about garbage collection for this process\&. The content of \fIGCInfo\fR\& can be changed without prior notice\&. .TP 2 .B \fI{garbage_collection_info, GCInfo}\fR\&: \fIGCInfo\fR\& is a list containing miscellaneous detailed information about garbage collection for this process\&. The content of \fIGCInfo\fR\& can be changed without prior notice\&. For details about the meaning of each item, see \fIgc_minor_start\fR\& in \fIerlang:trace/3\fR\&\&. .TP 2 .B \fI{group_leader, GroupLeader}\fR\&: \fIGroupLeader\fR\& is the group leader for the I/O of the process\&. .TP 2 .B \fI{heap_size, Size}\fR\&: \fISize\fR\& is the size in words of the youngest heap generation of the process\&. This generation includes the process stack\&. This information is highly implementation-dependent, and can change if the implementation changes\&. .TP 2 .B \fI{initial_call, {Module, Function, Arity}}\fR\&: \fIModule\fR\&, \fIFunction\fR\&, \fIArity\fR\& is the initial function call with which the process was spawned\&. .TP 2 .B \fI{links, PidsAndPorts}\fR\&: \fIPidsAndPorts\fR\& is a list of process identifiers and port identifiers, with processes or ports to which the process has a link\&. .TP 2 .B \fI{last_calls, false|Calls}\fR\&: The value is \fIfalse\fR\& if call saving is not active for the process (see \fIprocess_flag/3\fR\&)\&. If call saving is active, a list is returned, in which the last element is the most recent called\&. .TP 2 .B \fI{memory, Size}\fR\&: .RS 2 .LP \fISize\fR\& is the size in bytes of the process\&. This includes call stack, heap, and internal structures\&. .RE .TP 2 .B \fI{message_queue_len, MessageQueueLen}\fR\&: \fIMessageQueueLen\fR\& is the number of messages currently in the message queue of the process\&. This is the length of the list \fIMessageQueue\fR\& returned as the information item \fImessages\fR\& (see below)\&. .TP 2 .B \fI{messages, MessageQueue}\fR\&: \fIMessageQueue\fR\& is a list of the messages to the process, which have not yet been processed\&. .TP 2 .B \fI{min_heap_size, MinHeapSize}\fR\&: \fIMinHeapSize\fR\& is the minimum heap size for the process\&. .TP 2 .B \fI{min_bin_vheap_size, MinBinVHeapSize}\fR\&: \fIMinBinVHeapSize\fR\& is the minimum binary virtual heap size for the process\&. .TP 2 .B \fI{monitored_by, MonitoredBy}\fR\&: A list of identifiers for all the processes, ports and NIF resources, that are monitoring the process\&. .TP 2 .B \fI{monitors, Monitors}\fR\&: A list of monitors (started by \fImonitor/2\fR\&) that are active for the process\&. For a local process monitor or a remote process monitor by a process identifier, the list consists of: .RS 2 .TP 2 .B \fI{process, Pid}\fR\&: Process is monitored by pid\&. .TP 2 .B \fI{process, {RegName, Node}}\fR\&: Local or remote process is monitored by name\&. .TP 2 .B \fI{port, PortId}\fR\&: Local port is monitored by port id\&. .TP 2 .B \fI{port, {RegName, Node}}\fR\&: Local port is monitored by name\&. Please note, that remote port monitors are not supported, so \fINode\fR\& will always be the local node name\&. .RE .TP 2 .B \fI{message_queue_data, MQD}\fR\&: \fIMQD\fR\& is the current value of the \fImessage_queue_data\fR\& process flag, which can be either \fIoff_heap\fR\& or \fIon_heap\fR\&\&. For more information, see the documentation of \fIprocess_flag(message_queue_data, MQD)\fR\&\&. .TP 2 .B \fI{parent, Pid}\fR\&: \fIPid\fR\& is the identifier of the parent process, the one that spawned current process\&. When the process does not have a parent \fIundefined\fR\& is returned\&. Only the initial process (\fIinit\fR\&) on a node lacks a parent, though\&. .TP 2 .B \fI{priority, Level}\fR\&: \fILevel\fR\& is the current priority level for the process\&. For more information on priorities, see \fIprocess_flag(priority, Level)\fR\&\&. .TP 2 .B \fI{reductions, Number}\fR\&: \fINumber\fR\& is the number of reductions executed by the process\&. .TP 2 .B \fI{registered_name, Atom}\fR\&: \fIAtom\fR\& is the registered process name\&. If the process has no registered name, this tuple is not present in the list\&. .TP 2 .B \fI{sequential_trace_token, [] | SequentialTraceToken}\fR\&: \fISequentialTraceToken\fR\& is the sequential trace token for the process\&. This \fIInfoTuple\fR\& can be changed or removed without prior notice\&. .TP 2 .B \fI{stack_size, Size}\fR\&: \fISize\fR\& is the stack size, in words, of the process\&. .TP 2 .B \fI{status, Status}\fR\&: \fIStatus\fR\& is the status of the process and is one of the following: .RS 2 .TP 2 * \fIexiting\fR\& .LP .TP 2 * \fIgarbage_collecting\fR\& .LP .TP 2 * \fIwaiting\fR\& (for a message) .LP .TP 2 * \fIrunning\fR\& .LP .TP 2 * \fIrunnable\fR\& (ready to run, but another process is running) .LP .TP 2 * \fIsuspended\fR\& (suspended on a "busy" port or by the BIF \fIerlang:suspend_process/1,2\fR\&) .LP .RE .TP 2 .B \fI{suspending, SuspendeeList}\fR\&: \fISuspendeeList\fR\& is a list of \fI{Suspendee, ActiveSuspendCount, OutstandingSuspendCount}\fR\& tuples\&. \fISuspendee\fR\& is the process identifier of a process that has been, or is to be, suspended by the process identified by \fIPid\fR\& through the BIF \fIerlang:suspend_process/2\fR\& or \fIerlang:suspend_process/1\fR\&\&. .RS 2 .LP \fIActiveSuspendCount\fR\& is the number of times \fISuspendee\fR\& has been suspended by \fIPid\fR\&\&. \fIOutstandingSuspendCount\fR\& is the number of not yet completed suspend requests sent by \fIPid\fR\&, that is: .RE .RS 2 .TP 2 * If \fIActiveSuspendCount =/= 0\fR\&, \fISuspendee\fR\& is currently in the suspended state\&. .LP .TP 2 * If \fIOutstandingSuspendCount =/= 0\fR\&, option \fIasynchronous\fR\& of \fIerlang:suspend_process/2\fR\& has been used and the suspendee has not yet been suspended by \fIPid\fR\&\&. .LP .RE .RS 2 .LP Notice that \fIActiveSuspendCount\fR\& and \fIOutstandingSuspendCount\fR\& are not the total suspend count on \fISuspendee\fR\&, only the parts contributed by \fIPid\fR\&\&. .RE .TP 2 .B \fI{total_heap_size, Size}\fR\&: \fISize\fR\& is the total size, in words, of all heap fragments of the process\&. This includes the process stack and any unreceived messages that are considered to be part of the heap\&. .TP 2 .B \fI{trace, InternalTraceFlags}\fR\&: \fIInternalTraceFlags\fR\& is an integer representing the internal trace flag for this process\&. This \fIInfoTuple\fR\& can be changed or removed without prior notice\&. .TP 2 .B \fI{trap_exit, Boolean}\fR\&: \fIBoolean\fR\& is \fItrue\fR\& if the process is trapping exits, otherwise \fIfalse\fR\&\&. .RE .LP Notice that not all implementations support all these \fIItem\fR\&s\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIPid\fR\& is not a local process\&. .TP 2 .B \fIbadarg\fR\&: If \fIItem\fR\& is an invalid item\&. .RE .RE .LP .nf .B processes() -> [pid()] .br .fi .br .RS .LP Returns a list of process identifiers corresponding to all the processes currently existing on the local node\&. .LP Notice that an exiting process exists, but is not alive\&. That is, \fIis_process_alive/1\fR\& returns \fIfalse\fR\& for an exiting process, but its process identifier is part of the result returned from \fIprocesses/0\fR\&\&. .LP Example: .LP .nf > processes()\&. [<0.0.0>,<0.2.0>,<0.4.0>,<0.5.0>,<0.7.0>,<0.8.0>] .fi .RE .LP .nf .B purge_module(Module) -> true .br .fi .br .RS .LP Types: .RS 3 Module = atom() .br .RE .RE .RS .LP Removes old code for \fIModule\fR\&\&. Before this BIF is used, \fIcheck_process_code/2\fR\& is to be called to check that no processes execute old code in the module\&. .LP .RS -4 .B Warning: .RE This BIF is intended for the code server (see \fIcode(3erl)\fR\&) and is not to be used elsewhere\&. .LP .RS -4 .B Note: .RE As from ERTS 8\&.0 (Erlang/OTP 19), any lingering processes that still execute the old code is killed by this function\&. In earlier versions, such incorrect use could cause much more fatal failures, like emulator crash\&. .LP Failure: \fIbadarg\fR\& if there is no old code for \fIModule\fR\&\&. .RE .LP .nf .B put(Key, Val) -> term() .br .fi .br .RS .LP Types: .RS 3 Key = Val = term() .br .RE .RE .RS .LP Adds a new \fIKey\fR\& to the process dictionary, associated with the value \fIVal\fR\&, and returns \fIundefined\fR\&\&. If \fIKey\fR\& exists, the old value is deleted and replaced by \fIVal\fR\&, and the function returns the old value\&. The average time complexity for the current implementation of this function is O(\fI1\fR\&) and the worst case time complexity is O(\fIN\fR\&), where \fIN\fR\& is the number of items in the process dictionary\&. Example: .LP .nf > X = put(name, walrus), Y = put(name, carpenter), Z = get(name), {X, Y, Z}\&. {undefined,walrus,carpenter} .fi .LP .RS -4 .B Note: .RE The values stored when \fIput\fR\& is evaluated within the scope of a \fIcatch\fR\& are not retracted if a \fIthrow\fR\& is evaluated, or if an error occurs\&. .RE .LP .nf .B erlang:raise(Class, Reason, Stacktrace) -> badarg .br .fi .br .RS .LP Types: .RS 3 Class = error | exit | throw .br Reason = term() .br Stacktrace = raise_stacktrace() | stacktrace() .br .nf \fBraise_stacktrace()\fR\& = .br [{module(), atom(), arity() | [term()]} | .br {function(), arity() | [term()]}] .fi .br .RE .RE .RS .LP Raises an exception of the specified class, reason, and call stack backtrace (\fIstacktrace\fR\&)\&. .LP \fIClass\fR\& is \fIerror\fR\&, \fIexit\fR\&, or \fIthrow\fR\&\&. So, if it were not for the stacktrace, \fIerlang:raise(Class, Reason, Stacktrace)\fR\& is equivalent to \fIerlang:Class(Reason)\fR\& (given that \fIClass\fR\& is a valid class)\&. .LP \fIReason\fR\& can be any term\&. .LP \fIStacktrace\fR\& is a list as provided in a try-catch clause\&. .LP .nf try ... catch Class:Reason:Stacktrace -> ... end .fi .LP That is, a list of four-tuples \fI{Module, Function, Arity | Args, ExtraInfo}\fR\&, where \fIModule\fR\& and \fIFunction\fR\& are atoms, and the third element is an integer arity or an argument list\&. The stacktrace can also contain \fI{Fun, Args, ExtraInfo}\fR\& tuples, where \fIFun\fR\& is a local fun and \fIArgs\fR\& is an argument list\&. .LP Element \fIExtraInfo\fR\& at the end is optional\&. Omitting it is equivalent to specifying an empty list\&. .LP The stacktrace is used as the exception stacktrace for the calling process; it is truncated to the current maximum stacktrace depth\&. .LP As evaluating this function causes the process to terminate, it has no return value unless the arguments are invalid, in which case the function \fIreturns the error reason\fR\& \fIbadarg\fR\&\&. If you want to be sure not to return, you can call \fIerror(erlang:raise(Class, Reason, Stacktrace))\fR\& and hope to distinguish exceptions later\&. .LP See the reference manual about errors and error handling for more information about exception classes and how to catch exceptions\&. .RE .LP .nf .B erlang:read_timer(TimerRef) -> Result .br .fi .br .RS .LP Types: .RS 3 TimerRef = reference() .br Time = integer() >= 0 .br Result = Time | false .br .RE .RE .RS .LP Reads the state of a timer\&. The same as calling \fIerlang:read_timer(TimerRef, [])\fR\&\&. .RE .LP .nf .B erlang:read_timer(TimerRef, Options) -> Result | ok .br .fi .br .RS .LP Types: .RS 3 TimerRef = reference() .br Async = boolean() .br Option = {async, Async} .br Options = [Option] .br Time = integer() >= 0 .br Result = Time | false .br .RE .RE .RS .LP Reads the state of a timer that has been created by either \fIerlang:start_timer\fR\& or \fIerlang:send_after\fR\&\&. \fITimerRef\fR\& identifies the timer, and was returned by the BIF that created the timer\&. .LP \fIOptions\fR\&: .RS 2 .TP 2 .B \fI{async, Async}\fR\&: Asynchronous request for state information\&. \fIAsync\fR\& defaults to \fIfalse\fR\&, which causes the operation to be performed synchronously\&. In this case, the \fIResult\fR\& is returned by \fIerlang:read_timer\fR\&\&. When \fIAsync\fR\& is \fItrue\fR\&, \fIerlang:read_timer\fR\& sends an asynchronous request for the state information to the timer service that manages the timer, and then returns \fIok\fR\&\&. A message on the format \fI{read_timer, TimerRef, Result}\fR\& is sent to the caller of \fIerlang:read_timer\fR\& when the operation has been processed\&. .RE .LP More \fIOption\fR\&s can be added in the future\&. .LP If \fIResult\fR\& is an integer, it represents the time in milliseconds left until the timer expires\&. .LP If \fIResult\fR\& is \fIfalse\fR\&, a timer corresponding to \fITimerRef\fR\& could not be found\&. This because the timer had expired, or been canceled, or because \fITimerRef\fR\& never has corresponded to a timer\&. Even if the timer has expired, it does not tell you whether or not the time-out message has arrived at its destination yet\&. .LP .RS -4 .B Note: .RE The timer service that manages the timer can be co-located with another scheduler than the scheduler that the calling process is executing on\&. If so, communication with the timer service takes much longer time than if it is located locally\&. If the calling process is in a critical path, and can do other things while waiting for the result of this operation, you want to use option \fI{async, true}\fR\&\&. If using option \fI{async, false}\fR\&, the calling process is blocked until the operation has been performed\&. .LP See also \fIerlang:send_after/4\fR\&, \fIerlang:start_timer/4\fR\&, and \fIerlang:cancel_timer/2\fR\&\&. .RE .LP .nf .B ref_to_list(Ref) -> string() .br .fi .br .RS .LP Types: .RS 3 Ref = reference() .br .RE .RE .RS .LP Returns a string corresponding to the text representation of \fIRef\fR\&\&. .LP .RS -4 .B Warning: .RE This BIF is intended for debugging and is not to be used in application programs\&. .RE .LP .nf .B register(RegName, PidOrPort) -> true .br .fi .br .RS .LP Types: .RS 3 RegName = atom() .br PidOrPort = port() | pid() .br .RE .RE .RS .LP Registers the name \fIRegName\fR\& with a process identifier (pid) or a port identifier in the \fIname registry\fR\&\&. \fIRegName\fR\&, which must be an atom, can be used instead of the pid or port identifier in send operator (\fIRegName ! Message\fR\&) and most other BIFs that take a pid or port identifies as an argument\&. Example: .LP .nf > register(db, Pid)\&. true .fi .LP The registered name is considered a Directly Visible Erlang Resource and is automatically unregistered when the process terminates\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIPidOrPort\fR\& is not an existing local process or port\&. .TP 2 .B \fIbadarg\fR\&: If \fIRegName\fR\& is already in use\&. .TP 2 .B \fIbadarg\fR\&: If the process or port is already registered (already has a name)\&. .TP 2 .B \fIbadarg\fR\&: If \fIRegName\fR\& is the atom \fIundefined\fR\&\&. .RE .RE .LP .nf .B registered() -> [RegName] .br .fi .br .RS .LP Types: .RS 3 RegName = atom() .br .RE .RE .RS .LP Returns a list of names that have been registered using \fIregister/2\fR\&, for example: .LP .nf > registered()\&. [code_server, file_server, init, user, my_db] .fi .RE .LP .nf .B erlang:resume_process(Suspendee) -> true .br .fi .br .RS .LP Types: .RS 3 Suspendee = pid() .br .RE .RE .RS .LP Decreases the suspend count on the process identified by \fISuspendee\fR\&\&. \fISuspendee\fR\& is previously to have been suspended through \fIerlang:suspend_process/2\fR\& or \fIerlang:suspend_process/1\fR\& by the process calling \fIerlang:resume_process(Suspendee)\fR\&\&. When the suspend count on \fISuspendee\fR\& reaches zero, \fISuspendee\fR\& is resumed, that is, its state is changed from suspended into the state it had before it was suspended\&. .LP .RS -4 .B Warning: .RE This BIF is intended for debugging only\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fISuspendee\fR\& is not a process identifier\&. .TP 2 .B \fIbadarg\fR\&: If the process calling \fIerlang:resume_process/1\fR\& had not previously increased the suspend count on the process identified by \fISuspendee\fR\&\&. .TP 2 .B \fIbadarg\fR\&: If the process identified by \fISuspendee\fR\& is not alive\&. .RE .RE .LP .nf .B round(Number) -> integer() .br .fi .br .RS .LP Types: .RS 3 Number = number() .br .RE .RE .RS .LP Returns an integer by rounding \fINumber\fR\&, for example: .LP .nf round(42\&.1)\&. 42 .fi .LP .nf round(5\&.5)\&. 6 .fi .LP .nf round(-5\&.5)\&. -6 .fi .LP .nf round(36028797018963969\&.0)\&. 36028797018963968 .fi .LP In the last example, \fIround(36028797018963969\&.0)\fR\& evaluates to \fI36028797018963968\fR\&\&. The reason for this is that the number \fI36028797018963969\&.0\fR\& cannot be represented exactly as a float value\&. Instead, the float literal is represented as \fI36028797018963968\&.0\fR\&, which is the closest number that can be represented exactly as a float value\&. See Representation of Floating Point Numbers for additional information\&. .LP Allowed in guard tests\&. .RE .LP .nf .B self() -> pid() .br .fi .br .RS .LP Returns the process identifier of the calling process, for example: .LP .nf > self()\&. <0.26.0> .fi .LP Allowed in guard tests\&. .RE .LP .nf .B erlang:send(Dest, Msg) -> Msg .br .fi .br .RS .LP Types: .RS 3 Dest = send_destination() .br Msg = term() .br .RE .RE .RS .LP Sends a message and returns \fIMsg\fR\&\&. This is the same as using the send operator: \fIDest ! Msg\fR\&\&. .LP \fIDest\fR\& can be a remote or local process identifier, an alias, a (local) port, a locally registered name, or a tuple \fI{RegName, Node}\fR\& for a registered name at another node\&. .LP The function fails with a \fIbadarg\fR\& run-time error if \fIDest\fR\& is an atom name, but this name is not registered\&. This is the only case when \fIsend\fR\& fails for an unreachable destination \fIDest\fR\& (of correct type)\&. .RE .LP .nf .B erlang:send(Dest, Msg, Options) -> Res .br .fi .br .RS .LP Types: .RS 3 Dest = send_destination() .br Msg = term() .br Options = [nosuspend | noconnect] .br Res = ok | nosuspend | noconnect .br .RE .RE .RS .LP Either sends a message and returns \fIok\fR\&, or does not send the message but returns something else (see below)\&. Otherwise the same as \fIerlang:send/2\fR\&\&. For more detailed explanation and warnings, see \fIerlang:send_nosuspend/2,3\fR\&\&. .LP Options: .RS 2 .TP 2 .B \fInosuspend\fR\&: If the sender would have to be suspended to do the send, \fInosuspend\fR\& is returned instead\&. .TP 2 .B \fInoconnect\fR\&: If the destination node would have to be auto-connected to do the send, \fInoconnect\fR\& is returned instead\&. .RE .LP .RS -4 .B Warning: .RE As with \fIerlang:send_nosuspend/2,3\fR\&: use with extreme care\&. .RE .LP .nf .B erlang:send_after(Time, Dest, Msg) -> TimerRef .br .fi .br .RS .LP Types: .RS 3 Time = integer() >= 0 .br Dest = pid() | atom() .br Msg = term() .br TimerRef = reference() .br .RE .RE .RS .LP Starts a timer\&. The same as calling \fIerlang:send_after(Time, Dest, Msg, [])\fR\&\&. .RE .LP .nf .B erlang:send_after(Time, Dest, Msg, Options) -> TimerRef .br .fi .br .RS .LP Types: .RS 3 Time = integer() .br Dest = pid() | atom() .br Msg = term() .br Options = [Option] .br Abs = boolean() .br Option = {abs, Abs} .br TimerRef = reference() .br .RE .RE .RS .LP Starts a timer\&. When the timer expires, the message \fIMsg\fR\& is sent to the process identified by \fIDest\fR\&\&. Apart from the format of the time-out message, this function works exactly as \fIerlang:start_timer/4\fR\&\&. .RE .LP .nf .B erlang:send_nosuspend(Dest, Msg) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Dest = send_destination() .br Msg = term() .br .RE .RE .RS .LP The same as \fIerlang:send(Dest, Msg, [nosuspend])\fR\&, but returns \fItrue\fR\& if the message was sent and \fIfalse\fR\& if the message was not sent because the sender would have had to be suspended\&. .LP This function is intended for send operations to an unreliable remote node without ever blocking the sending (Erlang) process\&. If the connection to the remote node (usually not a real Erlang node, but a node written in C or Java) is overloaded, this function \fIdoes not send the message\fR\& and returns \fIfalse\fR\&\&. .LP The same occurs if \fIDest\fR\& refers to a local port that is busy\&. For all other destinations (allowed for the ordinary send operator \fI\&'!\&'\fR\&), this function sends the message and returns \fItrue\fR\&\&. .LP This function is only to be used in rare circumstances where a process communicates with Erlang nodes that can disappear without any trace, causing the TCP buffers and the drivers queue to be over-full before the node is shut down (because of tick time-outs) by \fInet_kernel\fR\&\&. The normal reaction to take when this occurs is some kind of premature shutdown of the other node\&. .LP Notice that ignoring the return value from this function would result in an \fIunreliable\fR\& message passing, which is contradictory to the Erlang programming model\&. The message is \fInot\fR\& sent if this function returns \fIfalse\fR\&\&. .LP In many systems, transient states of overloaded queues are normal\&. Although this function returns \fIfalse\fR\& does not mean that the other node is guaranteed to be non-responsive, it could be a temporary overload\&. Also, a return value of \fItrue\fR\& does only mean that the message can be sent on the (TCP) channel without blocking; the message is not guaranteed to arrive at the remote node\&. For a disconnected non-responsive node, the return value is \fItrue\fR\& (mimics the behavior of operator \fI!\fR\&)\&. The expected behavior and the actions to take when the function returns \fIfalse\fR\& are application- and hardware-specific\&. .LP .RS -4 .B Warning: .RE Use with extreme care\&. .RE .LP .nf .B erlang:send_nosuspend(Dest, Msg, Options) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Dest = send_destination() .br Msg = term() .br Options = [noconnect] .br .RE .RE .RS .LP The same as \fIerlang:send(Dest, Msg, [nosuspend | Options])\fR\&, but with a Boolean return value\&. .LP This function behaves like \fIerlang:send_nosuspend/2\fR\&, but takes a third parameter, a list of options\&. The only option is \fInoconnect\fR\&, which makes the function return \fIfalse\fR\& if the remote node is not currently reachable by the local node\&. The normal behavior is to try to connect to the node, which can stall the process during a short period\&. The use of option \fInoconnect\fR\& makes it possible to be sure not to get the slightest delay when sending to a remote process\&. This is especially useful when communicating with nodes that expect to always be the connecting part (that is, nodes written in C or Java)\&. .LP Whenever the function returns \fIfalse\fR\& (either when a suspend would occur or when \fInoconnect\fR\& was specified and the node was not already connected), the message is guaranteed \fInot\fR\& to have been sent\&. .LP .RS -4 .B Warning: .RE Use with extreme care\&. .RE .LP .nf .B erlang:set_cookie(Cookie) -> true .br .fi .br .RS .LP Types: .RS 3 Cookie = atom() .br .RE .RE .RS .LP Sets the magic cookie of the local node to the atom \fICookie\fR\&, which is also the cookie for all nodes that have no explicit cookie set with \fIset_cookie/2\fR\& \fICookie\fR\& (see section Distributed Erlang in the Erlang Reference Manual in System Documentation)\&. .LP You can get this value using \fIget_cookie/0\fR\&\&. .LP Failure: \fIfunction_clause\fR\& if the local node is not alive\&. .RE .LP .nf .B erlang:set_cookie(Node, Cookie) -> true .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Cookie = atom() .br .RE .RE .RS .LP Sets the magic cookie for \fINode\fR\& to the atom \fICookie\fR\&\&. If \fINode\fR\& is the local node, the function sets the cookie of all other nodes (that have no explicit cookie set with this function) to \fICookie\fR\& (see section Distributed Erlang in the Erlang Reference Manual in System Documentation)\&. .LP You can get this value using \fIget_cookie/1\fR\&\&. .LP Failure: \fIfunction_clause\fR\& if the local node is not alive\&. .RE .LP .nf .B setelement(Index, Tuple1, Value) -> Tuple2 .br .fi .br .RS .LP Types: .RS 3 Index = integer() >= 1 .br .RS 2 1\&.\&.tuple_size(Tuple1) .RE Tuple1 = Tuple2 = tuple() .br Value = term() .br .RE .RE .RS .LP Returns a tuple that is a copy of argument \fITuple1\fR\& with the element specified by integer argument \fIIndex\fR\& (the first element is the element with index 1) replaced by argument \fIValue\fR\&, for example: .LP .nf > setelement(2, {10, green, bottles}, red)\&. {10,red,bottles} .fi .RE .LP .nf .B size(Item) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Item = tuple() | binary() .br .RE .RE .RS .LP Returns the number of elements in a tuple or the number of bytes in a binary or bitstring, for example: .LP .nf > size({morni, mulle, bwange})\&. 3 > size(<<11, 22, 33>>)\&. 3 .fi .LP For bitstrings, the number of whole bytes is returned\&. That is, if the number of bits in the bitstring is not divisible by 8, the resulting number of bytes is rounded \fIdown\fR\&\&. .LP Allowed in guard tests\&. .LP See also \fItuple_size/1\fR\&, \fIbyte_size/1\fR\&, and \fIbit_size/1\fR\&\&. .RE .LP .nf .B spawn(Fun) -> pid() .br .fi .br .RS .LP Types: .RS 3 Fun = function() .br .RE .RE .RS .LP Returns the process identifier of a new process started by the application of \fIFun\fR\& to the empty list \fI[]\fR\&\&. Otherwise works like \fIspawn/3\fR\&\&. .RE .LP .nf .B spawn(Node, Fun) -> pid() .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Fun = function() .br .RE .RE .RS .LP Returns the process identifier of a new process started by the application of \fIFun\fR\& to the empty list \fI[]\fR\& on \fINode\fR\&\&. If \fINode\fR\& does not exist, a useless pid is returned\&. Otherwise works like \fIspawn/3\fR\&\&. .RE .LP .nf .B spawn(Module, Function, Args) -> pid() .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Returns the process identifier of a new process started by the application of \fIModule:Function\fR\& to \fIArgs\fR\&\&. .LP \fIerror_handler:undefined_function(Module, Function, Args)\fR\& is evaluated by the new process if \fIModule:Function/Arity\fR\& does not exist (where \fIArity\fR\& is the length of \fIArgs\fR\&)\&. The error handler can be redefined (see \fIprocess_flag/2\fR\&)\&. If \fIerror_handler\fR\& is undefined, or the user has redefined the default \fIerror_handler\fR\& and its replacement is undefined, a failure with reason \fIundef\fR\& occurs\&. .LP Example: .LP .nf > spawn(speed, regulator, [high_speed, thin_cut])\&. <0.13.1> .fi .RE .LP .nf .B spawn(Node, Module, Function, Args) -> pid() .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Returns the process identifier (pid) of a new process started by the application of \fIModule:Function\fR\& to \fIArgs\fR\& on \fINode\fR\&\&. If \fINode\fR\& does not exist, a useless pid is returned\&. Otherwise works like \fIspawn/3\fR\&\&. .RE .LP .nf .B spawn_link(Fun) -> pid() .br .fi .br .RS .LP Types: .RS 3 Fun = function() .br .RE .RE .RS .LP Returns the process identifier of a new process started by the application of \fIFun\fR\& to the empty list \fI[]\fR\&\&. A link is created between the calling process and the new process, atomically\&. Otherwise works like \fIspawn/3\fR\&\&. .RE .LP .nf .B spawn_link(Node, Fun) -> pid() .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Fun = function() .br .RE .RE .RS .LP Returns the process identifier (pid) of a new process started by the application of \fIFun\fR\& to the empty list \fI[]\fR\& on \fINode\fR\&\&. A link is created between the calling process and the new process, atomically\&. If \fINode\fR\& does not exist, a useless pid is returned and an exit signal with reason \fInoconnection\fR\& is sent to the calling process\&. Otherwise works like \fIspawn/3\fR\&\&. .RE .LP .nf .B spawn_link(Module, Function, Args) -> pid() .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Returns the process identifier of a new process started by the application of \fIModule:Function\fR\& to \fIArgs\fR\&\&. A link is created between the calling process and the new process, atomically\&. Otherwise works like \fIspawn/3\fR\&\&. .RE .LP .nf .B spawn_link(Node, Module, Function, Args) -> pid() .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP Returns the process identifier (pid) of a new process started by the application of \fIModule:Function\fR\& to \fIArgs\fR\& on \fINode\fR\&\&. A link is created between the calling process and the new process, atomically\&. If \fINode\fR\& does not exist, a useless pid is returned and an exit signal with reason \fInoconnection\fR\& is sent to the calling process\&. Otherwise works like \fIspawn/3\fR\&\&. .RE .LP .nf .B spawn_monitor(Fun) -> {pid(), reference()} .br .fi .br .RS .LP Types: .RS 3 Fun = function() .br .RE .RE .RS .LP Returns the process identifier of a new process, started by the application of \fIFun\fR\& to the empty list \fI[]\fR\&, and a reference for a monitor created to the new process\&. Otherwise works like \fIspawn/3\fR\&\&. .RE .LP .nf .B spawn_monitor(Node, Fun) -> {pid(), reference()} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Fun = function() .br .RE .RE .RS .LP Returns the process identifier of a new process, started by the application of \fIFun\fR\& to the empty list \fI[]\fR\& on the node \fINode\fR\&, and a reference for a monitor created to the new process\&. Otherwise works like \fIspawn/3\fR\&\&. .LP If the node identified by \fINode\fR\& does not support distributed \fIspawn_monitor()\fR\&, the call will fail with a \fInotsup\fR\& exception\&. .RE .LP .nf .B spawn_monitor(Module, Function, Args) -> {pid(), reference()} .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP A new process is started by the application of \fIModule:Function\fR\& to \fIArgs\fR\&\&. The process is monitored at the same time\&. Returns the process identifier and a reference for the monitor\&. Otherwise works like \fIspawn/3\fR\&\&. .RE .LP .nf .B spawn_monitor(Node, Module, Function, Args) -> .B {pid(), reference()} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br .RE .RE .RS .LP A new process is started by the application of \fIModule:Function\fR\& to \fIArgs\fR\& on the node \fINode\fR\&\&. The process is monitored at the same time\&. Returns the process identifier and a reference for the monitor\&. Otherwise works like \fIspawn/3\fR\&\&. .LP If the node identified by \fINode\fR\& does not support distributed \fIspawn_monitor()\fR\&, the call will fail with a \fInotsup\fR\& exception\&. .RE .LP .nf .B spawn_opt(Fun, Options) -> pid() | {pid(), reference()} .br .fi .br .RS .LP Types: .RS 3 Fun = function() .br Options = [spawn_opt_option()] .br .nf \fBpriority_level()\fR\& = low | normal | high | max .fi .br .nf \fBmax_heap_size()\fR\& = .br integer() >= 0 | .br #{size => integer() >= 0, .br kill => boolean(), .br error_logger => boolean()} .fi .br .nf \fBmessage_queue_data()\fR\& = off_heap | on_heap .fi .br .nf \fBspawn_opt_option()\fR\& = .br link | monitor | .br {monitor, MonitorOpts :: [monitor_option()]} | .br {priority, Level :: priority_level()} | .br {fullsweep_after, Number :: integer() >= 0} | .br {min_heap_size, Size :: integer() >= 0} | .br {min_bin_vheap_size, VSize :: integer() >= 0} | .br {max_heap_size, Size :: max_heap_size()} | .br {message_queue_data, MQD :: message_queue_data()} | .br {async_dist, Enabled :: boolean()} .fi .br .RE .RE .RS .LP Returns the process identifier (pid) of a new process started by the application of \fIFun\fR\& to the empty list \fI[]\fR\&\&. Otherwise works like \fIspawn_opt/4\fR\&\&. .LP If option \fImonitor\fR\& is specified, the newly created process is monitored, and both the pid and reference for the monitor are returned\&. .RE .LP .nf .B spawn_opt(Node, Fun, Options) -> pid() | {pid(), reference()} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Fun = function() .br Options = .br [monitor | {monitor, [monitor_option()]} | link | OtherOption] .br OtherOption = term() .br .RE .RE .RS .LP Returns the process identifier (pid) of a new process started by the application of \fIFun\fR\& to the empty list \fI[]\fR\& on \fINode\fR\&\&. If \fINode\fR\& does not exist, a useless pid is returned\&. Otherwise works like \fIspawn_opt/4\fR\&\&. .LP Valid options depends on what options are supported by the node identified by \fINode\fR\&\&. A description of valid \fIOption\fR\&s for the local node of current OTP version can be found in the documentation of \fIspawn_opt/4\fR\&\&. .RE .LP .nf .B spawn_opt(Module, Function, Args, Options) -> .B Pid | {Pid, MonitorRef} .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br Options = [spawn_opt_option()] .br Pid = pid() .br MonitorRef = reference() .br .nf \fBpriority_level()\fR\& = low | normal | high | max .fi .br .nf \fBmax_heap_size()\fR\& = .br integer() >= 0 | .br #{size => integer() >= 0, .br kill => boolean(), .br error_logger => boolean()} .fi .br .nf \fBmessage_queue_data()\fR\& = off_heap | on_heap .fi .br .nf \fBspawn_opt_option()\fR\& = .br link | monitor | .br {monitor, MonitorOpts :: [monitor_option()]} | .br {priority, Level :: priority_level()} | .br {fullsweep_after, Number :: integer() >= 0} | .br {min_heap_size, Size :: integer() >= 0} | .br {min_bin_vheap_size, VSize :: integer() >= 0} | .br {max_heap_size, Size :: max_heap_size()} | .br {message_queue_data, MQD :: message_queue_data()} | .br {async_dist, Enabled :: boolean()} .fi .br .RE .RE .RS .LP Works as \fIspawn/3\fR\&, except that an extra option list is specified when creating the process\&. .LP If option \fImonitor\fR\& is specified, the newly created process is monitored, and both the pid and reference for the monitor are returned\&. .LP Options: .RS 2 .TP 2 .B \fIlink\fR\&: Sets a link to the parent process (like \fIspawn_link/3\fR\& does)\&. .TP 2 .B \fImonitor\fR\&: Monitors the new process (like \fImonitor(process, Pid)\fR\& does)\&. A \fI{Pid, MonitorRef}\fR\& tuple will be returned instead of just a \fIPid\fR\&\&. .TP 2 .B \fI{monitor, MonitorOpts}\fR\&: Monitors the new process with options (like \fImonitor(process, Pid, MonitorOpts)\fR\& does)\&. A \fI{Pid, MonitorRef}\fR\& tuple will be returned instead of just a \fIPid\fR\&\&. .TP 2 .B \fI{priority, Level}\fR\&: Sets the priority of the new process\&. Equivalent to executing \fIprocess_flag(priority, Level)\fR\& in the start function of the new process, except that the priority is set before the process is selected for execution for the first time\&. For more information on priorities, see \fIprocess_flag(priority, Level)\fR\&\&. .TP 2 .B \fI{fullsweep_after, Number}\fR\&: Useful only for performance tuning\&. Do not use this option unless you know that there is problem with execution times or memory consumption, and ensure that the option improves matters\&. .RS 2 .LP The Erlang runtime system uses a generational garbage collection scheme, using an "old heap" for data that has survived at least one garbage collection\&. When there is no more room on the old heap, a fullsweep garbage collection is done\&. .RE .RS 2 .LP Option \fIfullsweep_after\fR\& makes it possible to specify the maximum number of generational collections before forcing a fullsweep, even if there is room on the old heap\&. Setting the number to zero disables the general collection algorithm, that is, all live data is copied at every garbage collection\&. .RE .RS 2 .LP A few cases when it can be useful to change \fIfullsweep_after\fR\&: .RE .RS 2 .TP 2 * If binaries that are no longer used are to be thrown away as soon as possible\&. (Set \fINumber\fR\& to zero\&.) .LP .TP 2 * A process that mostly have short-lived data is fullsweeped seldom or never, that is, the old heap contains mostly garbage\&. To ensure a fullsweep occasionally, set \fINumber\fR\& to a suitable value, such as 10 or 20\&. .LP .TP 2 * In embedded systems with a limited amount of RAM and no virtual memory, you might want to preserve memory by setting \fINumber\fR\& to zero\&. (The value can be set globally, see \fIerlang:system_flag/2\fR\&\&.) .LP .RE .TP 2 .B \fI{min_heap_size, Size}\fR\&: Useful only for performance tuning\&. Do not use this option unless you know that there is problem with execution times or memory consumption, and ensure that the option improves matters\&. .RS 2 .LP Gives a minimum heap size, in words\&. Setting this value higher than the system default can speed up some processes because less garbage collection is done\&. However, setting a too high value can waste memory and slow down the system because of worse data locality\&. Therefore, use this option only for fine-tuning an application and to measure the execution time with various \fISize\fR\& values\&. .RE .TP 2 .B \fI{min_bin_vheap_size, VSize}\fR\&: Useful only for performance tuning\&. Do not use this option unless you know that there is problem with execution times or memory consumption, and ensure that the option improves matters\&. .RS 2 .LP Gives a minimum binary virtual heap size, in words\&. Setting this value higher than the system default can speed up some processes because less garbage collection is done\&. However, setting a too high value can waste memory\&. Therefore, use this option only for fine-tuning an application and to measure the execution time with various \fIVSize\fR\& values\&. .RE .TP 2 .B \fI{max_heap_size, Size}\fR\&: Sets the \fImax_heap_size\fR\& process flag\&. The default \fImax_heap_size\fR\& is determined by command-line argument \fI+hmax\fR\& in \fIerl(1)\fR\&\&. For more information, see the documentation of \fIprocess_flag(max_heap_size, Size)\fR\&\&. .TP 2 .B \fI{message_queue_data, MQD}\fR\&: Sets the value of the \fImessage_queue_data\fR\& process flag\&. \fIMQD\fR\& can be either \fIoff_heap\fR\& or \fIon_heap\fR\&\&. The default value of the \fImessage_queue_data\fR\& process flag is determined by the command-line argument \fI+hmqd\fR\& in \fIerl(1)\fR\&\&. For more information, see the documentation of \fIprocess_flag(message_queue_data, MQD)\fR\&\&. .TP 2 .B \fI{async_dist, Enabled}\fR\&: Since: OTP 25\&.3 .RS 2 .LP Set the \fIasync_dist\fR\& process flag of the spawned process\&. This option will override the default value set by the command line argument \fI+pad \fR\&\&. .RE .RE .RE .LP .nf .B spawn_opt(Node, Module, Function, Args, Options) -> .B pid() | {pid(), reference()} .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Options = .br [monitor | {monitor, [monitor_option()]} | link | OtherOption] .br OtherOption = term() .br .RE .RE .RS .LP Returns the process identifier (pid) of a new process started by the application of \fIModule:Function\fR\& to \fIArgs\fR\& on \fINode\fR\&\&. If \fINode\fR\& does not exist, a useless pid is returned\&. Otherwise works like \fIspawn_opt/4\fR\&\&. .LP Valid options depends on what options are supported by the node identified by \fINode\fR\&\&. A description of valid \fIOption\fR\&s for the local node of current OTP version can be found in the documentation of \fIspawn_opt/4\fR\&\&. .RE .LP .nf .B spawn_request(Fun) -> ReqId .br .fi .br .RS .LP Types: .RS 3 Fun = function() .br ReqId = reference() .br .RE .RE .RS .LP The same as the call \fIspawn_request(node(),Fun,[])\fR\&\&. That is, a spawn request on the local node with no options\&. .RE .LP .nf .B spawn_request(Fun, Options) -> ReqId .br .fi .br .RS .LP Types: .RS 3 Fun = function() .br Option = .br {reply_tag, ReplyTag} | {reply, Reply} | spawn_opt_option() .br ReplyTag = term() .br Reply = yes | no | error_only | success_only .br Options = [Option] .br ReqId = reference() .br .RE .RE .RS .LP The same as the call \fIspawn_request(node(),Fun,Options)\fR\&\&. That is, a spawn request on the local node\&. .RE .LP .nf .B spawn_request(Node, Fun) -> ReqId .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Fun = function() .br ReqId = reference() .br .RE .RE .RS .LP The same as the call \fIspawn_request(Node,Fun,[])\fR\&\&. That is, a spawn request with no options\&. .RE .LP .nf .B spawn_request(Node, Fun, Options) -> ReqId .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Fun = function() .br Options = [Option] .br Option = .br monitor | .br {monitor, [monitor_option()]} | .br link | .br {reply_tag, ReplyTag} | .br {reply, Reply} | .br OtherOption .br ReplyTag = term() .br Reply = yes | no | error_only | success_only .br OtherOption = term() .br ReqId = reference() .br .RE .RE .RS .LP The same as \fIspawn_request(Node,erlang,apply,[Fun,[]],Options)\fR\&\&. That is, a spawn request using the fun \fIFun\fR\& of arity zero as entry point\&. .LP This function will fail with a \fIbadarg\fR\& exception if: .RS 2 .TP 2 * \fINode\fR\& is not an atom\&. .LP .TP 2 * \fIFun\fR\& is not a fun of arity zero\&. .LP .TP 2 * \fIOptions\fR\& is not a proper list of terms\&. .LP .RE .RE .LP .nf .B spawn_request(Module, Function, Args) -> ReqId .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br ReqId = reference() .br .RE .RE .RS .LP The same as the call \fIspawn_request(node(),Module,Function,Args,[])\fR\&\&. That is, a spawn request on the local node with no options\&. .RE .LP .nf .B spawn_request(Node, Module, Function, Args) -> ReqId .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br ReqId = reference() .br .RE .RE .RS .LP The same as the call \fIspawn_request(Node,Module,Function,Args,[])\fR\&\&. That is, a spawn request with no options\&. .RE .LP .nf .B spawn_request(Module, Function, Args, Options) -> ReqId .br .fi .br .RS .LP Types: .RS 3 Module = module() .br Function = atom() .br Args = [term()] .br Option = .br {reply_tag, ReplyTag} | {reply, Reply} | spawn_opt_option() .br ReplyTag = term() .br Reply = yes | no | error_only | success_only .br Options = [Option] .br ReqId = reference() .br .RE .RE .RS .LP The same as the call \fIspawn_request(node(),Module,Function,Args,Options)\fR\&\&. That is, a spawn request on the local node\&. .RE .LP .nf .B spawn_request(Node, Module, Function, Args, Options) -> ReqId .br .fi .br .RS .LP Types: .RS 3 Node = node() .br Module = module() .br Function = atom() .br Args = [term()] .br Options = [Option] .br Option = .br monitor | .br {monitor, [monitor_option()]} | .br link | .br {reply_tag, ReplyTag} | .br {reply, Reply} | .br OtherOption .br ReplyTag = term() .br Reply = yes | no | error_only | success_only .br OtherOption = term() .br ReqId = reference() .br .RE .RE .RS .LP Asynchronously send a spawn request\&. Returns a request identifier \fIReqId\fR\&\&. .LP If the spawn operation succeeds, a new process is created on the node identified by \fINode\fR\&\&. When a spawn operation succeeds, the caller will by default be sent a message on the form \fI{ReplyTag, ReqId, ok, Pid}\fR\& where \fIPid\fR\& is the process identifier of the newly created process\&. Such a message is referred to as a \fIsuccess message\fR\& below in the text\&. \fIReplyTag\fR\& is by default the atom \fIspawn_reply\fR\& unless modified by the \fI{reply_tag, ReplyTag}\fR\& option\&. The new process is started by the application of \fIModule:Function\fR\& to \fIArgs\fR\&\&. .LP The spawn operation fails either if creation of a new process failed or if the spawn operation was interrupted by a connection failure\&. When a spawn operation fails, the caller will by default be sent a message on the form \fI{ReplyTag, ReqId, error, Reason}\fR\& where \fIReason\fR\& is the error reason\&. Such a message is referred to as an \fIerror message\fR\& below in the text\&. Currently the following spawn error \fIReason\fR\&s are defined, but other reasons can appear at any time without prior notice: .RS 2 .TP 2 .B \fIbadopt\fR\&: An invalid \fIOption\fR\& was passed as argument\&. Note that different runtime systems may support different options\&. .TP 2 .B \fInotsup\fR\&: The node identified by \fINode\fR\& does not support spawn operations issued by \fIspawn_request()\fR\&\&. .TP 2 .B \fInoconnection\fR\&: Failure to set up a connection to the node identified by \fINode\fR\& or the connection to that node was lost during the spawn operation\&. In the case the connection was lost, a process may or may not have been created\&. .TP 2 .B \fIsystem_limit\fR\&: Could not create a new process due to that some system limit was reached\&. Typically the process table was full\&. .RE .LP Valid \fIOption\fR\&s: .RS 2 .TP 2 .B \fImonitor\fR\&: In the absence of spawn operation failures, atomically sets up a monitor to the newly created process\&. That is, as if the calling process had called \fImonitor(process, Pid)\fR\& where \fIPid\fR\& is the process identifier of the newly created process\&. The \fIReqId\fR\& returned by \fIspawn_request()\fR\& is also used as monitor reference as if it was returned from \fImonitor(process, Pid)\fR\&\&. .RS 2 .LP The monitor will not be activated for the calling process until the spawn operation has succeeded\&. The monitor can not be demonitored before the operation has succeeded\&. A \fI\&'DOWN\&'\fR\& message for the corresponding monitor is guaranteed not to be delivered before a \fIsuccess message\fR\& that corresponds to the spawn operation\&. If the spawn operation fails, no \fI\&'DOWN\&'\fR\& message will be delivered\&. .RE .RS 2 .LP If the connection between the nodes involved in the spawn operation is lost during the spawn operation, the spawn operation will fail with an error reason of \fInoconnection\fR\&\&. A new process may or may not have been created\&. .RE .TP 2 .B \fI{monitor, MonitorOpts}\fR\&: In the absence of spawn operation failures, atomically sets up a monitor to the newly created process\&. That is, as if the calling process had called \fImonitor(process, Pid, MonitorOpts)\fR\& where \fIPid\fR\& is the process identifier of the newly created process\&. See the \fImonitor\fR\& option above for more information\&. .RS 2 .LP Note that the monitor will not be activated for the calling process until the spawn operation has succeeded\&. For example, in the case that an alias is created using the monitor option, the alias will not be active until the monitor is activated\&. .RE .TP 2 .B \fIlink\fR\&: In absence of spawn operation failures, atomically sets up a link between the calling process and the newly created process\&. That is, as if the calling process had called \fIlink(Pid)\fR\& where \fIPid\fR\& is the process identifier of the newly created process\&. .RS 2 .LP The link will not be activated for the calling process until the spawn operation has succeeded\&. The link can not be removed before the operation has succeeded\&. An exit signal due to the link is guaranteed not to be delivered before a \fIsuccess message\fR\& that corresponds to the spawn operation\&. If the spawn operation fails, no exit signal due to the link will be delivered to the caller of \fIspawn_request()\fR\&\&. .RE .RS 2 .LP If the connection between the nodes involved in the spawn operation is lost during the spawn operation, the spawn operation will fail with an error reason of \fInoconnection\fR\&\&. A new process may or may not have been created\&. If it has been created, it will be delivered an exit signal with an exit reason of \fInoconnection\fR\&\&. .RE .TP 2 .B \fI{reply, Reply}\fR\&: Valid \fIReply\fR\& values: .RS 2 .TP 2 .B \fIyes\fR\&: A spawn reply message will be sent to the caller regardless of whether the operation succeeds or not\&. If the call to \fIspawn_request()\fR\& returns without raising an exception and the \fIreply\fR\& option is set to \fIyes\fR\&, the caller is guaranteed to be delivered either a \fIsuccess message\fR\& or an \fIerror message\fR\& \&. The \fIreply\fR\& option is by default set to \fIyes\fR\&\&. .TP 2 .B \fIno\fR\&: No spawn reply message will be sent to the caller when the spawn operation completes\&. This regardless of whether the operation succeeds or not\&. .TP 2 .B \fIerror_only\fR\&: No spawn reply message will be sent to the caller if the spawn operation succeeds, but an \fIerror message\fR\& will be sent to the caller if the operation fails\&. .TP 2 .B \fIsuccess_only\fR\&: No spawn reply message will be sent to the caller if the spawn operation fails, but a \fIsuccess message\fR\& will be sent to the caller if the operation succeeds\&. .RE .TP 2 .B \fI{reply_tag, ReplyTag}\fR\&: Sets the reply tag to \fIReplyTag\fR\& in the reply message\&. That is, in the \fIsuccess\fR\& or \fIerror\fR\& message that is sent to the caller due to the spawn operation\&. The default reply tag is the atom \fIspawn_reply\fR\&\&. .TP 2 .B \fIOtherOption\fR\&: Other valid options depends on what options are supported by the node identified by \fINode\fR\&\&. A description of other valid \fIOption\fR\&s for the local node of current OTP version can be found in the documentation of \fIspawn_opt/4\fR\&\&. .RE .LP If a spawn reply message is delivered, it is guaranteed to be delivered before any other signals from the newly spawned process are delivered to the process issuing the spawn request\&. .LP This function will fail with a \fIbadarg\fR\& exception if: .RS 2 .TP 2 * \fINode\fR\& is not an atom\&. .LP .TP 2 * \fIModule\fR\& is not an atom\&. .LP .TP 2 * \fIFunction\fR\& is not an atom\&. .LP .TP 2 * \fIArgs\fR\& is not a proper list of terms\&. .LP .TP 2 * \fIOptions\fR\& is not a proper list of terms\&. .LP .RE .LP Note that not all individual \fIOption\fR\&s are checked when the spawn request is sent\&. Some \fIOption\fR\&s can only be checked on reception of the request\&. Therefore an invalid option does \fInot\fR\& cause a \fIbadarg\fR\& exception, but will cause the spawn operation to fail with an error reason of \fIbadopt\fR\&\&. .LP A spawn request can be abandoned by calling \fIspawn_request_abandon/1\fR\&\&. .RE .LP .nf .B spawn_request_abandon(ReqId :: reference()) -> boolean() .br .fi .br .RS .LP Abandon a previously issued spawn request\&. \fIReqId\fR\& corresponds to a request identifier previously returned by \fIspawn_request()\fR\& in a call from current process\&. That is, only the process that has made the request can abandon the request\&. .LP A spawn request can only be successfully abandoned until the spawn request has completed\&. When a spawn request has been successfully abandoned, the caller will not be effected by future direct effects of the spawn request itself\&. For example, it will not receive a spawn reply message\&. The request is however not withdrawn, so a new process may or may not be created due to the request\&. If a new process is created after the spawn request was abandoned, no monitors nor links will be set up to the caller of \fIspawn_request_abandon/1\fR\& due to the spawn request\&. If the spawn request included the \fIlink\fR\& option, the process created due to this request will be sent an exit signal from its parent with the exit reason \fIabandoned\fR\& when it is detected that the spawn operation has succeeded\&. .LP .RS -4 .B Note: .RE A process created due to a spawn request that has been abandoned may communicate with its parent as any other process\&. It is \fIonly\fR\& the direct effects on the parent of the actual spawn request, that will be canceled by abandoning a spawn request\&. .LP Return values: .RS 2 .TP 2 .B \fItrue\fR\&: The spawn request was successfully abandoned\&. .TP 2 .B \fIfalse\fR\&: No spawn request was abandoned\&. The \fIReqId\fR\& request identifier did not correspond to an outstanding spawn request issued by the calling process\&. The reason for this is either: .RS 2 .TP 2 * \fIReqId\fR\& corresponds to a spawn request previoulsy made by the calling process\&. The spawn operation has completed and a spawn reply has already been delivered to the calling process unless the spawn reply was disabled in the request\&. .LP .TP 2 * \fIReqId\fR\& does not correspond to a spawn request that has been made by the calling process\&. .LP .RE .RE .LP This function fail with a \fIbadarg\fR\& exception if \fIReqId\fR\& is not a reference\&. .RE .LP .nf .B split_binary(Bin, Pos) -> {binary(), binary()} .br .fi .br .RS .LP Types: .RS 3 Bin = binary() .br Pos = integer() >= 0 .br .RS 2 0\&.\&.byte_size(Bin) .RE .RE .RE .RS .LP Returns a tuple containing the binaries that are the result of splitting \fIBin\fR\& into two parts at position \fIPos\fR\&\&. This is not a destructive operation\&. After the operation, there are three binaries altogether\&. Example: .LP .nf > B = list_to_binary("0123456789")\&. <<"0123456789">> > byte_size(B)\&. 10 > {B1, B2} = split_binary(B,3)\&. {<<"012">>,<<"3456789">>} > byte_size(B1)\&. 3 > byte_size(B2)\&. 7 .fi .RE .LP .nf .B erlang:start_timer(Time, Dest, Msg) -> TimerRef .br .fi .br .RS .LP Types: .RS 3 Time = integer() >= 0 .br Dest = pid() | atom() .br Msg = term() .br TimerRef = reference() .br .RE .RE .RS .LP Starts a timer\&. The same as calling \fIerlang:start_timer(Time, Dest, Msg, [])\fR\&\&. .RE .LP .nf .B erlang:start_timer(Time, Dest, Msg, Options) -> TimerRef .br .fi .br .RS .LP Types: .RS 3 Time = integer() .br Dest = pid() | atom() .br Msg = term() .br Options = [Option] .br Abs = boolean() .br Option = {abs, Abs} .br TimerRef = reference() .br .RE .RE .RS .LP Starts a timer\&. When the timer expires, the message \fI{timeout, TimerRef, Msg}\fR\& is sent to the process identified by \fIDest\fR\&\&. .LP \fIOption\fR\&s: .RS 2 .TP 2 .B \fI{abs, false}\fR\&: This is the default\&. It means the \fITime\fR\& value is interpreted as a time in milliseconds \fIrelative\fR\& current Erlang monotonic time\&. .TP 2 .B \fI{abs, true}\fR\&: Absolute \fITime\fR\& value\&. The \fITime\fR\& value is interpreted as an absolute Erlang monotonic time in milliseconds\&. .RE .LP More \fIOption\fR\&s can be added in the future\&. .LP The absolute point in time, the timer is set to expire on, must be in the interval \fI[ \fR\&erlang:convert_time_unit\fI(\fR\&erlang:system_info\fI(start_time), native, millisecond), \fR\&erlang:convert_time_unit\fI(\fR\&erlang:system_info\fI(end_time), native, millisecond) ]\fR\&\&. If a relative time is specified, the \fITime\fR\& value is not allowed to be negative\&. .LP If \fIDest\fR\& is a \fIpid()\fR\&, it must be a \fIpid()\fR\& of a process created on the current runtime system instance\&. This process has either terminated or not\&. If \fIDest\fR\& is an \fIatom()\fR\&, it is interpreted as the name of a locally registered process\&. The process referred to by the name is looked up at the time of timer expiration\&. No error is returned if the name does not refer to a process\&. .LP If \fIDest\fR\& is a \fIpid()\fR\&, the timer is automatically canceled if the process referred to by the \fIpid()\fR\& is not alive, or if the process exits\&. This feature was introduced in ERTS 5\&.4\&.11\&. Notice that timers are not automatically canceled when \fIDest\fR\& is an \fIatom()\fR\&\&. .LP See also \fIerlang:send_after/4\fR\&, \fIerlang:cancel_timer/2\fR\&, and \fIerlang:read_timer/2\fR\&\&. .LP Failure: \fIbadarg\fR\& if the arguments do not satisfy the requirements specified here\&. .RE .LP .nf .B statistics(Item :: active_tasks) -> [ActiveTasks] .br .fi .br .RS .LP Types: .RS 3 ActiveTasks = integer() >= 0 .br .RE .RE .RS .LP Returns the same as \fIstatistics(active_tasks_all)\fR\& with the exception that no information about the dirty IO run queue and its associated schedulers is part of the result\&. That is, only tasks that are expected to be CPU bound are part of the result\&. .RE .LP .nf .B statistics(Item :: active_tasks_all) -> [ActiveTasks] .br .fi .br .RS .LP Types: .RS 3 ActiveTasks = integer() >= 0 .br .RE .RE .RS .LP Returns a list where each element represents the amount of active processes and ports on each run queue and its associated schedulers\&. That is, the number of processes and ports that are ready to run, or are currently running\&. Values for normal run queues and their associated schedulers are located first in the resulting list\&. The first element corresponds to scheduler number 1 and so on\&. If support for dirty schedulers exist, an element with the value for the dirty CPU run queue and its associated dirty CPU schedulers follow and then as last element the value for the the dirty IO run queue and its associated dirty IO schedulers follow\&. The information is \fInot\fR\& gathered atomically\&. That is, the result is not necessarily a consistent snapshot of the state, but instead quite efficiently gathered\&. .LP .RS -4 .B Note: .RE Each normal scheduler has one run queue that it manages\&. If dirty schedulers schedulers are supported, all dirty CPU schedulers share one run queue, and all dirty IO schedulers share one run queue\&. That is, we have multiple normal run queues, one dirty CPU run queue and one dirty IO run queue\&. Work can \fInot\fR\& migrate between the different types of run queues\&. Only work in normal run queues can migrate to other normal run queues\&. This has to be taken into account when evaluating the result\&. .LP See also \fIstatistics(total_active_tasks)\fR\&, \fIstatistics(run_queue_lengths)\fR\&, \fIstatistics(run_queue_lengths_all)\fR\&, \fIstatistics(total_run_queue_lengths)\fR\&, and \fIstatistics(total_run_queue_lengths_all)\fR\&\&. .RE .LP .nf .B statistics(Item :: context_switches) -> {ContextSwitches, 0} .br .fi .br .RS .LP Types: .RS 3 ContextSwitches = integer() >= 0 .br .RE .RE .RS .LP Returns the total number of context switches since the system started\&. .RE .LP .nf .B statistics(Item :: exact_reductions) -> .B {Total_Exact_Reductions, .B Exact_Reductions_Since_Last_Call} .br .fi .br .RS .LP Types: .RS 3 Total_Exact_Reductions = Exact_Reductions_Since_Last_Call = integer() >= 0 .br .RE .RE .RS .LP Returns the number of exact reductions\&. .LP .RS -4 .B Note: .RE \fIstatistics(exact_reductions)\fR\& is a more expensive operation than statistics(reductions)\&. .RE .LP .nf .B statistics(Item :: garbage_collection) -> .B {Number_of_GCs, Words_Reclaimed, 0} .br .fi .br .RS .LP Types: .RS 3 Number_of_GCs = Words_Reclaimed = integer() >= 0 .br .RE .RE .RS .LP Returns information about garbage collection, for example: .LP .nf > statistics(garbage_collection)\&. {85,23961,0} .fi .LP This information can be invalid for some implementations\&. .RE .LP .nf .B statistics(Item :: io) -> {{input, Input}, {output, Output}} .br .fi .br .RS .LP Types: .RS 3 Input = Output = integer() >= 0 .br .RE .RE .RS .LP Returns \fIInput\fR\&, which is the total number of bytes received through ports, and \fIOutput\fR\&, which is the total number of bytes output to ports\&. .RE .LP .nf .B statistics(Item :: microstate_accounting) -> .B [MSAcc_Thread] | undefined .br .fi .br .RS .LP Types: .RS 3 MSAcc_Thread = .br #{type := MSAcc_Thread_Type, .br id := MSAcc_Thread_Id, .br counters := MSAcc_Counters} .br MSAcc_Thread_Type = .br async | aux | dirty_io_scheduler | dirty_cpu_scheduler | .br poll | scheduler .br MSAcc_Thread_Id = integer() >= 0 .br MSAcc_Counters = #{MSAcc_Thread_State => integer() >= 0} .br MSAcc_Thread_State = .br alloc | aux | bif | busy_wait | check_io | emulator | ets | .br gc | gc_fullsweep | nif | other | port | send | sleep | timers .br .RE .RE .RS .LP Microstate accounting can be used to measure how much time the Erlang runtime system spends doing various tasks\&. It is designed to be as lightweight as possible, but some overhead exists when this is enabled\&. Microstate accounting is meant to be a profiling tool to help finding performance bottlenecks\&. To \fIstart\fR\&/\fIstop\fR\&/\fIreset\fR\& microstate accounting, use system flag \fImicrostate_accounting\fR\&\&. .LP \fIstatistics(microstate_accounting)\fR\& returns a list of maps representing some of the OS threads within ERTS\&. Each map contains \fItype\fR\& and \fIid\fR\& fields that can be used to identify what thread it is, and also a counters field that contains data about how much time has been spent in the various states\&. .LP Example: .LP .nf > erlang:statistics(microstate_accounting)\&. [#{counters => #{aux => 1899182914, check_io => 2605863602, emulator => 45731880463, gc => 1512206910, other => 5421338456, port => 221631, sleep => 5150294100}, id => 1, type => scheduler}|...] .fi .LP The time unit is the same as returned by \fIos:perf_counter/0\fR\&\&. So, to convert it to milliseconds, you can do something like this: .LP .nf lists:map( fun(#{ counters := Cnt } = M) -> MsCnt = maps:map(fun(_K, PerfCount) -> erlang:convert_time_unit(PerfCount, perf_counter, 1000) end, Cnt), M#{ counters := MsCnt } end, erlang:statistics(microstate_accounting)). .fi .LP Notice that these values are not guaranteed to be the exact time spent in each state\&. This is because of various optimisation done to keep the overhead as small as possible\&. .LP \fIMSAcc_Thread_Type\fR\&s: .RS 2 .TP 2 .B \fIscheduler\fR\&: The main execution threads that do most of the work\&. See erl +S for more details\&. .TP 2 .B \fIdirty_cpu_scheduler\fR\&: The threads for long running cpu intensive work\&. See erl +SDcpu for more details\&. .TP 2 .B \fIdirty_io_scheduler\fR\&: The threads for long running I/O work\&. See erl +SDio for more details\&. .TP 2 .B \fIasync\fR\&: Async threads are used by various linked-in drivers (mainly the file drivers) do offload non-CPU intensive work\&. See erl +A for more details\&. .TP 2 .B \fIaux\fR\&: Takes care of any work that is not specifically assigned to a scheduler\&. .TP 2 .B \fIpoll\fR\&: Does the IO polling for the emulator\&. See erl +IOt for more details\&. .RE .LP The following \fIMSAcc_Thread_State\fR\&s are available\&. All states are exclusive, meaning that a thread cannot be in two states at once\&. So, if you add the numbers of all counters in a thread, you get the total runtime for that thread\&. .RS 2 .TP 2 .B \fIaux\fR\&: Time spent handling auxiliary jobs\&. .TP 2 .B \fIcheck_io\fR\&: Time spent checking for new I/O events\&. .TP 2 .B \fIemulator\fR\&: Time spent executing Erlang processes\&. .TP 2 .B \fIgc\fR\&: Time spent doing garbage collection\&. When extra states are enabled this is the time spent doing non-fullsweep garbage collections\&. .TP 2 .B \fIother\fR\&: Time spent doing unaccounted things\&. .TP 2 .B \fIport\fR\&: Time spent executing ports\&. .TP 2 .B \fIsleep\fR\&: Time spent sleeping\&. .RE .LP More fine-grained \fIMSAcc_Thread_State\fR\&s can be added through configure (such as \fI\&./configure --with-microstate-accounting=extra\fR\&)\&. Enabling these states causes performance degradation when microstate accounting is turned off and increases the overhead when it is turned on\&. .RS 2 .TP 2 .B \fIalloc\fR\&: Time spent managing memory\&. Without extra states this time is spread out over all other states\&. .TP 2 .B \fIbif\fR\&: Time spent in BIFs\&. Without extra states this time is part of the \fIemulator\fR\& state\&. .TP 2 .B \fIbusy_wait\fR\&: Time spent busy waiting\&. This is also the state where a scheduler no longer reports that it is active when using \fIstatistics(scheduler_wall_time)\fR\&\&. So, if you add all other states but this and sleep, and then divide that by all time in the thread, you should get something very similar to the \fIscheduler_wall_time\fR\& fraction\&. Without extra states this time is part of the \fIother\fR\& state\&. .TP 2 .B \fIets\fR\&: Time spent executing ETS BIFs\&. Without extra states this time is part of the \fIemulator\fR\& state\&. .TP 2 .B \fIgc_full\fR\&: Time spent doing fullsweep garbage collection\&. Without extra states this time is part of the \fIgc\fR\& state\&. .TP 2 .B \fInif\fR\&: Time spent in NIFs\&. Without extra states this time is part of the \fIemulator\fR\& state\&. .TP 2 .B \fIsend\fR\&: Time spent sending messages (processes only)\&. Without extra states this time is part of the \fIemulator\fR\& state\&. .TP 2 .B \fItimers\fR\&: Time spent managing timers\&. Without extra states this time is part of the \fIother\fR\& state\&. .RE .LP The utility module \fImsacc(3erl)\fR\& can be used to more easily analyse these statistics\&. .LP Returns \fIundefined\fR\& if system flag \fImicrostate_accounting\fR\& is turned off\&. .LP The list of thread information is unsorted and can appear in different order between calls\&. .LP .RS -4 .B Note: .RE The threads and states are subject to change without any prior notice\&. .RE .LP .nf .B statistics(Item :: reductions) -> .B {Total_Reductions, Reductions_Since_Last_Call} .br .fi .br .RS .LP Types: .RS 3 Total_Reductions = Reductions_Since_Last_Call = integer() >= 0 .br .RE .RE .RS .LP Returns information about reductions, for example: .LP .nf > statistics(reductions)\&. {2046,11} .fi .LP .RS -4 .B Note: .RE As from ERTS 5\&.5 (Erlang/OTP R11B), this value does not include reductions performed in current time slices of currently scheduled processes\&. If an exact value is wanted, use \fIstatistics(exact_reductions)\fR\&\&. .RE .LP .nf .B statistics(Item :: run_queue) -> integer() >= 0 .br .fi .br .RS .LP Returns the total length of all normal and dirty CPU run queues\&. That is, queued work that is expected to be CPU bound\&. The information is gathered atomically\&. That is, the result is a consistent snapshot of the state, but this operation is much more expensive compared to \fIstatistics(total_run_queue_lengths)\fR\&, especially when a large amount of schedulers is used\&. .RE .LP .nf .B statistics(Item :: run_queue_lengths) -> [RunQueueLength] .br .fi .br .RS .LP Types: .RS 3 RunQueueLength = integer() >= 0 .br .RE .RE .RS .LP Returns the same as \fIstatistics(run_queue_lengths_all)\fR\& with the exception that no information about the dirty IO run queue is part of the result\&. That is, only run queues with work that is expected to be CPU bound is part of the result\&. .RE .LP .nf .B statistics(Item :: run_queue_lengths_all) -> [RunQueueLength] .br .fi .br .RS .LP Types: .RS 3 RunQueueLength = integer() >= 0 .br .RE .RE .RS .LP Returns a list where each element represents the amount of processes and ports ready to run for each run queue\&. Values for normal run queues are located first in the resulting list\&. The first element corresponds to the normal run queue of scheduler number 1 and so on\&. If support for dirty schedulers exist, values for the dirty CPU run queue and the dirty IO run queue follow (in that order) at the end\&. The information is \fInot\fR\& gathered atomically\&. That is, the result is not necessarily a consistent snapshot of the state, but instead quite efficiently gathered\&. .LP .RS -4 .B Note: .RE Each normal scheduler has one run queue that it manages\&. If dirty schedulers schedulers are supported, all dirty CPU schedulers share one run queue, and all dirty IO schedulers share one run queue\&. That is, we have multiple normal run queues, one dirty CPU run queue and one dirty IO run queue\&. Work can \fInot\fR\& migrate between the different types of run queues\&. Only work in normal run queues can migrate to other normal run queues\&. This has to be taken into account when evaluating the result\&. .LP See also \fIstatistics(run_queue_lengths)\fR\&, \fIstatistics(total_run_queue_lengths_all)\fR\&, \fIstatistics(total_run_queue_lengths)\fR\&, \fIstatistics(active_tasks)\fR\&, \fIstatistics(active_tasks_all)\fR\&, and \fIstatistics(total_active_tasks)\fR\&, \fIstatistics(total_active_tasks_all)\fR\&\&. .RE .LP .nf .B statistics(Item :: runtime) -> .B {Total_Run_Time, Time_Since_Last_Call} .br .fi .br .RS .LP Types: .RS 3 Total_Run_Time = Time_Since_Last_Call = integer() >= 0 .br .RE .RE .RS .LP Returns information about runtime, in milliseconds\&. .LP This is the sum of the runtime for all threads in the Erlang runtime system and can therefore be greater than the wall clock time\&. .LP .RS -4 .B Warning: .RE This value might wrap due to limitations in the underlying functionality provided by the operating system that is used\&. .LP Example: .LP .nf > statistics(runtime)\&. {1690,1620} .fi .RE .LP .nf .B statistics(Item :: scheduler_wall_time) -> .B [{SchedulerId, ActiveTime, TotalTime}] | undefined .br .fi .br .RS .LP Types: .RS 3 SchedulerId = integer() >= 1 .br ActiveTime = TotalTime = integer() >= 0 .br .RE .RE .RS .LP Returns information describing how much time normal and dirty CPU schedulers in the system have been busy\&. This value is normally a better indicator of how much load an Erlang node is under instead of looking at the CPU utilization provided by tools such as \fItop\fR\& or \fIsysstat\fR\&\&. This is because \fIscheduler_wall_time\fR\& also includes time where the scheduler is waiting for some other reasource (such as an internal mutex) to be available but does not use the CPU\&. In order to better understand what a scheduler is busy doing you can use microstate accounting\&. .LP The definition of a busy scheduler is when it is not idle and not busy waiting for new work, that is: .RS 2 .TP 2 * Executing process code .LP .TP 2 * Executing linked-in driver or NIF code .LP .TP 2 * Executing BIFs, or any other runtime handling .LP .TP 2 * Garbage collecting .LP .TP 2 * Handling any other memory management .LP .RE .LP Notice that a scheduler can also be busy even if the OS has scheduled out the scheduler thread\&. .LP .RS -4 .B Note: .RE It is recommended to use the module \fIscheduler\fR\& instead of this function directly as it provides an easier way to get the information that you usually want\&. .LP If enabled this function returns a list of tuples with \fI{SchedulerId, ActiveTime, TotalTime}\fR\&, where \fISchedulerId\fR\& is an integer ID of the scheduler, \fIActiveTime\fR\& is the duration the scheduler has been busy, and \fITotalTime\fR\& is the total time duration since \fIscheduler_wall_time\fR\& activation for the specific scheduler\&. The time unit returned is undefined and can be subject to change between releases, OSs, and system restarts\&. \fIscheduler_wall_time\fR\& is only to be used to calculate relative values for scheduler utilization\&. The \fIActiveTime\fR\& can never exceed \fITotalTime\fR\&\&. The list of scheduler information is unsorted and can appear in different order between calls\&. .LP The disabled this function returns \fIundefined\fR\&\&. .LP The activation time can differ significantly between schedulers\&. Currently dirty schedulers are activated at system start while normal schedulers are activated some time after the \fIscheduler_wall_time\fR\& functionality is enabled\&. .LP Only information about schedulers that are expected to handle CPU bound work is included in the return values from this function\&. If you also want information about dirty I/O schedulers, use \fIstatistics(scheduler_wall_time_all)\fR\& instead\&. .LP Normal schedulers will have scheduler identifiers in the range \fI1 =< SchedulerId =< \fR\&\fIerlang:system_info(schedulers)\fR\&\&. Dirty CPU schedulers will have scheduler identifiers in the range \fIerlang:system_info(schedulers) < SchedulerId =< erlang:system_info(schedulers) + \fR\&\fIerlang:system_info(dirty_cpu_schedulers)\fR\&\&. .LP .RS -4 .B Note: .RE The different types of schedulers handle specific types of jobs\&. Every job is assigned to a specific scheduler type\&. Jobs can migrate between different schedulers of the same type, but never between schedulers of different types\&. This fact has to be taken under consideration when evaluating the result returned\&. .LP You can use \fIscheduler_wall_time\fR\& to calculate scheduler utilization\&. First you take a sample of the values returned by \fIerlang:statistics(scheduler_wall_time)\fR\&\&. .LP .nf > erlang:system_flag(scheduler_wall_time, true)\&. false > Ts0 = lists:sort(erlang:statistics(scheduler_wall_time)), ok\&. ok .fi .LP Some time later the user takes another snapshot and calculates scheduler utilization per scheduler, for example: .LP .nf > Ts1 = lists:sort(erlang:statistics(scheduler_wall_time)), ok\&. ok > lists:map(fun({{I, A0, T0}, {I, A1, T1}}) -> {I, (A1 - A0)/(T1 - T0)} end, lists:zip(Ts0,Ts1))\&. [{1,0.9743474730177548}, {2,0.9744843782751444}, {3,0.9995902361669045}, {4,0.9738012596572161}, {5,0.9717956667018103}, {6,0.9739235846420741}, {7,0.973237033077876}, {8,0.9741297293248656}] .fi .LP Using the same snapshots to calculate a total scheduler utilization: .LP .nf > {A, T} = lists:foldl(fun({{_, A0, T0}, {_, A1, T1}}, {Ai,Ti}) -> {Ai + (A1 - A0), Ti + (T1 - T0)} end, {0, 0}, lists:zip(Ts0,Ts1)), TotalSchedulerUtilization = A/T\&. 0.9769136803764825 .fi .LP Total scheduler utilization will equal \fI1\&.0\fR\& when all schedulers have been active all the time between the two measurements\&. .LP Another (probably more) useful value is to calculate total scheduler utilization weighted against maximum amount of available CPU time: .LP .nf > WeightedSchedulerUtilization = (TotalSchedulerUtilization * (erlang:system_info(schedulers) + erlang:system_info(dirty_cpu_schedulers))) / erlang:system_info(logical_processors_available)\&. 0.9769136803764825 .fi .LP This weighted scheduler utilization will reach \fI1\&.0\fR\& when schedulers are active the same amount of time as maximum available CPU time\&. If more schedulers exist than available logical processors, this value may be greater than \fI1\&.0\fR\&\&. .LP As of ERTS version 9\&.0, the Erlang runtime system will as default have more schedulers than logical processors\&. This due to the dirty schedulers\&. .LP .RS -4 .B Note: .RE \fIscheduler_wall_time\fR\& is by default disabled\&. To enable it, use \fIerlang:system_flag(scheduler_wall_time, true)\fR\&\&. .RE .LP .nf .B statistics(Item :: scheduler_wall_time_all) -> .B [{SchedulerId, ActiveTime, TotalTime}] | undefined .br .fi .br .RS .LP Types: .RS 3 SchedulerId = integer() >= 1 .br ActiveTime = TotalTime = integer() >= 0 .br .RE .RE .RS .LP The same as \fIstatistics(scheduler_wall_time)\fR\&, except that it also include information about all dirty I/O schedulers\&. .LP Dirty IO schedulers will have scheduler identifiers in the range \fIerlang:system_info(schedulers)\fR\&\fI + \fR\&\fIerlang:system_info(dirty_cpu_schedulers)\fR\&\fI < SchedulerId =< erlang:system_info(schedulers) + erlang:system_info(dirty_cpu_schedulers) + \fR\&\fIerlang:system_info(dirty_io_schedulers)\fR\&\&. .LP .RS -4 .B Note: .RE Note that work executing on dirty I/O schedulers are expected to mainly wait for I/O\&. That is, when you get high scheduler utilization on dirty I/O schedulers, CPU utilization is \fInot\fR\& expected to be high due to this work\&. .RE .LP .nf .B statistics(Item :: total_active_tasks) -> ActiveTasks .br .fi .br .RS .LP Types: .RS 3 ActiveTasks = integer() >= 0 .br .RE .RE .RS .LP The same as calling \fIlists:sum(\fR\&\fIstatistics(active_tasks)\fR\&\fI)\fR\&, but more efficient\&. .RE .LP .nf .B statistics(Item :: total_active_tasks_all) -> ActiveTasks .br .fi .br .RS .LP Types: .RS 3 ActiveTasks = integer() >= 0 .br .RE .RE .RS .LP The same as calling \fIlists:sum(\fR\&\fIstatistics(active_tasks_all)\fR\&\fI)\fR\&, but more efficient\&. .RE .LP .nf .B statistics(Item :: total_run_queue_lengths) -> .B TotalRunQueueLengths .br .fi .br .RS .LP Types: .RS 3 TotalRunQueueLengths = integer() >= 0 .br .RE .RE .RS .LP The same as calling \fIlists:sum(\fR\&\fIstatistics(run_queue_lengths)\fR\&\fI)\fR\&, but more efficient\&. .RE .LP .nf .B statistics(Item :: total_run_queue_lengths_all) -> .B TotalRunQueueLengths .br .fi .br .RS .LP Types: .RS 3 TotalRunQueueLengths = integer() >= 0 .br .RE .RE .RS .LP The same as calling \fIlists:sum(\fR\&\fIstatistics(run_queue_lengths_all)\fR\&\fI)\fR\&, but more efficient\&. .RE .LP .nf .B statistics(Item :: wall_clock) -> .B {Total_Wallclock_Time, .B Wallclock_Time_Since_Last_Call} .br .fi .br .RS .LP Types: .RS 3 Total_Wallclock_Time = Wallclock_Time_Since_Last_Call = integer() >= 0 .br .RE .RE .RS .LP Returns information about wall clock\&. \fIwall_clock\fR\& can be used in the same manner as \fIruntime\fR\&, except that real time is measured as opposed to runtime or CPU time\&. .RE .LP .nf .B erlang:suspend_process(Suspendee) -> true .br .fi .br .RS .LP Types: .RS 3 Suspendee = pid() .br .RE .RE .RS .LP Suspends the process identified by \fISuspendee\fR\&\&. The same as calling \fIerlang:suspend_process(Suspendee, [])\fR\&\&. .LP .RS -4 .B Warning: .RE This BIF is intended for debugging only\&. .RE .LP .nf .B erlang:suspend_process(Suspendee, OptList) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Suspendee = pid() .br OptList = [Opt] .br Opt = unless_suspending | asynchronous | {asynchronous, term()} .br .RE .RE .RS .LP Increases the suspend count on the process identified by \fISuspendee\fR\& and puts it in the suspended state if it is not already in that state\&. A suspended process is not scheduled for execution until the process has been resumed\&. .LP A process can be suspended by multiple processes and can be suspended multiple times by a single process\&. A suspended process does not leave the suspended state until its suspend count reaches zero\&. The suspend count of \fISuspendee\fR\& is decreased when \fIerlang:resume_process(Suspendee)\fR\& is called by the same process that called \fIerlang:suspend_process(Suspendee)\fR\&\&. All increased suspend counts on other processes acquired by a process are automatically decreased when the process terminates\&. .LP Options (\fIOpt\fR\&s): .RS 2 .TP 2 .B \fIasynchronous\fR\&: A suspend request is sent to the process identified by \fISuspendee\fR\&\&. \fISuspendee\fR\& eventually suspends unless it is resumed before it could suspend\&. The caller of \fIerlang:suspend_process/2\fR\& returns immediately, regardless of whether \fISuspendee\fR\& has suspended yet or not\&. The point in time when \fISuspendee\fR\& suspends cannot be deduced from other events in the system\&. It is only guaranteed that \fISuspendee\fR\& \fIeventually\fR\& suspends (unless it is resumed)\&. If no \fIasynchronous\fR\& options has been passed, the caller of \fIerlang:suspend_process/2\fR\& is blocked until \fISuspendee\fR\& has suspended\&. .TP 2 .B \fI{asynchronous, ReplyTag}\fR\&: A suspend request is sent to the process identified by \fISuspendee\fR\&\&. When the suspend request has been processed, a reply message is sent to the caller of this function\&. The reply is on the form \fI{ReplyTag, State}\fR\& where \fIState\fR\& is either: .RS 2 .TP 2 .B \fIexited\fR\&: \fISuspendee\fR\& has exited\&. .TP 2 .B \fIsuspended\fR\&: \fISuspendee\fR\& is now suspended\&. .TP 2 .B \fInot_suspended\fR\&: \fISuspendee\fR\& is not suspended\&. This can only happen when the process that issued this request, have called \fIresume_process(Suspendee)\fR\& before getting the reply\&. .RE .RS 2 .LP Apart from the reply message, the \fI{asynchronous, ReplyTag}\fR\& option behaves exactly the same as the \fIasynchronous\fR\& option without reply tag\&. .RE .TP 2 .B \fIunless_suspending\fR\&: The process identified by \fISuspendee\fR\& is suspended unless the calling process already is suspending \fISuspendee\fR\&\&. If \fIunless_suspending\fR\& is combined with option \fIasynchronous\fR\&, a suspend request is sent unless the calling process already is suspending \fISuspendee\fR\& or if a suspend request already has been sent and is in transit\&. If the calling process already is suspending \fISuspendee\fR\&, or if combined with option \fIasynchronous\fR\& and a send request already is in transit, \fIfalse\fR\& is returned and the suspend count on \fISuspendee\fR\& remains unchanged\&. .RE .LP If the suspend count on the process identified by \fISuspendee\fR\& is increased, \fItrue\fR\& is returned, otherwise \fIfalse\fR\&\&. .LP .RS -4 .B Warning: .RE This BIF is intended for debugging only\&. .LP .RS -4 .B Warning: .RE You can easily create deadlocks if processes suspends each other (directly or in circles)\&. In ERTS versions prior to ERTS version 10\&.0, the runtime system prevented such deadlocks, but this prevention has now been removed due to performance reasons\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fISuspendee\fR\& is not a process identifier\&. .TP 2 .B \fIbadarg\fR\&: If the process identified by \fISuspendee\fR\& is the same process as the process calling \fIerlang:suspend_process/2\fR\&\&. .TP 2 .B \fIbadarg\fR\&: If the process identified by \fISuspendee\fR\& is not alive\&. .TP 2 .B \fIbadarg\fR\&: If the process identified by \fISuspendee\fR\& resides on another node\&. .TP 2 .B \fIbadarg\fR\&: If \fIOptList\fR\& is not a proper list of valid \fIOpt\fR\&s\&. .TP 2 .B \fIsystem_limit\fR\&: If the process identified by \fISuspendee\fR\& has been suspended more times by the calling process than can be represented by the currently used internal data structures\&. The system limit is greater than 2,000,000,000 suspends and will never be lower\&. .RE .RE .LP .nf .B erlang:system_flag(Flag :: backtrace_depth, Depth) -> OldDepth .br .fi .br .RS .LP Types: .RS 3 Depth = OldDepth = integer() >= 0 .br .RE .RE .RS .LP Sets the maximum depth of call stack back-traces in the exit reason element of \fI\&'EXIT\&'\fR\& tuples\&. The flag also limits the stacktrace depth returned by \fIprocess_info\fR\& item \fIcurrent_stacktrace\&.\fR\& .LP Returns the old value of the flag\&. .RE .LP .nf .B erlang:system_flag(Flag :: cpu_topology, CpuTopology) -> .B OldCpuTopology .br .fi .br .RS .LP Types: .RS 3 CpuTopology = OldCpuTopology = cpu_topology() .br .nf \fBcpu_topology()\fR\& = [LevelEntry :: level_entry()] | undefined .fi .br .nf \fBlevel_entry()\fR\& = .br {LevelTag :: level_tag(), SubLevel :: sub_level()} | .br {LevelTag :: level_tag(), .br InfoList :: info_list(), .br SubLevel :: sub_level()} .fi .br .nf \fBlevel_tag()\fR\& = core | node | processor | thread .fi .br .nf \fBsub_level()\fR\& = .br [LevelEntry :: level_entry()] | .br (LogicalCpuId :: {logical, integer() >= 0}) .fi .br .nf \fBinfo_list()\fR\& = [] .fi .br .RE .RE .RS .LP .RS -4 .B Warning: .RE \fIThis argument is deprecated\&.\fR\& Instead of using this argument, use command-line argument \fI+sct\fR\& in \fIerl(1)\fR\&\&. .LP When this argument is removed, a final CPU topology to use is determined at emulator boot time\&. .LP Sets the user-defined \fICpuTopology\fR\&\&. The user-defined CPU topology overrides any automatically detected CPU topology\&. By passing \fIundefined\fR\& as \fICpuTopology\fR\&, the system reverts to the CPU topology automatically detected\&. The returned value equals the value returned from \fIerlang:system_info(cpu_topology)\fR\& before the change was made\&. .LP Returns the old value of the flag\&. .LP The CPU topology is used when binding schedulers to logical processors\&. If schedulers are already bound when the CPU topology is changed, the schedulers are sent a request to rebind according to the new CPU topology\&. .LP The user-defined CPU topology can also be set by passing command-line argument \fI+sct\fR\& to \fIerl(1)\fR\&\&. .LP For information on type \fICpuTopology\fR\& and more, see \fIerlang:system_info(cpu_topology)\fR\& as well as command-line flags \fI+sct\fR\& and \fI+sbt\fR\& in \fIerl(1)\fR\&\&. .RE .LP .nf .B erlang:system_flag(Flag :: dirty_cpu_schedulers_online, .B DirtyCPUSchedulersOnline) -> .B OldDirtyCPUSchedulersOnline .br .fi .br .RS .LP Types: .RS 3 DirtyCPUSchedulersOnline = OldDirtyCPUSchedulersOnline = integer() >= 1 .br .RE .RE .RS .LP Sets the number of dirty CPU schedulers online\&. Range is \fI1 <= DirtyCPUSchedulersOnline <= N\fR\&, where \fIN\fR\& is the smallest of the return values of \fIerlang:system_info(dirty_cpu_schedulers)\fR\& and \fIerlang:system_info(schedulers_online)\fR\&\&. .LP Returns the old value of the flag\&. .LP The number of dirty CPU schedulers online can change if the number of schedulers online changes\&. For example, if 12 schedulers and 6 dirty CPU schedulers are online, and \fIsystem_flag/2\fR\& is used to set the number of schedulers online to 6, then the number of dirty CPU schedulers online is automatically decreased by half as well, down to 3\&. Similarly, the number of dirty CPU schedulers online increases proportionally to increases in the number of schedulers online\&. .LP For more information, see \fIerlang:system_info(dirty_cpu_schedulers)\fR\& and \fIerlang:system_info(dirty_cpu_schedulers_online)\fR\&\&. .RE .LP .nf .B erlang:system_flag(Flag :: erts_alloc, Value :: {Alloc, F, V}) -> .B ok | notsup .br .fi .br .RS .LP Types: .RS 3 Alloc = F = atom() .br V = integer() .br .RE .RE .RS .LP Sets system flags for \fIerts_alloc(3erl)\fR\&\&. \fIAlloc\fR\& is the allocator to affect, for example \fIbinary_alloc\fR\&\&. \fIF\fR\& is the flag to change and \fIV\fR\& is the new value\&. .LP Only a subset of all \fIerts_alloc\fR\& flags can be changed at run time\&. This subset is currently only the flag \fIsbct\fR\&\&. .LP Returns \fIok\fR\& if the flag was set or \fInotsup\fR\& if not supported by \fIerts_alloc\fR\&\&. .RE .LP .nf .B erlang:system_flag(Flag :: fullsweep_after, Number) -> OldNumber .br .fi .br .RS .LP Types: .RS 3 Number = OldNumber = integer() >= 0 .br .RE .RE .RS .LP Sets system flag \fIfullsweep_after\fR\&\&. \fINumber\fR\& is a non-negative integer indicating how many times generational garbage collections can be done without forcing a fullsweep collection\&. The value applies to new processes, while processes already running are not affected\&. .LP Returns the old value of the flag\&. .LP In low-memory systems (especially without virtual memory), setting the value to \fI0\fR\& can help to conserve memory\&. .LP This value can also be set through (OS) environment variable \fIERL_FULLSWEEP_AFTER\fR\&\&. .RE .LP .nf .B erlang:system_flag(Flag :: microstate_accounting, Action) -> .B OldState .br .fi .br .RS .LP Types: .RS 3 Action = true | false | reset .br OldState = true | false .br .RE .RE .RS .LP Turns on/off microstate accounting measurements\&. When passing reset, all counters are reset to 0\&. .LP For more information see \fIstatistics(microstate_accounting)\fR\&\&. .RE .LP .nf .B erlang:system_flag(Flag :: min_heap_size, MinHeapSize) -> .B OldMinHeapSize .br .fi .br .RS .LP Types: .RS 3 MinHeapSize = OldMinHeapSize = integer() >= 0 .br .RE .RE .RS .LP Sets the default minimum heap size for processes\&. The size is specified in words\&. The new \fImin_heap_size\fR\& effects only processes spawned after the change of \fImin_heap_size\fR\& has been made\&. \fImin_heap_size\fR\& can be set for individual processes by using \fIspawn_opt/4\fR\& or \fIprocess_flag/2\fR\&\&. .LP Returns the old value of the flag\&. .RE .LP .nf .B erlang:system_flag(Flag :: min_bin_vheap_size, MinBinVHeapSize) -> .B OldMinBinVHeapSize .br .fi .br .RS .LP Types: .RS 3 MinBinVHeapSize = OldMinBinVHeapSize = integer() >= 0 .br .RE .RE .RS .LP Sets the default minimum binary virtual heap size for processes\&. The size is specified in words\&. The new \fImin_bin_vhheap_size\fR\& effects only processes spawned after the change of \fImin_bin_vheap_size\fR\& has been made\&. \fImin_bin_vheap_size\fR\& can be set for individual processes by using \fIspawn_opt/2,3,4\fR\& or \fIprocess_flag/2\fR\&\&. .LP Returns the old value of the flag\&. .RE .LP .nf .B erlang:system_flag(Flag :: max_heap_size, MaxHeapSize) -> .B OldMaxHeapSize .br .fi .br .RS .LP Types: .RS 3 MaxHeapSize = OldMaxHeapSize = max_heap_size() .br .nf \fBmax_heap_size()\fR\& = .br integer() >= 0 | .br #{size => integer() >= 0, .br kill => boolean(), .br error_logger => boolean()} .fi .br .RE .RE .RS .LP Sets the default maximum heap size settings for processes\&. The size is specified in words\&. The new \fImax_heap_size\fR\& effects only processes spawned efter the change has been made\&. \fImax_heap_size\fR\& can be set for individual processes using \fIspawn_opt/2,3,4\fR\& or \fIprocess_flag/2\fR\&\&. .LP Returns the old value of the flag\&. .LP For details on how the heap grows, see Sizing the heap in the ERTS internal documentation\&. .RE .LP .nf .B erlang:system_flag(Flag :: multi_scheduling, BlockState) -> .B OldBlockState .br .fi .br .RS .LP Types: .RS 3 BlockState = block | unblock | block_normal | unblock_normal .br OldBlockState = blocked | disabled | enabled .br .RE .RE .RS .LP If multi-scheduling is enabled, more than one scheduler thread is used by the emulator\&. Multi-scheduling can be blocked in two different ways\&. Either all schedulers but one is blocked, or all \fInormal\fR\& schedulers but one is blocked\&. When only normal schedulers are blocked, dirty schedulers are free to continue to schedule processes\&. .LP If \fIBlockState =:= block\fR\&, multi-scheduling is blocked\&. That is, one and only one scheduler thread will execute\&. If \fIBlockState =:= unblock\fR\& and no one else blocks multi-scheduling, and this process has blocked only once, multi-scheduling is unblocked\&. .LP If \fIBlockState =:= block_normal\fR\&, normal multi-scheduling is blocked\&. That is, only one normal scheduler thread will execute, but multiple dirty schedulers can execute\&. If \fIBlockState =:= unblock_normal\fR\& and no one else blocks normal multi-scheduling, and this process has blocked only once, normal multi-scheduling is unblocked\&. .LP One process can block multi-scheduling and normal multi-scheduling multiple times\&. If a process has blocked multiple times, it must unblock exactly as many times as it has blocked before it has released its multi-scheduling block\&. If a process that has blocked multi-scheduling or normal multi-scheduling exits, it automatically releases its blocking of multi-scheduling and normal multi-scheduling\&. .LP The return values are \fIdisabled\fR\&, \fIblocked\fR\&, \fIblocked_normal\fR\&, or \fIenabled\fR\&\&. The returned value describes the state just after the call to \fIerlang:system_flag(multi_scheduling, BlockState)\fR\& has been made\&. For information about the return values, see \fIerlang:system_info(multi_scheduling)\fR\&\&. .LP .RS -4 .B Note: .RE Blocking of multi-scheduling and normal multi-scheduling is normally not needed\&. If you feel that you need to use these features, consider it a few more times again\&. Blocking multi-scheduling is only to be used as a last resort, as it is most likely a \fIvery inefficient\fR\& way to solve the problem\&. .LP See also \fIerlang:system_info(multi_scheduling)\fR\&, \fIerlang:system_info(normal_multi_scheduling_blockers)\fR\&, \fIerlang:system_info(multi_scheduling_blockers)\fR\&, and \fIerlang:system_info(schedulers)\fR\&\&. .RE .LP .nf .B erlang:system_flag(Flag :: outstanding_system_requests_limit, .B NewLimit) -> .B OldLimit .br .fi .br .RS .LP Types: .RS 3 NewLimit = OldLimit = 1\&.\&.134217727 .br .RE .RE .RS .LP Sets a limit on the amount of outstanding requests made by a system process orchestrating system wide changes\&. Currently there are two such processes: .RS 2 .TP 2 .B The Code Purger: The code purger orchestrates checking of references to old code before old code is removed from the system\&. .TP 2 .B The Literal Area Collector: The literal area collector orchestrates copying of references from old literal areas before removal of such areas from the system\&. .RE .LP Each of these processes are allowed to have as many outstanding requests as this limit is set to\&. By default this limit is set to twice the amount of schedulers on the system\&. This will ensure that schedulers will have enough work scheduled to perform these operations as quickly as possible at the same time as other work will be interleaved with this work\&. Currently used limit can be checked by calling \fIerlang:system_info(outstanding_system_requests_limit)\fR\&\&. .LP This limit can also be set by passing the command line argument \fI+zosrl \fR\& to \fIerl\fR\&\&. .RE .LP .nf .B erlang:system_flag(Flag :: scheduler_bind_type, How) -> .B OldBindType .br .fi .br .RS .LP Types: .RS 3 How = scheduler_bind_type() | default_bind .br OldBindType = scheduler_bind_type() .br .nf \fBscheduler_bind_type()\fR\& = .br no_node_processor_spread | no_node_thread_spread | no_spread | .br processor_spread | spread | thread_spread | .br thread_no_node_processor_spread | unbound .fi .br .RE .RE .RS .LP .RS -4 .B Warning: .RE \fIThis argument is deprecated\&.\fR\& Instead of using this argument, use command-line argument \fI+sbt\fR\& in \fIerl(1)\fR\&\&. When this argument is removed, a final scheduler bind type to use is determined at emulator boot time\&. .LP Controls if and how schedulers are bound to logical processors\&. .LP When \fIerlang:system_flag(scheduler_bind_type, How)\fR\& is called, an asynchronous signal is sent to all schedulers online, causing them to try to bind or unbind as requested\&. .LP .RS -4 .B Note: .RE If a scheduler fails to bind, this is often silently ignored, as it is not always possible to verify valid logical processor identifiers\&. If an error is reported, an error event is logged\&. To verify that the schedulers have bound as requested, call \fIerlang:system_info(scheduler_bindings)\fR\&\&. .LP Schedulers can be bound on newer Linux, Solaris, FreeBSD, and Windows systems, but more systems will be supported in future releases\&. .LP In order for the runtime system to be able to bind schedulers, the CPU topology must be known\&. If the runtime system fails to detect the CPU topology automatically, it can be defined\&. For more information on how to define the CPU topology, see command-line flag \fI+sct\fR\& in \fIerl(1)\fR\&\&. .LP The runtime system does by default \fInot\fR\& bind schedulers to logical processors\&. .LP .RS -4 .B Note: .RE If the Erlang runtime system is the only OS process binding threads to logical processors, this improves the performance of the runtime system\&. However, if other OS processes (for example, another Erlang runtime system) also bind threads to logical processors, there can be a performance penalty instead\&. Sometimes this performance penalty can be severe\&. If so, it is recommended to not bind the schedulers\&. .LP Schedulers can be bound in different ways\&. Argument \fIHow\fR\& determines how schedulers are bound and can be any of the following: .RS 2 .TP 2 .B \fIunbound\fR\&: Same as command-line argument \fI+sbt u\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIno_spread\fR\&: Same as command-line argument \fI+sbt ns\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIthread_spread\fR\&: Same as command-line argument \fI+sbt ts\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIprocessor_spread\fR\&: Same as command-line argument \fI+sbt ps\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIspread\fR\&: Same as command-line argument \fI+sbt s\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIno_node_thread_spread\fR\&: Same as command-line argument \fI+sbt nnts\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIno_node_processor_spread\fR\&: Same as command-line argument \fI+sbt nnps\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIthread_no_node_processor_spread\fR\&: Same as command-line argument \fI+sbt tnnps\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIdefault_bind\fR\&: Same as command-line argument \fI+sbt db\fR\& in \fIerl(1)\fR\&\&. .RE .LP The returned value equals \fIHow\fR\& before flag \fIscheduler_bind_type\fR\& was changed\&. .LP Failures: .RS 2 .TP 2 .B \fInotsup\fR\&: If binding of schedulers is not supported\&. .TP 2 .B \fIbadarg\fR\&: If \fIHow\fR\& is not one of the documented alternatives\&. .TP 2 .B \fIbadarg\fR\&: If CPU topology information is unavailable\&. .RE .LP The scheduler bind type can also be set by passing command-line argument \fI+sbt\fR\& to \fIerl(1)\fR\&\&. .LP For more information, see \fIerlang:system_info(scheduler_bind_type)\fR\&, \fIerlang:system_info(scheduler_bindings)\fR\&, as well as command-line flags \fI+sbt\fR\& and \fI+sct\fR\& in \fIerl(1)\fR\&\&. .RE .LP .nf .B erlang:system_flag(Flag :: scheduler_wall_time, Boolean) -> .B OldBoolean .br .fi .br .RS .LP Types: .RS 3 Boolean = OldBoolean = boolean() .br .RE .RE .RS .LP Try enable or disable scheduler wall time measurements by passing \fIBoolean\fR\& as either \fItrue\fR\& or \fIfalse\fR\&\&. .LP For more information about how to use scheduler wall time measurements, see \fIstatistics(scheduler_wall_time)\fR\&\&. .LP Scheduler wall time measurements has a node global state\&. It is either enabled for all processes on the node or disabled for all processes\&. Each process has a logical counter initialized as zero\&. A call with \fIBoolean\fR\& as \fItrue\fR\& will increase that counter one step for the calling process\&. A call with \fIfalse\fR\& will decrease it one step unless it already is zero\&. The node global state for \fIscheduler_wall_time\fR\& will be enabled as long as there is at least one process alive with a counter value larger than zero\&. When a process terminates, its counter will also disappear\&. To ensure \fIscheduler_wall_time\fR\& is kept enabled, the process that enabled it must therefore be kept alive\&. .LP Returns the old value of the node global state, \fItrue\fR\& if scheduler wall time measurements were enabled, \fIfalse\fR\& if it were disabled\&. .LP Scheduler wall time measurements do consume some cpu overhead and should not be left turned on unless used\&. .RE .LP .nf .B erlang:system_flag(Flag :: schedulers_online, SchedulersOnline) -> .B OldSchedulersOnline .br .fi .br .RS .LP Types: .RS 3 SchedulersOnline = OldSchedulersOnline = integer() >= 1 .br .RE .RE .RS .LP Sets the number of schedulers online\&. Range is \fI1 <= SchedulersOnline <= erlang:system_info(schedulers)\fR\&\&. .LP Returns the old value of the flag\&. .LP If the emulator was built with support for dirty schedulers, changing the number of schedulers online can also change the number of dirty CPU schedulers online\&. For example, if 12 schedulers and 6 dirty CPU schedulers are online, and \fIsystem_flag/2\fR\& is used to set the number of schedulers online to 6, then the number of dirty CPU schedulers online is automatically decreased by half as well, down to 3\&. Similarly, the number of dirty CPU schedulers online increases proportionally to increases in the number of schedulers online\&. .LP For more information, see \fIerlang:system_info(schedulers)\fR\& and \fIerlang:system_info(schedulers_online)\fR\&\&. .RE .LP .nf .B erlang:system_flag(Flag :: system_logger, Logger) -> PrevLogger .br .fi .br .RS .LP Types: .RS 3 Logger = PrevLogger = logger | undefined | pid() .br .RE .RE .RS .LP Sets the process that will receive the logging messages generated by ERTS\&. If set to \fIundefined\fR\&, all logging messages generated by ERTS will be dropped\&. The messages will be in the format: .LP .nf {log,Level,Format,ArgList,Metadata} where Level = atom(), Format = string(), ArgList = list(term()), Metadata = #{ pid => pid(), group_leader => pid(), time := logger:timestamp(), error_logger := #{ emulator := true, tag := atom() } .fi .LP If the \fIsystem_logger\fR\& process dies, this flag will be reset to \fIlogger\fR\&\&. .LP The default is the process named \fIlogger\fR\&\&. .LP Returns the old value of the flag\&. .LP .RS -4 .B Note: .RE This function is designed to be used by the KERNEL \fIlogger\fR\&\&. Be careful if you change it to something else as log messages may be lost\&. If you want to intercept emulator log messages, do it by adding a specialized handler to the KERNEL logger\&. .RE .LP .nf .B erlang:system_flag(Flag :: trace_control_word, TCW) -> OldTCW .br .fi .br .RS .LP Types: .RS 3 TCW = OldTCW = integer() >= 0 .br .RE .RE .RS .LP Sets the value of the node trace control word to \fITCW\fR\&, which is to be an unsigned integer\&. For more information, see function \fIset_tcw\fR\& in section "Match Specifications in Erlang" in the User\&'s Guide\&. .LP Returns the old value of the flag\&. .RE .LP .nf .B erlang:system_flag(Flag :: time_offset, Value :: finalize) -> .B OldState .br .fi .br .RS .LP Types: .RS 3 OldState = preliminary | final | volatile .br .RE .RE .RS .LP Finalizes the time offset when single time warp mode is used\&. If another time warp mode is used, the time offset state is left unchanged\&. .LP Returns the old state identifier, that is: .RS 2 .TP 2 * If \fIpreliminary\fR\& is returned, finalization was performed and the time offset is now final\&. .LP .TP 2 * If \fIfinal\fR\& is returned, the time offset was already in the final state\&. This either because another \fIerlang:system_flag(time_offset, finalize)\fR\& call or because no time warp mode is used\&. .LP .TP 2 * If \fIvolatile\fR\& is returned, the time offset cannot be finalized because multi-time warp mode is used\&. .LP .RE .RE .LP .nf .B erlang:system_info(Item :: update_cpu_info) -> changed | unchanged .br .fi .br .RS .LP Returns information about the current system\&. The documentation of this function is broken into the following sections in order to make it easier to navigate\&. .RS 2 .TP 2 .B \fIMemory Allocation\fR\&: \fIallocated_areas\fR\&, \fIallocator\fR\&, \fIalloc_util_allocators\fR\&, \fIallocator_sizes\fR\& .TP 2 .B \fICPU Topology\fR\&: \fIcpu_topology\fR\&, \fIlogical_processors\fR\&, \fIupdate_cpu_info\fR\& .TP 2 .B \fIProcess Information\fR\&: \fIfullsweep_after\fR\&, \fIgarbage_collection\fR\&, \fIheap_sizes\fR\&, \fIheap_type\fR\&, \fImax_heap_size\fR\&, \fImessage_queue_data\fR\&, \fImin_heap_size\fR\&, \fImin_bin_vheap_size\fR\&, \fIprocs\fR\& .TP 2 .B \fISystem Limits\fR\&: \fIatom_count\fR\&, \fIatom_limit\fR\&, \fIets_count\fR\&, \fIets_limit\fR\&, \fIport_count\fR\&, \fIport_limit\fR\&, \fIprocess_count\fR\&, \fIprocess_limit\fR\& .TP 2 .B \fISystem Time\fR\&: \fIend_time\fR\&, \fIos_monotonic_time_source\fR\&, \fIos_system_time_source\fR\&, \fIstart_time\fR\&, \fItime_correction\fR\&, \fItime_offset\fR\&, \fItime_warp_mode\fR\&, \fItolerant_timeofday\fR\& .TP 2 .B \fIScheduler Information\fR\&: \fIdirty_cpu_schedulers\fR\&, \fIdirty_cpu_schedulers_online\fR\&, \fIdirty_io_schedulers\fR\&, \fImulti_scheduling\fR\&, \fImulti_scheduling_blockers\fR\&, \fInormal_multi_scheduling_blockers\fR\&, \fIscheduler_bind_type\fR\&, \fIscheduler_bindings\fR\&, \fIscheduler_id\fR\&, \fIschedulers\fR\&, \fIsmp_support\fR\&, \fIthreads\fR\&, \fIthread_pool_size\fR\& .TP 2 .B \fIDistribution Information\fR\&: \fIcreation\fR\&, \fIdelayed_node_table_gc\fR\&, \fIdist\fR\&, \fIdist_buf_busy_limit\fR\&, \fIdist_ctrl\fR\& .TP 2 .B \fISystem Information\fR\&: \fIc_compiler_used\fR\&, \fIcheck_io\fR\&, \fIcompat_rel\fR\&, \fIdebug_compiled\fR\&, \fIdriver_version\fR\&, \fIdynamic_trace\fR\&, \fIdynamic_trace_probes\fR\&, \fIemu_flavor\fR\&, \fIemu_type\fR\&, \fIinfo\fR\&, \fIkernel_poll\fR\&, \fIloaded\fR\&, \fImachine\fR\&, \fImodified_timing_level\fR\&, \fInif_version\fR\&, \fIotp_release\fR\&, \fIoutstanding_system_requests_limit\fR\&, \fIport_parallelism\fR\&, \fIsystem_architecture\fR\&, \fIsystem_logger\fR\&, \fIsystem_version\fR\&, \fItrace_control_word\fR\&, \fIversion\fR\&, \fIwordsize\fR\& .RE .RE .LP .nf .B erlang:system_info(Item :: allocated_areas) -> [tuple()] .br .fi .br .nf .B erlang:system_info(Item :: allocator) -> .B {Allocator, Version, Features, Settings} .br .fi .br .nf .B erlang:system_info(Item :: {allocator, Alloc}) -> [term()] .br .fi .br .nf .B erlang:system_info(Item :: alloc_util_allocators) -> [Alloc] .br .fi .br .nf .B erlang:system_info(Item :: {allocator_sizes, Alloc}) -> [term()] .br .fi .br .RS .LP Types: .RS 3 Allocator = undefined | glibc .br Version = [integer() >= 0] .br Features = [atom()] .br Settings = .br [{Subsystem :: atom(), .br [{Parameter :: atom(), Value :: term()}]}] .br Alloc = atom() .br .RE .RE .RS .LP Returns various information about the memory allocators of the current system (emulator) as specified by \fIItem\fR\&: .RS 2 .TP 2 .B \fIallocated_areas\fR\&: Returns a list of tuples with information about miscellaneous allocated memory areas\&. .RS 2 .LP Each tuple contains an atom describing the type of memory as first element and the amount of allocated memory in bytes as second element\&. When information about allocated and used memory is present, also a third element is present, containing the amount of used memory in bytes\&. .RE .RS 2 .LP \fIerlang:system_info(allocated_areas)\fR\& is intended for debugging, and the content is highly implementation-dependent\&. The content of the results therefore changes when needed without prior notice\&. .RE .RS 2 .LP Notice that the sum of these values is \fInot\fR\& the total amount of memory allocated by the emulator\&. Some values are part of other values, and some memory areas are not part of the result\&. For information about the total amount of memory allocated by the emulator, see \fIerlang:memory/0,1\fR\&\&. .RE .TP 2 .B \fIallocator\fR\&: Returns \fI{Allocator, Version, Features, Settings\fR\&, where: .RS 2 .TP 2 * \fIAllocator\fR\& corresponds to the \fImalloc()\fR\& implementation used\&. If \fIAllocator\fR\& equals \fIundefined\fR\&, the \fImalloc()\fR\& implementation used cannot be identified\&. \fIglibc\fR\& can be identified\&. .LP .TP 2 * \fIVersion\fR\& is a list of integers (but not a string) representing the version of the \fImalloc()\fR\& implementation used\&. .LP .TP 2 * \fIFeatures\fR\& is a list of atoms representing the allocation features used\&. .LP .TP 2 * \fISettings\fR\& is a list of subsystems, their configurable parameters, and used values\&. Settings can differ between different combinations of platforms, allocators, and allocation features\&. Memory sizes are given in bytes\&. .LP .RE .RS 2 .LP See also "System Flags Effecting erts_alloc" in \fIerts_alloc(3erl)\fR\&\&. .RE .TP 2 .B \fI{allocator, Alloc}\fR\&: Returns information about the specified allocator\&. As from ERTS 5\&.6\&.1, the return value is a list of \fI{instance, InstanceNo, InstanceInfo}\fR\& tuples, where \fIInstanceInfo\fR\& contains information about a specific instance of the allocator\&. If \fIAlloc\fR\& is not a recognized allocator, \fIundefined\fR\& is returned\&. If \fIAlloc\fR\& is disabled, \fIfalse\fR\& is returned\&. .RS 2 .LP Notice that the information returned is highly implementation-dependent and can be changed or removed at any time without prior notice\&. It was initially intended as a tool when developing new allocators, but as it can be of interest for others it has been briefly documented\&. .RE .RS 2 .LP The recognized allocators are listed in \fIerts_alloc(3erl)\fR\&\&. Information about super carriers can be obtained from ERTS 8\&.0 with \fI{allocator, erts_mmap}\fR\& or from ERTS 5\&.10\&.4; the returned list when calling with \fI{allocator, mseg_alloc}\fR\& also includes an \fI{erts_mmap, _}\fR\& tuple as one element in the list\&. .RE .RS 2 .LP After reading the \fIerts_alloc(3erl)\fR\& documentation, the returned information more or less speaks for itself, but it can be worth explaining some things\&. Call counts are presented by two values, the first value is giga calls, and the second value is calls\&. \fImbcs\fR\& and \fIsbcs\fR\& denote multi-block carriers, and single-block carriers, respectively\&. Sizes are presented in bytes\&. When a size is not presented, it is the amount of something\&. Sizes and amounts are often presented by three values: .RE .RS 2 .TP 2 * The first is the current value\&. .LP .TP 2 * The second is the maximum value since the last call to \fIerlang:system_info({allocator, Alloc})\fR\&\&. .LP .TP 2 * The third is the maximum value since the emulator was started\&. .LP .RE .RS 2 .LP If only one value is present, it is the current value\&. \fIfix_alloc\fR\& memory block types are presented by two values\&. The first value is the memory pool size and the second value is the used memory size\&. .RE .TP 2 .B \fIalloc_util_allocators\fR\&: Returns a list of the names of all allocators using the ERTS internal \fIalloc_util\fR\& framework as atoms\&. For more information, see section The alloc_util framework in \fIerts_alloc(3erl)\fR\&\&. .TP 2 .B \fI{allocator_sizes, Alloc}\fR\&: Returns various size information for the specified allocator\&. The information returned is a subset of the information returned by \fIerlang:system_info({allocator, Alloc})\fR\&\&. .RE .RE .LP .nf .B erlang:system_info(Item :: cpu_topology) -> CpuTopology .br .fi .br .nf .B erlang:system_info(Item :: .B {cpu_topology, defined | detected | used}) -> .B CpuTopology .br .fi .br .nf .B erlang:system_info(Item :: .B logical_processors | .B logical_processors_available | .B logical_processors_online) -> .B unknown | integer() >= 1 .br .fi .br .nf .B erlang:system_info(Item :: trace_control_word) -> .B integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 .nf \fBcpu_topology()\fR\& = [LevelEntry :: level_entry()] | undefined .fi .br .RS 2 All \fILevelEntry\fR\&s of a list must contain the same \fILevelTag\fR\&, except on the top level where both \fInode\fR\& and \fIprocessor\fR\&\fILevelTag\fR\&s can coexist\&. .RE .nf \fBlevel_entry()\fR\& = .br {LevelTag :: level_tag(), SubLevel :: sub_level()} | .br {LevelTag :: level_tag(), .br InfoList :: info_list(), .br SubLevel :: sub_level()} .fi .br .RS 2 \fI{LevelTag, SubLevel} == {LevelTag, [], SubLevel}\fR\& .RE .nf \fBlevel_tag()\fR\& = core | node | processor | thread .fi .br .RS 2 More \fILevelTag\fR\&s can be introduced in a future release\&. .RE .nf \fBsub_level()\fR\& = .br [LevelEntry :: level_entry()] | .br (LogicalCpuId :: {logical, integer() >= 0}) .fi .br .nf \fBinfo_list()\fR\& = [] .fi .br .RS 2 The \fIinfo_list()\fR\& can be extended in a future release\&. .RE .RE .RE .RS .LP Returns various information about the CPU topology of the current system (emulator) as specified by \fIItem\fR\&: .RS 2 .TP 2 .B \fIcpu_topology\fR\&: Returns the \fICpuTopology\fR\& currently used by the emulator\&. The CPU topology is used when binding schedulers to logical processors\&. The CPU topology used is the user-defined CPU topology, if such exists, otherwise the automatically detected CPU topology, if such exists\&. If no CPU topology exists, \fIundefined\fR\& is returned\&. .RS 2 .LP \fInode\fR\& refers to Non-Uniform Memory Access (NUMA) nodes\&. \fIthread\fR\& refers to hardware threads (for example, Intel hyper-threads)\&. .RE .RS 2 .LP A level in term \fICpuTopology\fR\& can be omitted if only one entry exists and \fIInfoList\fR\& is empty\&. .RE .RS 2 .LP \fIthread\fR\& can only be a sublevel to \fIcore\fR\&\&. \fIcore\fR\& can be a sublevel to \fIprocessor\fR\& or \fInode\fR\&\&. \fIprocessor\fR\& can be on the top level or a sublevel to \fInode\fR\&\&. \fInode\fR\& can be on the top level or a sublevel to \fIprocessor\fR\&\&. That is, NUMA nodes can be processor internal or processor external\&. A CPU topology can consist of a mix of processor internal and external NUMA nodes, as long as each logical CPU belongs to \fIone\fR\& NUMA node\&. Cache hierarchy is not part of the \fICpuTopology\fR\& type, but will be in a future release\&. Other things can also make it into the CPU topology in a future release\&. So, expect the \fICpuTopology\fR\& type to change\&. .RE .TP 2 .B \fI{cpu_topology, defined}\fR\&: .RS 2 .LP Returns the user-defined \fICpuTopology\fR\&\&. For more information, see command-line flag \fI+sct\fR\& in \fIerl(1)\fR\& and argument \fIcpu_topology\fR\&\&. .RE .TP 2 .B \fI{cpu_topology, detected}\fR\&: .RS 2 .LP Returns the automatically detected \fICpuTopologyy\fR\&\&. The emulator detects the CPU topology on some newer Linux, Solaris, FreeBSD, and Windows systems\&. On Windows system with more than 32 logical processors, the CPU topology is not detected\&. .RE .RS 2 .LP For more information, see argument \fIcpu_topology\fR\&\&. .RE .TP 2 .B \fI{cpu_topology, used}\fR\&: Returns \fICpuTopology\fR\& used by the emulator\&. For more information, see argument \fIcpu_topology\fR\&\&. .TP 2 .B \fIlogical_processors\fR\&: Returns the detected number of logical processors configured in the system\&. The return value is either an integer, or the atom \fIunknown\fR\& if the emulator cannot detect the configured logical processors\&. .TP 2 .B \fIlogical_processors_available\fR\&: Returns the detected number of logical processors available to the Erlang runtime system\&. The return value is either an integer, or the atom \fIunknown\fR\& if the emulator cannot detect the available logical processors\&. The number of available logical processors is less than or equal to the number of logical processors online\&. .TP 2 .B \fIlogical_processors_online\fR\&: Returns the detected number of logical processors online on the system\&. The return value is either an integer, or the atom \fIunknown\fR\& if the emulator cannot detect logical processors online\&. The number of logical processors online is less than or equal to the number of logical processors configured\&. .TP 2 .B \fIcpu_quota\fR\&: Returns the detected CPU quota the emulator is limited by\&. The return value is an integer saying how many processors\&' worth of runtime we get (between 1 and the number of logical processors), or the atom \fIunknown\fR\& if the emulator cannot detect a quota\&. .TP 2 .B \fIupdate_cpu_info\fR\&: The runtime system rereads the CPU information available and updates its internally stored information about the detected CPU topology and the number of logical processors configured, online, available, and cpu quota\&. .RS 2 .LP If the CPU information has changed since the last time it was read, the atom \fIchanged\fR\& is returned, otherwise the atom \fIunchanged\fR\&\&. If the CPU information has changed, you probably want to adjust the number of schedulers online\&. You typically want to have as many schedulers online as logical processors available\&. .RE .RE .RE .LP .nf .B erlang:system_info(Item :: fullsweep_after) -> .B {fullsweep_after, integer() >= 0} .br .fi .br .nf .B erlang:system_info(Item :: garbage_collection) -> .B [{atom(), integer()}] .br .fi .br .nf .B erlang:system_info(Item :: heap_sizes) -> [integer() >= 0] .br .fi .br .nf .B erlang:system_info(Item :: heap_type) -> private .br .fi .br .nf .B erlang:system_info(Item :: max_heap_size) -> .B {max_heap_size, .B MaxHeapSize :: max_heap_size()} .br .fi .br .nf .B erlang:system_info(Item :: message_queue_data) -> .B message_queue_data() .br .fi .br .nf .B erlang:system_info(Item :: min_heap_size) -> .B {min_heap_size, .B MinHeapSize :: integer() >= 1} .br .fi .br .nf .B erlang:system_info(Item :: min_bin_vheap_size) -> .B {min_bin_vheap_size, .B MinBinVHeapSize :: integer() >= 1} .br .fi .br .nf .B erlang:system_info(Item :: process_limit) -> integer() >= 1 .br .fi .br .RS .LP Types: .RS 3 .nf \fBmessage_queue_data()\fR\& = off_heap | on_heap .fi .br .nf \fBmax_heap_size()\fR\& = .br integer() >= 0 | .br #{size => integer() >= 0, .br kill => boolean(), .br error_logger => boolean()} .fi .br .RE .RE .RS .LP Returns information about the default process heap settings: .RS 2 .TP 2 .B \fIfullsweep_after\fR\&: Returns \fI{fullsweep_after, integer() >= 0}\fR\&, which is the \fIfullsweep_after\fR\& garbage collection setting used by default\&. For more information, see \fIgarbage_collection\fR\& described below\&. .TP 2 .B \fIgarbage_collection\fR\&: Returns a list describing the default garbage collection settings\&. A process spawned on the local node by a \fIspawn\fR\& or \fIspawn_link\fR\& uses these garbage collection settings\&. The default settings can be changed by using \fIerlang:system_flag/2\fR\&\&. \fIspawn_opt/2,3,4\fR\& can spawn a process that does not use the default settings\&. .TP 2 .B \fIheap_sizes\fR\&: Returns a list of integers representing valid heap sizes in words\&. All Erlang heaps are sized from sizes in this list\&. .TP 2 .B \fIheap_type\fR\&: Returns the heap type used by the current emulator\&. One heap type exists: .RS 2 .TP 2 .B \fIprivate\fR\&: Each process has a heap reserved for its use and no references between heaps of different processes are allowed\&. Messages passed between processes are copied between heaps\&. .RE .TP 2 .B \fImax_heap_size\fR\&: Returns \fI{max_heap_size, MaxHeapSize}\fR\&, where \fIMaxHeapSize\fR\& is the current system-wide maximum heap size settings for spawned processes\&. This setting can be set using the command-line flags \fI+hmax\fR\&, \fI+hmaxk\fR\& and \fI+hmaxel\fR\& in \fIerl(1)\fR\&\&. It can also be changed at runtime using \fIerlang:system_flag(max_heap_size, MaxHeapSize)\fR\&\&. For more details about the \fImax_heap_size\fR\& process flag, see \fIprocess_flag(max_heap_size, MaxHeapSize)\fR\&\&. .TP 2 .B \fImessage_queue_data\fR\&: Returns the default value of the \fImessage_queue_data\fR\& process flag, which can be either \fIoff_heap\fR\& or \fIon_heap\fR\&\&. The default value is set by the command-line argument \fI+hmqd\fR\& in \fIerl(1)\fR\&\&. For more information, see the documentation of \fIprocess_flag(message_queue_data, MQD)\fR\&\&. .TP 2 .B \fImin_heap_size\fR\&: Returns \fI{min_heap_size, MinHeapSize}\fR\&, where \fIMinHeapSize\fR\& is the current system-wide minimum heap size for spawned processes\&. .TP 2 .B \fImin_bin_vheap_size\fR\&: Returns \fI{min_bin_vheap_size, MinBinVHeapSize}\fR\&, where \fIMinBinVHeapSize\fR\& is the current system-wide minimum binary virtual heap size for spawned processes\&. .TP 2 .B \fIprocs\fR\&: Returns a binary containing a string of process and port information formatted as in Erlang crash dumps\&. For more information, see section How to interpret the Erlang crash dumps in the User\&'s Guide\&. .RE .RE .LP .nf .B erlang:system_info(Item :: atom_count) -> integer() >= 1 .br .fi .br .nf .B erlang:system_info(Item :: atom_limit) -> integer() >= 1 .br .fi .br .nf .B erlang:system_info(Item :: ets_count) -> integer() >= 1 .br .fi .br .nf .B erlang:system_info(Item :: ets_limit) -> integer() >= 1 .br .fi .br .nf .B erlang:system_info(Item :: port_parallelism) -> boolean() .br .fi .br .nf .B erlang:system_info(Item :: port_count) -> integer() >= 0 .br .fi .br .nf .B erlang:system_info(Item :: port_limit) -> integer() >= 1 .br .fi .br .nf .B erlang:system_info(Item :: process_count) -> integer() >= 1 .br .fi .br .RS .LP Returns information about the current system (emulator) limits as specified by \fIItem\fR\&: .RS 2 .TP 2 .B \fIatom_count\fR\&: Returns the number of atoms currently existing at the local node\&. The value is given as an integer\&. .TP 2 .B \fIatom_limit\fR\&: Returns the maximum number of atoms allowed\&. This limit can be increased at startup by passing command-line flag \fI+t\fR\& to \fIerl(1)\fR\&\&. .TP 2 .B \fIets_count\fR\&: Returns the number of ETS tables currently existing at the local node\&. .TP 2 .B \fIets_limit\fR\&: Returns the limit for number of ETS tables\&. This limit is partially obsolete and number of tables are only limited by available memory\&. .TP 2 .B \fIport_count\fR\&: Returns the number of ports currently existing at the local node\&. The value is given as an integer\&. This is the same value as returned by \fIlength(erlang:ports())\fR\&, but more efficient\&. .TP 2 .B \fIport_limit\fR\&: Returns the maximum number of simultaneously existing ports at the local node as an integer\&. This limit can be configured at startup by using command-line flag \fI+Q\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIprocess_count\fR\&: Returns the number of processes currently existing at the local node\&. The value is given as an integer\&. This is the same value as returned by \fIlength(processes())\fR\&, but more efficient\&. .TP 2 .B \fIprocess_limit\fR\&: Returns the maximum number of simultaneously existing processes at the local node\&. The value is given as an integer\&. This limit can be configured at startup by using command-line flag \fI+P\fR\& in \fIerl(1)\fR\&\&. .RE .RE .LP .nf .B erlang:system_info(Item :: end_time) -> integer() >= 0 .br .fi .br .nf .B erlang:system_info(Item :: os_monotonic_time_source) -> .B [{atom(), term()}] .br .fi .br .nf .B erlang:system_info(Item :: os_system_time_source) -> .B [{atom(), term()}] .br .fi .br .nf .B erlang:system_info(Item :: smp_support) -> boolean() .br .fi .br .nf .B erlang:system_info(Item :: thread_pool_size) -> integer() >= 0 .br .fi .br .nf .B erlang:system_info(Item :: time_correction) -> true | false .br .fi .br .nf .B erlang:system_info(Item :: time_offset) -> .B preliminary | final | volatile .br .fi .br .nf .B erlang:system_info(Item :: time_warp_mode) -> .B no_time_warp | single_time_warp | .B multi_time_warp .br .fi .br .RS .LP Returns information about the current system (emulator) time as specified by \fIItem\fR\&: .RS 2 .TP 2 .B \fIend_time\fR\&: The last Erlang monotonic time in \fInative\fR\& time unit that can be represented internally in the current Erlang runtime system instance\&. The time between the start time and the end time is at least a quarter of a millennium\&. .TP 2 .B \fIos_monotonic_time_source\fR\&: Returns a list containing information about the source of OS monotonic time that is used by the runtime system\&. .RS 2 .LP If \fI[]\fR\& is returned, no OS monotonic time is available\&. The list contains two-tuples with \fIKey\fR\&s as first element, and \fIValue\fR\&s as second element\&. The order of these tuples is undefined\&. The following tuples can be part of the list, but more tuples can be introduced in the future: .RE .RS 2 .TP 2 .B \fI{function, Function}\fR\&: \fIFunction\fR\& is the name of the function used\&. This tuple always exists if OS monotonic time is available to the runtime system\&. .TP 2 .B \fI{clock_id, ClockId}\fR\&: This tuple only exists if \fIFunction\fR\& can be used with different clocks\&. \fIClockId\fR\& corresponds to the clock identifier used when calling \fIFunction\fR\&\&. .TP 2 .B \fI{resolution, OsMonotonicTimeResolution}\fR\&: Highest possible resolution of current OS monotonic time source as parts per second\&. If no resolution information can be retrieved from the OS, \fIOsMonotonicTimeResolution\fR\& is set to the resolution of the time unit of \fIFunction\fR\&s return value\&. That is, the actual resolution can be lower than \fIOsMonotonicTimeResolution\fR\&\&. Notice that the resolution does not say anything about the accuracy or whether the precision aligns with the resolution\&. You do, however, know that the precision is not better than \fIOsMonotonicTimeResolution\fR\&\&. .TP 2 .B \fI{extended, Extended}\fR\&: \fIExtended\fR\& equals \fIyes\fR\& if the range of time values has been extended; otherwise \fIExtended\fR\& equals \fIno\fR\&\&. The range must be extended if \fIFunction\fR\& returns values that wrap fast\&. This typically is the case when the return value is a 32-bit value\&. .TP 2 .B \fI{parallel, Parallel}\fR\&: \fIParallel\fR\& equals \fIyes\fR\& if \fIFunction\fR\& is called in parallel from multiple threads\&. If it is not called in parallel, because calls must be serialized, \fIParallel\fR\& equals \fIno\fR\&\&. .TP 2 .B \fI{time, OsMonotonicTime}\fR\&: \fIOsMonotonicTime\fR\& equals current OS monotonic time in \fInative\fR\& time unit\&. .RE .TP 2 .B \fIos_system_time_source\fR\&: Returns a list containing information about the source of OS system time that is used by the runtime system\&. .RS 2 .LP The list contains two-tuples with \fIKey\fR\&s as first element, and \fIValue\fR\&s as second element\&. The order of these tuples is undefined\&. The following tuples can be part of the list, but more tuples can be introduced in the future: .RE .RS 2 .TP 2 .B \fI{function, Function}\fR\&: \fIFunction\fR\& is the name of the function used\&. .TP 2 .B \fI{clock_id, ClockId}\fR\&: Exists only if \fIFunction\fR\& can be used with different clocks\&. \fIClockId\fR\& corresponds to the clock identifier used when calling \fIFunction\fR\&\&. .TP 2 .B \fI{resolution, OsSystemTimeResolution}\fR\&: Highest possible resolution of current OS system time source as parts per second\&. If no resolution information can be retrieved from the OS, \fIOsSystemTimeResolution\fR\& is set to the resolution of the time unit of \fIFunction\fR\&s return value\&. That is, the actual resolution can be lower than \fIOsSystemTimeResolution\fR\&\&. Notice that the resolution does not say anything about the accuracy or whether the precision do align with the resolution\&. You do, however, know that the precision is not better than \fIOsSystemTimeResolution\fR\&\&. .TP 2 .B \fI{parallel, Parallel}\fR\&: \fIParallel\fR\& equals \fIyes\fR\& if \fIFunction\fR\& is called in parallel from multiple threads\&. If it is not called in parallel, because calls needs to be serialized, \fIParallel\fR\& equals \fIno\fR\&\&. .TP 2 .B \fI{time, OsSystemTime}\fR\&: \fIOsSystemTime\fR\& equals current OS system time in \fInative\fR\& time unit\&. .RE .TP 2 .B \fIstart_time\fR\&: The Erlang monotonic time in \fInative\fR\& time unit at the time when current Erlang runtime system instance started\&. .RS 2 .LP See also \fIerlang:system_info(end_time)\fR\&\&. .RE .TP 2 .B \fItime_correction\fR\&: Returns a boolean value indicating whether time correction is enabled or not\&. .TP 2 .B \fItime_offset\fR\&: Returns the state of the time offset: .RS 2 .TP 2 .B \fIpreliminary\fR\&: The time offset is preliminary, and will be changed and finalized later\&. The preliminary time offset is used during the preliminary phase of the single time warp mode\&. .TP 2 .B \fIfinal\fR\&: The time offset is final\&. This either because no time warp mode is used, or because the time offset have been finalized when single time warp mode is used\&. .TP 2 .B \fIvolatile\fR\&: The time offset is volatile\&. That is, it can change at any time\&. This is because multi-time warp mode is used\&. .RE .TP 2 .B \fItime_warp_mode\fR\&: Returns a value identifying the time warp mode that is used: .RS 2 .TP 2 .B \fIno_time_warp\fR\&: The no time warp mode is used\&. .TP 2 .B \fIsingle_time_warp\fR\&: The single time warp mode is used\&. .TP 2 .B \fImulti_time_warp\fR\&: The multi-time warp mode is used\&. .RE .TP 2 .B \fItolerant_timeofday\fR\&: Returns whether a pre ERTS 7\&.0 backwards compatible compensation for sudden changes of system time is \fIenabled\fR\& or \fIdisabled\fR\&\&. Such compensation is \fIenabled\fR\& when the time offset is \fIfinal\fR\&, and time correction is enabled\&. .RE .RE .LP .nf .B erlang:system_info(Item :: dirty_cpu_schedulers) -> .B integer() >= 0 .br .fi .br .nf .B erlang:system_info(Item :: dirty_cpu_schedulers_online) -> .B integer() >= 0 .br .fi .br .nf .B erlang:system_info(Item :: dirty_io_schedulers) -> .B integer() >= 0 .br .fi .br .nf .B erlang:system_info(Item :: multi_scheduling) -> .B disabled | blocked | blocked_normal | .B enabled .br .fi .br .nf .B erlang:system_info(Item :: multi_scheduling_blockers) -> .B [Pid :: pid()] .br .fi .br .nf .B erlang:system_info(Item :: normal_multi_scheduling_blockers) -> .B [Pid :: pid()] .br .fi .br .nf .B erlang:system_info(Item :: procs) -> binary() .br .fi .br .nf .B erlang:system_info(Item :: scheduler_bind_type) -> .B spread | processor_spread | thread_spread | .B thread_no_node_processor_spread | .B no_node_processor_spread | .B no_node_thread_spread | no_spread | unbound .br .fi .br .nf .B erlang:system_info(Item :: scheduler_bindings) -> tuple() .br .fi .br .nf .B erlang:system_info(Item :: scheduler_id) -> .B SchedulerId :: integer() >= 1 .br .fi .br .nf .B erlang:system_info(Item :: schedulers | schedulers_online) -> .B integer() >= 1 .br .fi .br .nf .B erlang:system_info(Item :: system_version) -> string() .br .fi .br .nf .B erlang:system_info(Item :: threads) -> boolean() .br .fi .br .RS .LP Returns information about schedulers, scheduling and threads in the current system as specified by \fIItem\fR\&: .RS 2 .TP 2 .B \fIdirty_cpu_schedulers\fR\&: Returns the number of dirty CPU scheduler threads used by the emulator\&. Dirty CPU schedulers execute CPU-bound native functions, such as NIFs, linked-in driver code, and BIFs that cannot be managed cleanly by the normal emulator schedulers\&. .RS 2 .LP The number of dirty CPU scheduler threads is determined at emulator boot time and cannot be changed after that\&. However, the number of dirty CPU scheduler threads online can be changed at any time\&. The number of dirty CPU schedulers can be set at startup by passing command-line flag \fI+SDcpu\fR\& or \fI+SDPcpu\fR\& in \fIerl(1)\fR\&\&. .RE .RS 2 .LP See also \fIerlang:system_flag(dirty_cpu_schedulers_online, DirtyCPUSchedulersOnline)\fR\&, \fIerlang:system_info(dirty_cpu_schedulers_online)\fR\&, \fIerlang:system_info(dirty_io_schedulers)\fR\&, \fIerlang:system_info(schedulers)\fR\&, \fIerlang:system_info(schedulers_online)\fR\&, and \fIerlang:system_flag(schedulers_online, SchedulersOnline)\fR\&\&. .RE .TP 2 .B \fIdirty_cpu_schedulers_online\fR\&: Returns the number of dirty CPU schedulers online\&. The return value satisfies \fI1 <= DirtyCPUSchedulersOnline <= N\fR\&, where \fIN\fR\& is the smallest of the return values of \fIerlang:system_info(dirty_cpu_schedulers)\fR\& and \fIerlang:system_info(schedulers_online)\fR\&\&. .RS 2 .LP The number of dirty CPU schedulers online can be set at startup by passing command-line flag \fI+SDcpu\fR\& in \fIerl(1)\fR\&\&. .RE .RS 2 .LP For more information, see \fIerlang:system_info(dirty_cpu_schedulers)\fR\&, \fIerlang:system_info(dirty_io_schedulers)\fR\&, \fIerlang:system_info(schedulers_online)\fR\&, and \fIerlang:system_flag(dirty_cpu_schedulers_online, DirtyCPUSchedulersOnline)\fR\&\&. .RE .TP 2 .B \fIdirty_io_schedulers\fR\&: Returns the number of dirty I/O schedulers as an integer\&. Dirty I/O schedulers execute I/O-bound native functions, such as NIFs and linked-in driver code, which cannot be managed cleanly by the normal emulator schedulers\&. .RS 2 .LP This value can be set at startup by passing command-line argument \fI+SDio\fR\& in \fIerl(1)\fR\&\&. .RE .RS 2 .LP For more information, see \fIerlang:system_info(dirty_cpu_schedulers)\fR\&, \fIerlang:system_info(dirty_cpu_schedulers_online)\fR\&, and \fIerlang:system_flag(dirty_cpu_schedulers_online, DirtyCPUSchedulersOnline)\fR\&\&. .RE .TP 2 .B \fImulti_scheduling\fR\&: Returns one of the following: .RS 2 .TP 2 .B \fIdisabled\fR\&: The emulator has been started with only one scheduler thread\&. .TP 2 .B \fIblocked\fR\&: The emulator has more than one scheduler thread, but all scheduler threads except one are blocked\&. That is, only one scheduler thread schedules Erlang processes and executes Erlang code\&. .TP 2 .B \fIblocked_normal\fR\&: The emulator has more than one scheduler thread, but all normal scheduler threads except one are blocked\&. Notice that dirty schedulers are not blocked, and can schedule Erlang processes and execute native code\&. .TP 2 .B \fIenabled\fR\&: The emulator has more than one scheduler thread, and no scheduler threads are blocked\&. That is, all available scheduler threads schedule Erlang processes and execute Erlang code\&. .RE .RS 2 .LP See also \fIerlang:system_flag(multi_scheduling, BlockState)\fR\&, \fIerlang:system_info(multi_scheduling_blockers)\fR\&, \fIerlang:system_info(normal_multi_scheduling_blockers)\fR\&, and \fIerlang:system_info(schedulers)\fR\&\&. .RE .TP 2 .B \fImulti_scheduling_blockers\fR\&: Returns a list of \fIPid\fR\&s when multi-scheduling is blocked, otherwise the empty list is returned\&. The \fIPid\fR\&s in the list represent all the processes currently blocking multi-scheduling\&. A \fIPid\fR\& occurs only once in the list, even if the corresponding process has blocked multiple times\&. .RS 2 .LP See also \fIerlang:system_flag(multi_scheduling, BlockState)\fR\&, \fIerlang:system_info(multi_scheduling)\fR\&, \fIerlang:system_info(normal_multi_scheduling_blockers)\fR\&, and \fIerlang:system_info(schedulers)\fR\&\&. .RE .TP 2 .B \fInormal_multi_scheduling_blockers\fR\&: Returns a list of \fIPid\fR\&s when normal multi-scheduling is blocked (that is, all normal schedulers but one is blocked), otherwise the empty list is returned\&. The \fIPid\fR\&s in the list represent all the processes currently blocking normal multi-scheduling\&. A \fIPid\fR\& occurs only once in the list, even if the corresponding process has blocked multiple times\&. .RS 2 .LP See also \fIerlang:system_flag(multi_scheduling, BlockState)\fR\&, \fIerlang:system_info(multi_scheduling)\fR\&, \fIerlang:system_info(multi_scheduling_blockers)\fR\&, and \fIerlang:system_info(schedulers)\fR\&\&. .RE .TP 2 .B \fIscheduler_bind_type\fR\&: Returns information about how the user has requested schedulers to be bound or not bound\&. .RS 2 .LP Notice that although a user has requested schedulers to be bound, they can silently have failed to bind\&. To inspect the scheduler bindings, call \fIerlang:system_info(scheduler_bindings)\fR\&\&. .RE .RS 2 .LP For more information, see command-line argument \fI+sbt\fR\& in \fIerl(1)\fR\& and \fIerlang:system_info(scheduler_bindings)\fR\&\&. .RE .TP 2 .B \fIscheduler_bindings\fR\&: Returns information about the currently used scheduler bindings\&. .RS 2 .LP A tuple of a size equal to \fIerlang:system_info(schedulers)\fR\& is returned\&. The tuple elements are integers or the atom \fIunbound\fR\&\&. Logical processor identifiers are represented as integers\&. The \fIN\fR\&th element of the tuple equals the current binding for the scheduler with the scheduler identifier equal to \fIN\fR\&\&. For example, if the schedulers are bound, \fIelement(erlang:system_info(scheduler_id), erlang:system_info(scheduler_bindings))\fR\& returns the identifier of the logical processor that the calling process is executing on\&. .RE .RS 2 .LP Notice that only schedulers online can be bound to logical processors\&. .RE .RS 2 .LP For more information, see command-line argument \fI+sbt\fR\& in \fIerl(1)\fR\& and \fIerlang:system_info(schedulers_online)\fR\&\&. .RE .TP 2 .B \fIscheduler_id\fR\&: Returns the scheduler ID (\fISchedulerId\fR\&) of the scheduler thread that the calling process is executing on\&. \fISchedulerId\fR\& is a positive integer, where \fI1 <= SchedulerId <= erlang:system_info(schedulers)\fR\&\&. .RS 2 .LP See also \fIerlang:system_info(schedulers)\fR\&\&. .RE .TP 2 .B \fIschedulers\fR\&: Returns the number of scheduler threads used by the emulator\&. Scheduler threads online schedules Erlang processes and Erlang ports, and execute Erlang code and Erlang linked-in driver code\&. .RS 2 .LP The number of scheduler threads is determined at emulator boot time and cannot be changed later\&. However, the number of schedulers online can be changed at any time\&. .RE .RS 2 .LP See also \fIerlang:system_flag(schedulers_online, SchedulersOnline)\fR\&, \fIerlang:system_info(schedulers_online)\fR\&, \fIerlang:system_info(scheduler_id)\fR\&, \fIerlang:system_flag(multi_scheduling, BlockState)\fR\&, \fIerlang:system_info(multi_scheduling)\fR\&, \fIerlang:system_info(normal_multi_scheduling_blockers)\fR\& and \fIerlang:system_info(multi_scheduling_blockers)\fR\&\&. .RE .TP 2 .B \fIschedulers_online\fR\&: Returns the number of schedulers online\&. The scheduler identifiers of schedulers online satisfy the relationship \fI1 <= SchedulerId <= erlang:system_info(schedulers_online)\fR\&\&. .RS 2 .LP For more information, see \fIerlang:system_info(schedulers)\fR\& and \fIerlang:system_flag(schedulers_online, SchedulersOnline)\fR\&\&. .RE .TP 2 .B \fIsmp_support\fR\&: Returns \fItrue\fR\&\&. .TP 2 .B \fIthreads\fR\&: Returns \fItrue\fR\&\&. .TP 2 .B \fIthread_pool_size\fR\&: .RS 2 .LP Returns the number of async threads in the async thread pool used for asynchronous driver calls (\fIerl_driver:driver_async()\fR\&)\&. The value is given as an integer\&. .RE .RE .RE .LP .nf .B erlang:system_info(Item :: async_dist) -> boolean() .br .fi .br .nf .B erlang:system_info(Item :: creation) -> integer() .br .fi .br .nf .B erlang:system_info(Item :: delayed_node_table_gc) -> .B infinity | integer() >= 0 .br .fi .br .nf .B erlang:system_info(Item :: dist) -> binary() .br .fi .br .nf .B erlang:system_info(Item :: dist_buf_busy_limit) -> .B integer() >= 0 .br .fi .br .nf .B erlang:system_info(Item :: dist_ctrl) -> .B [{Node :: node(), .B ControllingEntity :: port() | pid()}] .br .fi .br .RS .LP Returns information about Erlang Distribution in the current system as specified by \fIItem\fR\&: .RS 2 .TP 2 .B \fIasync_dist\fR\&: Since: OTP 25\&.3 .RS 2 .LP Returns the value of the command line argument +pad which the runtime system use\&. This value determines the default \fIasync_dist\fR\& value for newly spawned processes\&. .RE .TP 2 .B \fIcreation\fR\&: Returns the creation of the local node as an integer\&. The creation is changed when a node is restarted\&. The creation of a node is stored in process identifiers, port identifiers, and references\&. This makes it (to some extent) possible to distinguish between identifiers from different incarnations of a node\&. The valid creations are integers in the range 1\&.\&.3, but this will probably change in a future release\&. If the node is not alive, \fI0\fR\& is returned\&. .TP 2 .B \fIdelayed_node_table_gc\fR\&: Returns the amount of time in seconds garbage collection of an entry in a node table is delayed\&. This limit can be set on startup by passing command-line flag \fI+zdntgc\fR\& to \fIerl(1)\fR\&\&. For more information, see the documentation of the command-line flag\&. .TP 2 .B \fIdist\fR\&: Returns a binary containing a string of distribution information formatted as in Erlang crash dumps\&. For more information, see section How to interpret the Erlang crash dumps in the User\&'s Guide\&. .TP 2 .B \fIdist_buf_busy_limit\fR\&: Returns the value of the distribution buffer busy limit in bytes\&. This limit can be set at startup by passing command-line flag \fI+zdbbl\fR\& to \fIerl(1)\fR\&\&. .TP 2 .B \fIdist_ctrl\fR\&: Returns a list of tuples \fI{Node, ControllingEntity}\fR\&, one entry for each connected remote node\&. \fINode\fR\& is the node name and \fIControllingEntity\fR\& is the port or process identifier responsible for the communication to that node\&. More specifically, \fIControllingEntity\fR\& for nodes connected through TCP/IP (the normal case) is the socket used in communication with the specific node\&. .RE .RE .LP .nf .B erlang:system_info(Item :: c_compiler_used) -> {atom(), term()} .br .fi .br .nf .B erlang:system_info(Item :: check_io) -> [term()] .br .fi .br .nf .B erlang:system_info(Item :: compat_rel) -> integer() .br .fi .br .nf .B erlang:system_info(Item :: debug_compiled) -> boolean() .br .fi .br .nf .B erlang:system_info(Item :: driver_version) -> string() .br .fi .br .nf .B erlang:system_info(Item :: dynamic_trace) -> .B none | dtrace | systemtap .br .fi .br .nf .B erlang:system_info(Item :: dynamic_trace_probes) -> boolean() .br .fi .br .nf .B erlang:system_info(Item :: emu_flavor) -> emu | jit .br .fi .br .nf .B erlang:system_info(Item :: emu_type) -> .B opt | debug | gcov | valgrind | gprof | .B lcnt | frmptr .br .fi .br .nf .B erlang:system_info(Item :: info) -> binary() .br .fi .br .nf .B erlang:system_info(Item :: kernel_poll) -> boolean() .br .fi .br .nf .B erlang:system_info(Item :: loaded) -> binary() .br .fi .br .nf .B erlang:system_info(Item :: machine) -> string() .br .fi .br .nf .B erlang:system_info(Item :: modified_timing_level) -> .B integer() | undefined .br .fi .br .nf .B erlang:system_info(Item :: nif_version) -> string() .br .fi .br .nf .B erlang:system_info(Item :: otp_release) -> string() .br .fi .br .nf .B erlang:system_info(Item :: outstanding_system_requests_limit) -> .B 1\&.\&.134217727 .br .fi .br .nf .B erlang:system_info(Item :: port_parallelism) -> boolean() .br .fi .br .nf .B erlang:system_info(Item :: system_architecture) -> string() .br .fi .br .nf .B erlang:system_info(Item :: system_logger) -> .B logger | undefined | pid() .br .fi .br .nf .B erlang:system_info(Item :: system_version) -> string() .br .fi .br .nf .B erlang:system_info(Item :: trace_control_word) -> .B integer() >= 0 .br .fi .br .nf .B erlang:system_info(Item :: version) -> string() .br .fi .br .nf .B erlang:system_info(Item :: .B wordsize | .B {wordsize, internal} | .B {wordsize, external}) -> .B 4 | 8 .br .fi .br .RS .LP Returns various information about the current system (emulator) as specified by \fIItem\fR\&: .RS 2 .TP 2 .B \fIbuild_type\fR\&: Deprecated, use emu_type instead .TP 2 .B \fIc_compiler_used\fR\&: Returns a two-tuple describing the C compiler used when compiling the runtime system\&. The first element is an atom describing the name of the compiler, or \fIundefined\fR\& if unknown\&. The second element is a term describing the version of the compiler, or \fIundefined\fR\& if unknown\&. .TP 2 .B \fIcheck_io\fR\&: Returns a list containing miscellaneous information about the emulators internal I/O checking\&. Notice that the content of the returned list can vary between platforms and over time\&. It is only guaranteed that a list is returned\&. .TP 2 .B \fIcompat_rel\fR\&: Returns the compatibility mode of the local node as an integer\&. The integer returned represents the Erlang/OTP release that the current emulator has been set to be backward compatible with\&. The compatibility mode can be configured at startup by using command-line flag \fI+R\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIdebug_compiled\fR\&: Returns \fItrue\fR\& if the emulator has been debug-compiled, otherwise \fIfalse\fR\&\&. .TP 2 .B \fIdriver_version\fR\&: Returns a string containing the Erlang driver version used by the runtime system\&. It has the form "\&."\&. .TP 2 .B \fIdynamic_trace\fR\&: Returns an atom describing the dynamic trace framework compiled into the virtual machine\&. It can be \fIdtrace\fR\&, \fIsystemtap\fR\&, or \fInone\fR\&\&. For a commercial or standard build, it is always \fInone\fR\&\&. The other return values indicate a custom configuration (for example, \fI\&./configure --with-dynamic-trace=dtrace\fR\&)\&. For more information about dynamic tracing, see \fIdyntrace(3erl)\fR\& manual page and the \fIREADME\&.dtrace\fR\&/\fIREADME\&.systemtap\fR\& files in the Erlang source code top directory\&. .TP 2 .B \fIdynamic_trace_probes\fR\&: Returns a \fIboolean()\fR\& indicating if dynamic trace probes (\fIdtrace\fR\& or \fIsystemtap\fR\&) are built into the emulator\&. This can only be \fItrue\fR\& if the virtual machine was built for dynamic tracing (that is, \fIsystem_info(dynamic_trace)\fR\& returns \fIdtrace\fR\& or \fIsystemtap\fR\&)\&. .TP 2 .B \fIemu_flavor\fR\&: Returns an atom describing the flavor of the runtime system\&. This will be either \fIemu\fR\& or \fIjit\fR\&\&. Possible return values can be added or removed at any time without prior notice\&. .TP 2 .B \fIemu_type\fR\&: Returns an atom describing the build type of the runtime system\&. This is normally the atom \fIopt\fR\& for optimized\&. Other possible return values are \fIdebug\fR\&, \fIgcov\fR\&, \fIvalgrind\fR\&, \fIgprof\fR\&, and \fIlcnt\fR\&\&. Possible return values can be added or removed at any time without prior notice\&. .TP 2 .B \fIinfo\fR\&: Returns a binary containing a string of miscellaneous system information formatted as in Erlang crash dumps\&. For more information, see section How to interpret the Erlang crash dumps in the User\&'s Guide\&. .TP 2 .B \fIkernel_poll\fR\&: Returns \fItrue\fR\& if the emulator uses some kind of kernel-poll implementation, otherwise \fIfalse\fR\&\&. .TP 2 .B \fIloaded\fR\&: Returns a binary containing a string of loaded module information formatted as in Erlang crash dumps\&. For more information, see section How to interpret the Erlang crash dumps in the User\&'s Guide\&. .TP 2 .B \fImachine\fR\&: Returns a string containing the Erlang machine name\&. .TP 2 .B \fImodified_timing_level\fR\&: Returns the modified timing-level (an integer) if modified timing is enabled, otherwise \fIundefined\fR\&\&. For more information about modified timing, see command-line flag \fI+T\fR\& in \fIerl(1)\fR\& .TP 2 .B \fInif_version\fR\&: Returns a string containing the version of the Erlang NIF interface used by the runtime system\&. It is on the form "\&."\&. .TP 2 .B \fIotp_release\fR\&: .RS 2 .LP Returns a string containing the OTP release number of the OTP release that the currently executing ERTS application is part of\&. .RE .RS 2 .LP As from Erlang/OTP 17, the OTP release number corresponds to the major OTP version number\&. No \fIerlang:system_info()\fR\& argument gives the exact OTP version\&. This is because the exact OTP version in the general case is difficult to determine\&. For more information, see the description of versions in System principles in System Documentation\&. .RE .TP 2 .B \fIoutstanding_system_requests_limit\fR\&: Returns the limit on the amount of outstanding requests made by a system process orchestrating system wide changes\&. See \fIerlang:system_flag(outstanding_system_requests_limit, Limit)\fR\& for more information\&. .TP 2 .B \fIport_parallelism\fR\&: Returns the default port parallelism scheduling hint used\&. For more information, see command-line argument \fI+spp\fR\& in \fIerl(1)\fR\&\&. .TP 2 .B \fIsystem_architecture\fR\&: Returns a string containing the processor and OS architecture the emulator is built for\&. .TP 2 .B \fIsystem_logger\fR\&: Returns the current \fIsystem_logger\fR\& as set by \fIerlang:system_flag(system_logger, _)\fR\&\&. .TP 2 .B \fIsystem_version\fR\&: Returns a string containing version number and some important properties, such as the number of schedulers\&. .TP 2 .B \fItrace_control_word\fR\&: Returns the value of the node trace control word\&. For more information, see function \fIget_tcw\fR\& in section Match Specifications in Erlang in the User\&'s Guide\&. .TP 2 .B \fIversion\fR\&: Returns a string containing the version number of the emulator\&. .TP 2 .B \fIwordsize\fR\&: Same as \fI{wordsize, internal}\fR\&\&. .TP 2 .B \fI{wordsize, internal}\fR\&: Returns the size of Erlang term words in bytes as an integer, that is, 4 is returned on a 32-bit architecture, and 8 is returned on a 64-bit architecture\&. .TP 2 .B \fI{wordsize, external}\fR\&: Returns the true word size of the emulator, that is, the size of a pointer\&. The value is given in bytes as an integer\&. On a pure 32-bit architecture, 4 is returned\&. On a 64-bit architecture, 8 is returned\&. .RE .RE .LP .nf .B erlang:system_monitor() -> MonSettings .br .fi .br .RS .LP Types: .RS 3 MonSettings = undefined | {MonitorPid, Options} .br MonitorPid = pid() .br Options = [system_monitor_option()] .br .nf \fBsystem_monitor_option()\fR\& = .br busy_port | busy_dist_port | .br {long_gc, integer() >= 0} | .br {long_schedule, integer() >= 0} | .br {large_heap, integer() >= 0} .fi .br .RE .RE .RS .LP Returns the current system monitoring settings set by \fIerlang:system_monitor/2\fR\& as \fI{MonitorPid, Options}\fR\&, or \fIundefined\fR\& if no settings exist\&. The order of the options can be different from the one that was set\&. .RE .LP .nf .B erlang:system_monitor(Arg) -> MonSettings .br .fi .br .RS .LP Types: .RS 3 Arg = MonSettings = undefined | {MonitorPid, Options} .br MonitorPid = pid() .br Options = [system_monitor_option()] .br .nf \fBsystem_monitor_option()\fR\& = .br busy_port | busy_dist_port | .br {long_gc, integer() >= 0} | .br {long_schedule, integer() >= 0} | .br {large_heap, integer() >= 0} .fi .br .RE .RE .RS .LP When called with argument \fIundefined\fR\&, all system performance monitoring settings are cleared\&. .LP Calling the function with \fI{MonitorPid, Options}\fR\& as argument is the same as calling \fIerlang:system_monitor(MonitorPid, Options)\fR\&\&. .LP Returns the previous system monitor settings just like \fIerlang:system_monitor/0\fR\&\&. .RE .LP .nf .B erlang:system_monitor(MonitorPid, Options) -> MonSettings .br .fi .br .RS .LP Types: .RS 3 MonitorPid = pid() .br Options = [system_monitor_option()] .br MonSettings = undefined | {OldMonitorPid, OldOptions} .br OldMonitorPid = pid() .br OldOptions = [system_monitor_option()] .br .nf \fBsystem_monitor_option()\fR\& = .br busy_port | busy_dist_port | .br {long_gc, integer() >= 0} | .br {long_schedule, integer() >= 0} | .br {large_heap, integer() >= 0} .fi .br .RE .RE .RS .LP Sets the system performance monitoring options\&. \fIMonitorPid\fR\& is a local process identifier (pid) receiving system monitor messages\&. The second argument is a list of monitoring options: .RS 2 .TP 2 .B \fI{long_gc, Time}\fR\&: If a garbage collection in the system takes at least \fITime\fR\& wall clock milliseconds, a message \fI{monitor, GcPid, long_gc, Info}\fR\& is sent to \fIMonitorPid\fR\&\&. \fIGcPid\fR\& is the pid that was garbage collected\&. \fIInfo\fR\& is a list of two-element tuples describing the result of the garbage collection\&. .RS 2 .LP One of the tuples is \fI{timeout, GcTime}\fR\&, where \fIGcTime\fR\& is the time for the garbage collection in milliseconds\&. The other tuples are tagged with \fIheap_size\fR\&, \fIheap_block_size\fR\&, \fIstack_size\fR\&, \fImbuf_size\fR\&, \fIold_heap_size\fR\&, and \fIold_heap_block_size\fR\&\&. These tuples are explained in the description of trace message \fIgc_minor_start\fR\& (see \fIerlang:trace/3\fR\&)\&. New tuples can be added, and the order of the tuples in the \fIInfo\fR\& list can be changed at any time without prior notice\&. .RE .TP 2 .B \fI{long_schedule, Time}\fR\&: If a process or port in the system runs uninterrupted for at least \fITime\fR\& wall clock milliseconds, a message \fI{monitor, PidOrPort, long_schedule, Info}\fR\& is sent to \fIMonitorPid\fR\&\&. \fIPidOrPort\fR\& is the process or port that was running\&. \fIInfo\fR\& is a list of two-element tuples describing the event\&. .RS 2 .LP If a \fIpid()\fR\&, the tuples \fI{timeout, Millis}\fR\&, \fI{in, Location}\fR\&, and \fI{out, Location}\fR\& are present, where \fILocation\fR\& is either an MFA (\fI{Module, Function, Arity}\fR\&) describing the function where the process was scheduled in/out, or the atom \fIundefined\fR\&\&. .RE .RS 2 .LP If a \fIport()\fR\&, the tuples \fI{timeout, Millis}\fR\& and \fI{port_op,Op}\fR\& are present\&. \fIOp\fR\& is one of \fIproc_sig\fR\&, \fItimeout\fR\&, \fIinput\fR\&, \fIoutput\fR\&, \fIevent\fR\&, or \fIdist_cmd\fR\&, depending on which driver callback was executing\&. .RE .RS 2 .LP \fIproc_sig\fR\& is an internal operation and is never to appear, while the others represent the corresponding driver callbacks \fItimeout\fR\&, \fIready_input\fR\&, \fIready_output\fR\&, \fIevent\fR\&, and \fIoutputv\fR\& (when the port is used by distribution)\&. Value \fIMillis\fR\& in tuple \fItimeout\fR\& informs about the uninterrupted execution time of the process or port, which always is equal to or higher than the \fITime\fR\& value supplied when starting the trace\&. New tuples can be added to the \fIInfo\fR\& list in a future release\&. The order of the tuples in the list can be changed at any time without prior notice\&. .RE .RS 2 .LP This can be used to detect problems with NIFs or drivers that take too long to execute\&. 1 ms is considered a good maximum time for a driver callback or a NIF\&. However, a time-sharing system is usually to consider everything < 100 ms as "possible" and fairly "normal"\&. However, longer schedule times can indicate swapping or a misbehaving NIF/driver\&. Misbehaving NIFs and drivers can cause bad resource utilization and bad overall system performance\&. .RE .TP 2 .B \fI{large_heap, Size}\fR\&: If a garbage collection in the system results in the allocated size of a heap being at least \fISize\fR\& words, a message \fI{monitor, GcPid, large_heap, Info}\fR\& is sent to \fIMonitorPid\fR\&\&. \fIGcPid\fR\& and \fIInfo\fR\& are the same as for \fIlong_gc\fR\& earlier, except that the tuple tagged with \fItimeout\fR\& is not present\&. .RS 2 .LP The monitor message is sent if the sum of the sizes of all memory blocks allocated for all heap generations after a garbage collection is equal to or higher than \fISize\fR\&\&. .RE .RS 2 .LP When a process is killed by \fImax_heap_size\fR\&, it is killed before the garbage collection is complete and thus no large heap message is sent\&. .RE .TP 2 .B \fIbusy_port\fR\&: If a process in the system gets suspended because it sends to a busy port, a message \fI{monitor, SusPid, busy_port, Port}\fR\& is sent to \fIMonitorPid\fR\&\&. \fISusPid\fR\& is the pid that got suspended when sending to \fIPort\fR\&\&. .TP 2 .B \fIbusy_dist_port\fR\&: If a process in the system gets suspended because it sends to a process on a remote node whose inter-node communication was handled by a busy port, a message \fI{monitor, SusPid, busy_dist_port, Port}\fR\& is sent to \fIMonitorPid\fR\&\&. \fISusPid\fR\& is the pid that got suspended when sending through the inter-node communication port \fIPort\fR\&\&. .RE .LP Returns the previous system monitor settings just like \fIerlang:system_monitor/0\fR\&\&. .LP The arguments to \fIsystem_monitor/2\fR\& specifies how all system monitoring on the node should be done, not how it should be changed\&. This means only one process at a time (\fIMonitorPid\fR\&) can be the receiver of system monitor messages\&. Also, the way to clear a specific monitor option is to not include it in the list \fIOptions\fR\&\&. All system monitoring will, however, be cleared if the process identified by \fIMonitorPid\fR\& terminates\&. .LP There are no special option values (like zero) to clear an option\&. Some of the options have a unspecified minimum value\&. Lower values will be adjusted to the minimum value\&. For example, it is currently not possible to monitor all garbage collections with \fI{long_gc, 0}\fR\&\&. .LP .RS -4 .B Note: .RE If a monitoring process gets so large that it itself starts to cause system monitor messages when garbage collecting, the messages enlarge the process message queue and probably make the problem worse\&. .LP Keep the monitoring process neat and do not set the system monitor limits too tight\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: If \fIMonitorPid\fR\& does not exist\&. .TP 2 .B \fIbadarg\fR\&: If \fIMonitorPid\fR\& is not a local process\&. .RE .RE .LP .nf .B erlang:system_profile() -> ProfilerSettings .br .fi .br .RS .LP Types: .RS 3 ProfilerSettings = undefined | {ProfilerPid, Options} .br ProfilerPid = pid() | port() .br Options = [system_profile_option()] .br .nf \fBsystem_profile_option()\fR\& = .br exclusive | runnable_ports | runnable_procs | scheduler | .br timestamp | monotonic_timestamp | strict_monotonic_timestamp .fi .br .RE .RE .RS .LP Returns the current system profiling settings set by \fIerlang:system_profile/2\fR\& as \fI{ProfilerPid, Options}\fR\&, or \fIundefined\fR\& if there are no settings\&. The order of the options can be different from the one that was set\&. .RE .LP .nf .B erlang:system_profile(ProfilerPid, Options) -> ProfilerSettings .br .fi .br .RS .LP Types: .RS 3 ProfilerPid = pid() | port() | undefined .br Options = [system_profile_option()] .br ProfilerSettings = .br undefined | {pid() | port(), [system_profile_option()]} .br .nf \fBsystem_profile_option()\fR\& = .br exclusive | runnable_ports | runnable_procs | scheduler | .br timestamp | monotonic_timestamp | strict_monotonic_timestamp .fi .br .RE .RE .RS .LP Sets system profiler options\&. \fIProfilerPid\fR\& is a local process identifier (pid) or port receiving profiling messages\&. The receiver is excluded from all profiling\&. The second argument is a list of profiling options: .RS 2 .TP 2 .B \fIexclusive\fR\&: If a synchronous call to a port from a process is done, the calling process is considered not runnable during the call runtime to the port\&. The calling process is notified as \fIinactive\fR\&, and later \fIactive\fR\& when the port callback returns\&. .TP 2 .B \fImonotonic_timestamp\fR\&: Time stamps in profile messages use Erlang monotonic time\&. The time stamp (Ts) has the same format and value as produced by \fIerlang:monotonic_time(nanosecond)\fR\&\&. .TP 2 .B \fIrunnable_procs\fR\&: If a process is put into or removed from the run queue, a message, \fI{profile, Pid, State, Mfa, Ts}\fR\&, is sent to \fIProfilerPid\fR\&\&. Running processes that are reinserted into the run queue after having been pre-empted do not trigger this message\&. .TP 2 .B \fIrunnable_ports\fR\&: If a port is put into or removed from the run queue, a message, \fI{profile, Port, State, 0, Ts}\fR\&, is sent to \fIProfilerPid\fR\&\&. .TP 2 .B \fIscheduler\fR\&: If a scheduler is put to sleep or awoken, a message, \fI{profile, scheduler, Id, State, NoScheds, Ts}\fR\&, is sent to \fIProfilerPid\fR\&\&. .TP 2 .B \fIstrict_monotonic_timestamp\fR\&: Time stamps in profile messages consist of Erlang monotonic time and a monotonically increasing integer\&. The time stamp (Ts) has the same format and value as produced by \fI{erlang:monotonic_time(nanosecond), erlang:unique_integer([monotonic])}\fR\&\&. .TP 2 .B \fItimestamp\fR\&: Time stamps in profile messages include a time stamp (Ts) that has the same form as returned by \fIerlang:now()\fR\&\&. This is also the default if no time stamp flag is specified\&. If \fIcpu_timestamp\fR\& has been enabled through \fIerlang:trace/3\fR\&, this also effects the time stamp produced in profiling messages when flag \fItimestamp\fR\& is enabled\&. .RE .LP .RS -4 .B Note: .RE \fIerlang:system_profile\fR\& behavior can change in a future release\&. .RE .LP .nf .B erlang:system_time() -> integer() .br .fi .br .RS .LP Returns current Erlang system time in \fInative\fR\& time unit\&. .LP Calling \fIerlang:system_time()\fR\& is equivalent to \fIerlang:monotonic_time()\fR\&\fI + \fR\&\fIerlang:time_offset()\fR\&\&. .LP .RS -4 .B Note: .RE This time is \fInot\fR\& a monotonically increasing time in the general case\&. For more information, see the documentation of time warp modes in the User\&'s Guide\&. .RE .LP .nf .B erlang:system_time(Unit) -> integer() .br .fi .br .RS .LP Types: .RS 3 Unit = time_unit() .br .RE .RE .RS .LP Returns current Erlang system time converted into the \fIUnit\fR\& passed as argument\&. .LP Calling \fIerlang:system_time(Unit)\fR\& is equivalent to \fIerlang:convert_time_unit\fR\&\fI(\fR\&\fIerlang:system_time()\fR\&\fI, native, Unit)\fR\&\&. .LP .RS -4 .B Note: .RE This time is \fInot\fR\& a monotonically increasing time in the general case\&. For more information, see the documentation of time warp modes in the User\&'s Guide\&. .RE .LP .nf .B term_to_binary(Term) -> ext_binary() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns a binary data object that is the result of encoding \fITerm\fR\& according to the Erlang external term format\&. .LP This can be used for various purposes, for example, writing a term to a file in an efficient way, or sending an Erlang term to some type of communications channel not supported by distributed Erlang\&. .LP .nf > Bin = term_to_binary(hello)\&. <<131,100,0,5,104,101,108,108,111>> > hello = binary_to_term(Bin)\&. hello .fi .LP See also \fIbinary_to_term/1\fR\&\&. .LP .RS -4 .B Note: .RE There is no guarantee that this function will return the same encoded representation for the same term\&. .RE .LP .nf .B term_to_binary(Term, Options) -> ext_binary() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br Options = .br [compressed | .br {compressed, Level :: 0\&.\&.9} | .br deterministic | .br {minor_version, Version :: 0\&.\&.2}] .br .RE .RE .RS .LP Returns a binary data object that is the result of encoding \fITerm\fR\& according to the Erlang external term format\&. .LP If option \fIcompressed\fR\& is provided, the external term format is compressed\&. The compressed format is automatically recognized by \fIbinary_to_term/1\fR\& as from Erlang/OTP R7B\&. .LP A compression level can be specified by giving option \fI{compressed, Level}\fR\&\&. \fILevel\fR\& is an integer with range 0\&.\&.9, where: .RS 2 .TP 2 * \fI0\fR\& - No compression is done (it is the same as giving no \fIcompressed\fR\& option)\&. .LP .TP 2 * \fI1\fR\& - Takes least time but may not compress as well as the higher levels\&. .LP .TP 2 * \fI6\fR\& - Default level when option \fIcompressed\fR\& is provided\&. .LP .TP 2 * \fI9\fR\& - Takes most time and tries to produce a smaller result\&. Notice "tries" in the preceding sentence; depending on the input term, level 9 compression either does or does not produce a smaller result than level 1 compression\&. .LP .RE .LP Option \fI{minor_version, Version}\fR\& can be used to control some encoding details\&. This option was introduced in Erlang/OTP R11B-4\&. The valid values for \fIVersion\fR\& are: .RS 2 .TP 2 .B \fI0\fR\&: Floats are encoded using a textual representation\&. This option is useful to ensure that releases before Erlang/OTP R11B-4 can decode resulting binary\&. .RS 2 .LP This version encode atoms that can be represented by a latin1 string using latin1 encoding while only atoms that cannot be represented by latin1 are encoded using utf8\&. .RE .TP 2 .B \fI1\fR\&: This is as of Erlang/OTP 17\&.0 the \fIdefault\fR\&\&. It forces any floats in the term to be encoded in a more space-efficient and exact way (namely in the 64-bit IEEE format, rather than converted to a textual representation)\&. As from Erlang/OTP R11B-4, \fIbinary_to_term/1\fR\& can decode this representation\&. .RS 2 .LP This version encode atoms that can be represented by a latin1 string using latin1 encoding while only atoms that cannot be represented by latin1 are encoded using utf8\&. .RE .TP 2 .B \fI2\fR\&: Drops usage of the latin1 atom encoding and unconditionally use utf8 encoding for all atoms\&. Erlang/OTP systems as of R16B can decode this representation\&. .LP .RS -4 .B Note: .RE In Erlang/OTP 26, the default \fIminor_version\fR\& is planned to change from 1 to 2\&. See Upcoming Potential Incompatibilities \&. .RE .LP Option \fIdeterministic\fR\& (introduced in OTP 24\&.1) can be used to ensure that within the same major release of Erlang/OTP, the same encoded representation is returned for the same term\&. There is still no guarantee that the encoded representation remains the same between major releases of Erlang/OTP\&. .LP See also \fIbinary_to_term/1\fR\&\&. .RE .LP .nf .B term_to_iovec(Term) -> ext_iovec() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br .RE .RE .RS .LP Returns the encoding of \fITerm\fR\& according to the Erlang external term format as \fIext_iovec()\fR\&\&. .LP This function produce the same encoding as \fIterm_to_binary/1\fR\&, but with another return type\&. The call \fIiolist_to_binary(term_to_iovec(Term))\fR\& will produce exactly the same result as the call \fIterm_to_binary(Term)\fR\&\&. .LP \fIterm_to_iovec()\fR\& is a pure optimization of the functionality \fIterm_to_binary()\fR\& provide\&. \fIterm_to_iovec()\fR\& can for example refer directly to off heap binaries instead of copying the binary data into the result\&. .LP See also \fIterm_to_binary/1\fR\&\&. .RE .LP .nf .B term_to_iovec(Term, Options) -> ext_iovec() .br .fi .br .RS .LP Types: .RS 3 Term = term() .br Options = .br [compressed | .br {compressed, Level :: 0\&.\&.9} | .br deterministic | .br {minor_version, Version :: 0\&.\&.2}] .br .RE .RE .RS .LP Returns the encoding of \fITerm\fR\& according to the Erlang external term format as \fIext_iovec()\fR\&\&. .LP This function produce the same encoding as \fIterm_to_binary/2\fR\&, but with another return type\&. The call \fIiolist_to_binary(term_to_iovec(Term, Opts))\fR\& will produce exactly the same result as \fIterm_to_binary(Term, Opts)\fR\&\&. .LP Currently recognised options are all options recognised by \fIterm_to_binary/2\fR\&\&. .LP \fIterm_to_iovec()\fR\& is a pure optimization of the functionality \fIterm_to_binary()\fR\& provide\&. \fIterm_to_iovec()\fR\& can for example refer directly to off heap binaries instead of copying the binary data into the result\&. .LP See also \fIterm_to_binary/2\fR\&\&. .RE .LP .nf .B throw(Any) -> no_return() .br .fi .br .RS .LP Types: .RS 3 Any = term() .br .RE .RE .RS .LP Raises an exception of class \fIthrow\fR\&\&. Intended to be used to do non-local returns from functions\&. .LP If evaluated within a catch expression, the catch expression returns value \fIAny\fR\&\&. Example: .LP .nf > catch throw({hello, there})\&. {hello,there} .fi .LP If evaluated within a \fItry\fR\&-block of a try expression, the value \fIAny\fR\& can be caught within the catch block\&. Example: .LP .nf try throw({my_exception, "Something happened"}) catch throw:{my_exception, Desc} -> io:format(standard_error, "Error: ~s~n", [Desc]) end .fi .LP Failure: \fInocatch\fR\& if not caught by an exception handler\&. .LP See the guide about errors and error handling for additional information\&. .RE .LP .nf .B time() -> Time .br .fi .br .RS .LP Types: .RS 3 Time = calendar:time() .br .RE .RE .RS .LP Returns the current time as \fI{Hour, Minute, Second}\fR\&\&. .LP The time zone and Daylight Saving Time correction depend on the underlying OS\&. The return value is based on the OS System Time\&. Example: .LP .nf > time()\&. {9,42,44} .fi .RE .LP .nf .B erlang:time_offset() -> integer() .br .fi .br .RS .LP Returns the current time offset between Erlang monotonic time and Erlang system time in \fInative\fR\& time unit\&. Current time offset added to an Erlang monotonic time gives corresponding Erlang system time\&. .LP The time offset may or may not change during operation depending on the time warp mode used\&. .LP .RS -4 .B Note: .RE A change in time offset can be observed at slightly different points in time by different processes\&. .LP If the runtime system is in multi-time warp mode, the time offset is changed when the runtime system detects that the OS system time has changed\&. The runtime system will, however, not detect this immediately when it occurs\&. A task checking the time offset is scheduled to execute at least once a minute; so, under normal operation this is to be detected within a minute, but during heavy load it can take longer time\&. .RE .LP .nf .B erlang:time_offset(Unit) -> integer() .br .fi .br .RS .LP Types: .RS 3 Unit = time_unit() .br .RE .RE .RS .LP Returns the current time offset between Erlang monotonic time and Erlang system time converted into the \fIUnit\fR\& passed as argument\&. .LP Same as calling \fIerlang:convert_time_unit\fR\&\fI(\fR\&\fIerlang:time_offset()\fR\&\fI, native, Unit)\fR\& however optimized for commonly used \fIUnit\fR\&s\&. .RE .LP .nf .B erlang:timestamp() -> Timestamp .br .fi .br .RS .LP Types: .RS 3 Timestamp = timestamp() .br .nf \fBtimestamp()\fR\& = .br {MegaSecs :: integer() >= 0, .br Secs :: integer() >= 0, .br MicroSecs :: integer() >= 0} .fi .br .RE .RE .RS .LP Returns current Erlang system time on the format \fI{MegaSecs, Secs, MicroSecs}\fR\&\&. This format is the same as \fIos:timestamp/0\fR\& and the deprecated \fIerlang:now/0\fR\& use\&. The reason for the existence of \fIerlang:timestamp()\fR\& is purely to simplify use for existing code that assumes this time stamp format\&. Current Erlang system time can more efficiently be retrieved in the time unit of your choice using \fIerlang:system_time/1\fR\&\&. .LP The \fIerlang:timestamp()\fR\& BIF is equivalent to: .LP .nf timestamp() -> ErlangSystemTime = erlang:system_time(microsecond), MegaSecs = ErlangSystemTime div 1000_000_000_000, Secs = ErlangSystemTime div 1000_000 - MegaSecs*1000_000, MicroSecs = ErlangSystemTime rem 1000_000, {MegaSecs, Secs, MicroSecs}. .fi .LP It, however, uses a native implementation that does not build garbage on the heap and with slightly better performance\&. .LP .RS -4 .B Note: .RE This time is \fInot\fR\& a monotonically increasing time in the general case\&. For more information, see the documentation of time warp modes in the User\&'s Guide\&. .RE .LP .nf .B tl(List) -> term() .br .fi .br .RS .LP Types: .RS 3 List = nonempty_maybe_improper_list() .br .RE .RE .RS .LP Returns the tail of \fIList\fR\&, that is, the list minus the first element, for example: .LP .nf > tl([geesties, guilies, beasties])\&. [guilies, beasties] .fi .LP .nf > tl([geesties])\&. [] .fi .LP .nf > tl([geesties, guilies, beasties | improper_end])\&. [guilies, beasties | improper_end] .fi .LP .nf > tl([geesties | improper_end])\&. improper_end .fi .LP Allowed in guard tests\&. .LP Failure: \fIbadarg\fR\& if \fIList\fR\& is the empty list \fI[]\fR\&\&. .RE .LP .nf .B erlang:trace(PidPortSpec, How, FlagList) -> integer() .br .fi .br .RS .LP Types: .RS 3 PidPortSpec = .br pid() | .br port() | .br all | processes | ports | existing | existing_processes | .br existing_ports | new | new_processes | new_ports .br How = boolean() .br FlagList = [trace_flag()] .br .nf \fBtrace_flag()\fR\& = .br all | send | \&'receive\&' | procs | ports | call | arity | .br return_to | silent | running | exiting | running_procs | .br running_ports | garbage_collection | timestamp | .br cpu_timestamp | monotonic_timestamp | .br strict_monotonic_timestamp | set_on_spawn | .br set_on_first_spawn | set_on_link | set_on_first_link | .br {tracer, pid() | port()} | .br {tracer, module(), term()} .fi .br .RE .RE .RS .LP Turns on (if \fIHow == true\fR\&) or off (if \fIHow == false\fR\&) the trace flags in \fIFlagList\fR\& for the process or processes represented by \fIPidPortSpec\fR\&\&. .LP \fIPidPortSpec\fR\& is either a process identifier (pid) for a local process, a port identifier, or one of the following atoms: .RS 2 .TP 2 .B \fIall\fR\&: All currently existing processes and ports and all that will be created in the future\&. .TP 2 .B \fIprocesses\fR\&: All currently existing processes and all that will be created in the future\&. .TP 2 .B \fIports\fR\&: All currently existing ports and all that will be created in the future\&. .TP 2 .B \fIexisting\fR\&: All currently existing processes and ports\&. .TP 2 .B \fIexisting_processes\fR\&: All currently existing processes\&. .TP 2 .B \fIexisting_ports\fR\&: All currently existing ports\&. .TP 2 .B \fInew\fR\&: All processes and ports that will be created in the future\&. .TP 2 .B \fInew_processes\fR\&: All processes that will be created in the future\&. .TP 2 .B \fInew_ports\fR\&: All ports that will be created in the future\&. .RE .LP \fIFlagList\fR\& can contain any number of the following flags (the "message tags" refers to the list of \fItrace messages\fR\&): .RS 2 .TP 2 .B \fIall\fR\&: Sets all trace flags except \fItracer\fR\& and \fIcpu_timestamp\fR\&, which are in their nature different than the others\&. .TP 2 .B \fIsend\fR\&: Traces sending of messages\&. .RS 2 .LP Message tags: \fIsend\fR\& and \fIsend_to_non_existing_process\fR\&\&. .RE .TP 2 .B \fI\&'receive\&'\fR\&: Traces receiving of messages\&. .RS 2 .LP Message tags: \fI\&'receive\&'\fR\&\&. .RE .TP 2 .B \fIcall\fR\&: Traces certain function calls\&. Specify which function calls to trace by calling \fIerlang:trace_pattern/3\fR\&\&. .RS 2 .LP Message tags: \fIcall\fR\& and \fIreturn_from\fR\&\&. .RE .TP 2 .B \fIsilent\fR\&: Used with the \fIcall\fR\& trace flag\&. The \fIcall\fR\&, \fIreturn_from\fR\&, and \fIreturn_to\fR\& trace messages are inhibited if this flag is set, but they are executed as normal if there are match specifications\&. .RS 2 .LP Silent mode is inhibited by executing \fIerlang:trace(_, false, [silent|_])\fR\&, or by a match specification executing the function \fI{silent, false}\fR\&\&. .RE .RS 2 .LP The \fIsilent\fR\& trace flag facilitates setting up a trace on many or even all processes in the system\&. The trace can then be activated and deactivated using the match specification function \fI{silent,Bool}\fR\&, giving a high degree of control of which functions with which arguments that trigger the trace\&. .RE .RS 2 .LP Message tags: \fIcall\fR\&, \fIreturn_from\fR\&, and \fIreturn_to\fR\&\&. Or rather, the absence of\&. .RE .TP 2 .B \fIreturn_to\fR\&: Used with the \fIcall\fR\& trace flag\&. Traces the return from a traced function back to its caller\&. Only works for functions traced with option \fIlocal\fR\& to \fIerlang:trace_pattern/3\fR\&\&. .RS 2 .LP The semantics is that a trace message is sent when a call traced function returns, that is, when a chain of tail recursive calls ends\&. Only one trace message is sent per chain of tail recursive calls, so the properties of tail recursiveness for function calls are kept while tracing with this flag\&. Using \fIcall\fR\& and \fIreturn_to\fR\& trace together makes it possible to know exactly in which function a process executes at any time\&. .RE .RS 2 .LP To get trace messages containing return values from functions, use the \fI{return_trace}\fR\& match specification action instead\&. .RE .RS 2 .LP Message tags: \fIreturn_to\fR\&\&. .RE .TP 2 .B \fIprocs\fR\&: Traces process-related events\&. .RS 2 .LP Message tags: \fIspawn\fR\&, \fIspawned\fR\&, \fIexit\fR\&, \fIregister\fR\&, \fIunregister\fR\&, \fIlink\fR\&, \fIunlink\fR\&, \fIgetting_linked\fR\&, and \fIgetting_unlinked\fR\&\&. .RE .TP 2 .B \fIports\fR\&: Traces port-related events\&. .RS 2 .LP Message tags: \fIopen\fR\&, \fIclosed\fR\&, \fIregister\fR\&, \fIunregister\fR\&, \fIgetting_linked\fR\&, and \fIgetting_unlinked\fR\&\&. .RE .TP 2 .B \fIrunning\fR\&: Traces scheduling of processes\&. .RS 2 .LP Message tags: \fIin\fR\& and \fIout\fR\&\&. .RE .TP 2 .B \fIexiting\fR\&: Traces scheduling of exiting processes\&. .RS 2 .LP Message tags: \fIin_exiting\fR\&, \fIout_exiting\fR\&, and \fIout_exited\fR\&\&. .RE .TP 2 .B \fIrunning_procs\fR\&: Traces scheduling of processes just like \fIrunning\fR\&\&. However, this option also includes schedule events when the process executes within the context of a port without being scheduled out itself\&. .RS 2 .LP Message tags: \fIin\fR\& and \fIout\fR\&\&. .RE .TP 2 .B \fIrunning_ports\fR\&: Traces scheduling of ports\&. .RS 2 .LP Message tags: \fIin\fR\& and \fIout\fR\&\&. .RE .TP 2 .B \fIgarbage_collection\fR\&: Traces garbage collections of processes\&. .RS 2 .LP Message tags: \fIgc_minor_start\fR\&, \fIgc_max_heap_size\fR\&, and \fIgc_minor_end\fR\&\&. .RE .TP 2 .B \fItimestamp\fR\&: Includes a time stamp in all trace messages\&. The time stamp (Ts) has the same form as returned by \fIerlang:now()\fR\&\&. .TP 2 .B \fIcpu_timestamp\fR\&: A global trace flag for the Erlang node that makes all trace time stamps using flag \fItimestamp\fR\& to be in CPU time, not wall clock time\&. That is, \fIcpu_timestamp\fR\& is not be used if \fImonotonic_timestamp\fR\& or \fIstrict_monotonic_timestamp\fR\& is enabled\&. Only allowed with \fIPidPortSpec==all\fR\&\&. If the host machine OS does not support high-resolution CPU time measurements, \fItrace/3\fR\& exits with \fIbadarg\fR\&\&. Notice that most OS do not synchronize this value across cores, so be prepared that time can seem to go backwards when using this option\&. .TP 2 .B \fImonotonic_timestamp\fR\&: Includes an Erlang monotonic time time stamp in all trace messages\&. The time stamp (Ts) has the same format and value as produced by \fIerlang:monotonic_time(nanosecond)\fR\&\&. This flag overrides flag \fIcpu_timestamp\fR\&\&. .TP 2 .B \fIstrict_monotonic_timestamp\fR\&: Includes an time stamp consisting of Erlang monotonic time and a monotonically increasing integer in all trace messages\&. The time stamp (Ts) has the same format and value as produced by \fI{\fR\& \fIerlang:monotonic_time(nanosecond)\fR\&\fI,\fR\& \fIerlang:unique_integer([monotonic])\fR\&\fI}\fR\&\&. This flag overrides flag \fIcpu_timestamp\fR\&\&. .TP 2 .B \fIarity\fR\&: Used with the \fIcall\fR\& trace flag\&. \fI{M, F, Arity}\fR\& is specified instead of \fI{M, F, Args}\fR\& in call trace messages\&. .TP 2 .B \fIset_on_spawn\fR\&: Makes any process created by a traced process inherit its trace flags, including flag \fIset_on_spawn\fR\&\&. .TP 2 .B \fIset_on_first_spawn\fR\&: Makes the first process created by a traced process inherit its trace flags, excluding flag \fIset_on_first_spawn\fR\&\&. .TP 2 .B \fIset_on_link\fR\&: Makes any process linked by a traced process inherit its trace flags, including flag \fIset_on_link\fR\&\&. .TP 2 .B \fIset_on_first_link\fR\&: Makes the first process linked to by a traced process inherit its trace flags, excluding flag \fIset_on_first_link\fR\&\&. .TP 2 .B \fI{tracer, Tracer}\fR\&: Specifies where to send the trace messages\&. \fITracer\fR\& must be the process identifier of a local process or the port identifier of a local port\&. .TP 2 .B \fI{tracer, TracerModule, TracerState}\fR\&: Specifies that a tracer module is to be called instead of sending a trace message\&. The tracer module can then ignore or change the trace message\&. For more details on how to write a tracer module, see \fIerl_tracer(3erl)\fR\&\&. .RE .LP If no \fItracer\fR\& is specified, the calling process receives all the trace messages\&. .LP The effect of combining \fIset_on_first_link\fR\& with \fIset_on_link\fR\& is the same as \fIset_on_first_link\fR\& alone\&. Likewise for \fIset_on_spawn\fR\& and \fIset_on_first_spawn\fR\&\&. .LP The tracing process receives the \fItrace messages\fR\& described in the following list\&. \fIPid\fR\& is the process identifier of the traced process in which the traced event has occurred\&. The third tuple element is the message tag\&. .LP If flag \fItimestamp\fR\&, \fIstrict_monotonic_timestamp\fR\&, or \fImonotonic_timestamp\fR\& is specified, the first tuple element is \fItrace_ts\fR\& instead, and the time stamp is added as an extra element last in the message tuple\&. If multiple time stamp flags are passed, \fItimestamp\fR\& has precedence over \fIstrict_monotonic_timestamp\fR\&, which in turn has precedence over \fImonotonic_timestamp\fR\&\&. All time stamp flags are remembered, so if two are passed and the one with highest precedence later is disabled, the other one becomes active\&. .LP If a match specification (applicable only for \fIcall\fR\&, \fIsend\fR\& and \fI\&'receive\&'\fR\& tracing) contains a \fI{message}\fR\& action function with a non-boolean value, that value is added as an extra element to the message tuple either in the last position or before the timestamp (if it is present)\&. .LP Trace messages: .RS 2 .TP 2 .B \fI{trace, PidPort, send, Msg, To}\fR\&: When \fIPidPort\fR\& sends message \fIMsg\fR\& to process \fITo\fR\&\&. .TP 2 .B \fI{trace, PidPort, send_to_non_existing_process, Msg, To}\fR\&: When \fIPidPort\fR\& sends message \fIMsg\fR\& to the non-existing process \fITo\fR\&\&. .TP 2 .B \fI{trace, PidPort, \&'receive\&', Msg}\fR\&: When \fIPidPort\fR\& receives message \fIMsg\fR\&\&. If \fIMsg\fR\& is set to time-out, a receive statement can have timed out, or the process received a message with the payload \fItimeout\fR\&\&. .TP 2 .B \fI{trace, Pid, call, {M, F, Args}}\fR\&: When \fIPid\fR\& calls a traced function\&. The return values of calls are never supplied, only the call and its arguments\&. .RS 2 .LP Trace flag \fIarity\fR\& can be used to change the contents of this message, so that \fIArity\fR\& is specified instead of \fIArgs\fR\&\&. .RE .TP 2 .B \fI{trace, Pid, return_to, {M, F, Arity}}\fR\&: When \fIPid\fR\& returns \fIto\fR\& the specified function\&. This trace message is sent if both the flags \fIcall\fR\& and \fIreturn_to\fR\& are set, and the function is set to be traced on \fIlocal\fR\& function calls\&. The message is only sent when returning from a chain of tail recursive function calls, where at least one call generated a \fIcall\fR\& trace message (that is, the functions match specification matched, and \fI{message, false}\fR\& was not an action)\&. .TP 2 .B \fI{trace, Pid, return_from, {M, F, Arity}, ReturnValue}\fR\&: When \fIPid\fR\& returns \fIfrom\fR\& the specified function\&. This trace message is sent if flag \fIcall\fR\& is set, and the function has a match specification with a \fIreturn_trace\fR\& or \fIexception_trace\fR\& action\&. .TP 2 .B \fI{trace, Pid, exception_from, {M, F, Arity}, {Class, Value}}\fR\&: When \fIPid\fR\& exits \fIfrom\fR\& the specified function because of an exception\&. This trace message is sent if flag \fIcall\fR\& is set, and the function has a match specification with an \fIexception_trace\fR\& action\&. .TP 2 .B \fI{trace, Pid, spawn, Pid2, {M, F, Args}}\fR\&: When \fIPid\fR\& spawns a new process \fIPid2\fR\& with the specified function call as entry point\&. .RS 2 .LP \fIArgs\fR\& is supposed to be the argument list, but can be any term if the spawn is erroneous\&. .RE .TP 2 .B \fI{trace, Pid, spawned, Pid2, {M, F, Args}}\fR\&: When \fIPid\fR\& is spawned by process \fIPid2\fR\& with the specified function call as entry point\&. .RS 2 .LP \fIArgs\fR\& is supposed to be the argument list, but can be any term if the spawn is erroneous\&. .RE .TP 2 .B \fI{trace, Pid, exit, Reason}\fR\&: When \fIPid\fR\& exits with reason \fIReason\fR\&\&. .TP 2 .B \fI{trace, PidPort, register, RegName}\fR\&: When \fIPidPort\fR\& gets the name \fIRegName\fR\& registered\&. .TP 2 .B \fI{trace, PidPort, unregister, RegName}\fR\&: When \fIPidPort\fR\& gets the name \fIRegName\fR\& unregistered\&. This is done automatically when a registered process or port exits\&. .TP 2 .B \fI{trace, Pid, link, Pid2}\fR\&: When \fIPid\fR\& links to a process \fIPid2\fR\&\&. .TP 2 .B \fI{trace, Pid, unlink, Pid2}\fR\&: When \fIPid\fR\& removes the link from a process \fIPid2\fR\&\&. .TP 2 .B \fI{trace, PidPort, getting_linked, Pid2}\fR\&: When \fIPidPort\fR\& gets linked to a process \fIPid2\fR\&\&. .TP 2 .B \fI{trace, PidPort, getting_unlinked, Pid2}\fR\&: When \fIPidPort\fR\& gets unlinked from a process \fIPid2\fR\&\&. .TP 2 .B \fI{trace, Port, open, Pid, Driver}\fR\&: When \fIPid\fR\& opens a new port \fIPort\fR\& with the running \fIDriver\fR\&\&. .RS 2 .LP \fIDriver\fR\& is the name of the driver as an atom\&. .RE .TP 2 .B \fI{trace, Port, closed, Reason}\fR\&: When \fIPort\fR\& closes with \fIReason\fR\&\&. .TP 2 .B \fI{trace, Pid, in | in_exiting, {M, F, Arity} | 0}\fR\&: When \fIPid\fR\& is scheduled to run\&. The process runs in function \fI{M, F, Arity}\fR\&\&. On some rare occasions, the current function cannot be determined, then the last element is \fI0\fR\&\&. .TP 2 .B \fI{trace, Pid, out | out_exiting | out_exited, {M, F, Arity} | 0}\fR\&: When \fIPid\fR\& is scheduled out\&. The process was running in function {M, F, Arity}\&. On some rare occasions, the current function cannot be determined, then the last element is \fI0\fR\&\&. .TP 2 .B \fI{trace, Port, in, Command | 0}\fR\&: When \fIPort\fR\& is scheduled to run\&. \fICommand\fR\& is the first thing the port will execute, it can however run several commands before being scheduled out\&. On some rare occasions, the current function cannot be determined, then the last element is \fI0\fR\&\&. .RS 2 .LP The possible commands are \fIcall\fR\&, \fIclose\fR\&, \fIcommand\fR\&, \fIconnect\fR\&, \fIcontrol\fR\&, \fIflush\fR\&, \fIinfo\fR\&, \fIlink\fR\&, \fIopen\fR\&, and \fIunlink\fR\&\&. .RE .TP 2 .B \fI{trace, Port, out, Command | 0}\fR\&: When \fIPort\fR\& is scheduled out\&. The last command run was \fICommand\fR\&\&. On some rare occasions, the current function cannot be determined, then the last element is \fI0\fR\&\&. \fICommand\fR\& can contain the same commands as \fIin\fR\& .TP 2 .B \fI{trace, Pid, gc_minor_start, Info}\fR\&: .RS 2 .LP Sent when a young garbage collection is about to be started\&. \fIInfo\fR\& is a list of two-element tuples, where the first element is a key, and the second is the value\&. Do not depend on any order of the tuples\&. The following keys are defined: .RE .RS 2 .TP 2 .B \fIheap_size\fR\&: The size of the used part of the heap\&. .TP 2 .B \fIheap_block_size\fR\&: The size of the memory block used for storing the heap and the stack\&. .TP 2 .B \fIold_heap_size\fR\&: The size of the used part of the old heap\&. .TP 2 .B \fIold_heap_block_size\fR\&: The size of the memory block used for storing the old heap\&. .TP 2 .B \fIstack_size\fR\&: The size of the stack\&. .TP 2 .B \fIrecent_size\fR\&: The size of the data that survived the previous garbage collection\&. .TP 2 .B \fImbuf_size\fR\&: The combined size of message buffers associated with the process\&. .TP 2 .B \fIbin_vheap_size\fR\&: The total size of unique off-heap binaries referenced from the process heap\&. .TP 2 .B \fIbin_vheap_block_size\fR\&: The total size of binaries allowed in the virtual heap in the process before doing a garbage collection\&. .TP 2 .B \fIbin_old_vheap_size\fR\&: The total size of unique off-heap binaries referenced from the process old heap\&. .TP 2 .B \fIbin_old_vheap_block_size\fR\&: The total size of binaries allowed in the virtual old heap in the process before doing a garbage collection\&. .TP 2 .B \fIwordsize\fR\&: For the \fIgc_minor_start\fR\& event it is the size of the need that triggered the GC\&. For the corresponding \fIgc_minor_end\fR\& event it is the size of reclaimed memory = start \fIheap_size\fR\& - end \fIheap_size\fR\&\&. .RE .RS 2 .LP All sizes are in words\&. .RE .TP 2 .B \fI{trace, Pid, gc_max_heap_size, Info}\fR\&: Sent when the \fImax_heap_size\fR\& is reached during garbage collection\&. \fIInfo\fR\& contains the same kind of list as in message \fIgc_start\fR\&, but the sizes reflect the sizes that triggered \fImax_heap_size\fR\& to be reached\&. .TP 2 .B \fI{trace, Pid, gc_minor_end, Info}\fR\&: Sent when young garbage collection is finished\&. \fIInfo\fR\& contains the same kind of list as in message \fIgc_minor_start\fR\&, but the sizes reflect the new sizes after garbage collection\&. .TP 2 .B \fI{trace, Pid, gc_major_start, Info}\fR\&: Sent when fullsweep garbage collection is about to be started\&. \fIInfo\fR\& contains the same kind of list as in message \fIgc_minor_start\fR\&\&. .TP 2 .B \fI{trace, Pid, gc_major_end, Info}\fR\&: Sent when fullsweep garbage collection is finished\&. \fIInfo\fR\& contains the same kind of list as in message \fIgc_minor_start\fR\&, but the sizes reflect the new sizes after a fullsweep garbage collection\&. .RE .LP If the tracing process/port dies or the tracer module returns \fIremove\fR\&, the flags are silently removed\&. .LP Each process can only be traced by one tracer\&. Therefore, attempts to trace an already traced process fail\&. .LP Returns a number indicating the number of processes that matched \fIPidPortSpec\fR\&\&. If \fIPidPortSpec\fR\& is a process identifier, the return value is \fI1\fR\&\&. If \fIPidPortSpec\fR\& is \fIall\fR\& or \fIexisting\fR\&, the return value is the number of processes running\&. If \fIPidPortSpec\fR\& is \fInew\fR\&, the return value is \fI0\fR\&\&. .LP Failure: \fIbadarg\fR\& if the specified arguments are not supported\&. For example, \fIcpu_timestamp\fR\& is not supported on all platforms\&. .RE .LP .nf .B erlang:trace_delivered(Tracee) -> Ref .br .fi .br .RS .LP Types: .RS 3 Tracee = pid() | all .br Ref = reference() .br .RE .RE .RS .LP The delivery of trace messages (generated by \fIerlang:trace/3\fR\&, \fIseq_trace(3erl)\fR\&, or \fIerlang:system_profile/2\fR\&) is dislocated on the time-line compared to other events in the system\&. If you know that \fITracee\fR\& has passed some specific point in its execution, and you want to know when at least all trace messages corresponding to events up to this point have reached the tracer, use \fIerlang:trace_delivered(Tracee)\fR\&\&. .LP When it is guaranteed that all trace messages are delivered to the tracer up to the point that \fITracee\fR\& reached at the time of the call to \fIerlang:trace_delivered(Tracee)\fR\&, then a \fI{trace_delivered, Tracee, Ref}\fR\& message is sent to the caller of \fIerlang:trace_delivered(Tracee)\fR\& \&. .LP Notice that message \fItrace_delivered\fR\& does \fInot\fR\& imply that trace messages have been delivered\&. Instead it implies that all trace messages that \fIare to be delivered\fR\& have been delivered\&. It is not an error if \fITracee\fR\& is not, and has not been traced by someone, but if this is the case, \fIno\fR\& trace messages have been delivered when the \fItrace_delivered\fR\& message arrives\&. .LP Notice that \fITracee\fR\& must refer to a process currently or previously existing on the same node as the caller of \fIerlang:trace_delivered(Tracee)\fR\& resides on\&. The special \fITracee\fR\& atom \fIall\fR\& denotes all processes that currently are traced in the node\&. .LP When used together with a Tracer Module, any message sent in the trace callback is guaranteed to have reached its recipient before the \fItrace_delivered\fR\& message is sent\&. .LP Example: Process \fIA\fR\& is \fITracee\fR\&, port \fIB\fR\& is tracer, and process \fIC\fR\& is the port owner of \fIB\fR\&\&. \fIC\fR\& wants to close \fIB\fR\& when \fIA\fR\& exits\&. To ensure that the trace is not truncated, \fIC\fR\& can call \fIerlang:trace_delivered(A)\fR\& when \fIA\fR\& exits, and wait for message \fI{trace_delivered, A, Ref}\fR\& before closing \fIB\fR\&\&. .LP Failure: \fIbadarg\fR\& if \fITracee\fR\& does not refer to a process (dead or alive) on the same node as the caller of \fIerlang:trace_delivered(Tracee)\fR\& resides on\&. .RE .LP .nf .B erlang:trace_info(PidPortFuncEvent, Item) -> Res .br .fi .br .RS .LP Types: .RS 3 PidPortFuncEvent = .br pid() | .br port() | .br new | new_processes | new_ports | .br {Module, Function, Arity} | .br on_load | send | \&'receive\&' .br Module = module() .br Function = atom() .br Arity = arity() .br Item = .br flags | tracer | traced | match_spec | meta | .br meta_match_spec | call_count | call_time | all .br Res = trace_info_return() .br .nf \fBtrace_info_return()\fR\& = .br undefined | .br {flags, [trace_info_flag()]} | .br {tracer, pid() | port() | []} | .br {tracer, module(), term()} | .br trace_info_item_result() | .br {all, [trace_info_item_result()] | false | undefined} .fi .br .nf \fBtrace_info_item_result()\fR\& = .br {traced, global | local | false | undefined} | .br {match_spec, trace_match_spec() | false | undefined} | .br {meta, pid() | port() | false | undefined | []} | .br {meta, module(), term()} | .br {meta_match_spec, trace_match_spec() | false | undefined} | .br {call_count, integer() >= 0 | boolean() | undefined} | .br {call_time, .br [{pid(), .br integer() >= 0, .br integer() >= 0, .br integer() >= 0}] | .br boolean() | .br undefined} .fi .br .nf \fBtrace_info_flag()\fR\& = .br send | \&'receive\&' | set_on_spawn | call | return_to | procs | .br set_on_first_spawn | set_on_link | running | .br garbage_collection | timestamp | monotonic_timestamp | .br strict_monotonic_timestamp | arity .fi .br .nf \fBtrace_match_spec()\fR\& = .br [{[term()] | \&'_\&' | match_variable(), [term()], [term()]}] .fi .br .nf \fBmatch_variable()\fR\& = atom() .fi .br .RS 2 Approximation of \&'$1\&' | \&'$2\&' | \&'$3\&' | \&.\&.\&. .RE .RE .RE .RS .LP Returns trace information about a port, process, function, or event\&. .LP \fITo get information about a port or process\fR\&, \fIPidPortFuncEvent\fR\& is to be a process identifier (pid), port identifier, or one of the atoms \fInew\fR\&, \fInew_processes\fR\&, or \fInew_ports\fR\&\&. The atom \fInew\fR\& or \fInew_processes\fR\& means that the default trace state for processes to be created is returned\&. The atom \fInew_ports\fR\& means that the default trace state for ports to be created is returned\&. .LP Valid \fIItem\fR\&s for ports and processes: .RS 2 .TP 2 .B \fIflags\fR\&: Returns a list of atoms indicating what kind of traces is enabled for the process\&. The list is empty if no traces are enabled, and one or more of the following atoms if traces are enabled: \fIsend\fR\&, \fI\&'receive\&'\fR\&, \fIset_on_spawn\fR\&, \fIcall\fR\&, \fIreturn_to\fR\&, \fIprocs\fR\&, \fIports\fR\&, \fIset_on_first_spawn\fR\&, \fIset_on_link\fR\&, \fIrunning\fR\&, \fIrunning_procs\fR\&, \fIrunning_ports\fR\&, \fIsilent\fR\&, \fIexiting\fR\&, \fImonotonic_timestamp\fR\&, \fIstrict_monotonic_timestamp\fR\&, \fIgarbage_collection\fR\&, \fItimestamp\fR\&, and \fIarity\fR\&\&. The order is arbitrary\&. .TP 2 .B \fItracer\fR\&: Returns the identifier for process, port, or a tuple containing the tracer module and tracer state tracing this process\&. If this process is not traced, the return value is \fI[]\fR\&\&. .RE .LP \fITo get information about a function\fR\&, \fIPidPortFuncEvent\fR\& is to be the three-element tuple \fI{Module, Function, Arity}\fR\& or the atom \fIon_load\fR\&\&. No wildcards are allowed\&. Returns \fIundefined\fR\& if the function does not exist, or \fIfalse\fR\& if the function is not traced\&. If \fIPidPortFuncEvent\fR\& is \fIon_load\fR\&, the information returned refers to the default value for code that will be loaded\&. .LP Valid \fIItem\fR\&s for functions: .RS 2 .TP 2 .B \fItraced\fR\&: Returns \fIglobal\fR\& if this function is traced on global function calls, \fIlocal\fR\& if this function is traced on local function calls (that is, local and global function calls), and \fIfalse\fR\& if local or global function calls are not traced\&. .TP 2 .B \fImatch_spec\fR\&: Returns the match specification for this function, if it has one\&. If the function is locally or globally traced but has no match specification defined, the returned value is \fI[]\fR\&\&. .TP 2 .B \fImeta\fR\&: Returns the meta-trace tracer process, port, or trace module for this function, if it has one\&. If the function is not meta-traced, the returned value is \fIfalse\fR\&\&. If the function is meta-traced but has once detected that the tracer process is invalid, the returned value is \fI[]\fR\&\&. .TP 2 .B \fImeta_match_spec\fR\&: Returns the meta-trace match specification for this function, if it has one\&. If the function is meta-traced but has no match specification defined, the returned value is \fI[]\fR\&\&. .TP 2 .B \fIcall_count\fR\&: Returns the call count value for this function or \fItrue\fR\& for the pseudo function \fIon_load\fR\& if call count tracing is active\&. Otherwise \fIfalse\fR\& is returned\&. .RS 2 .LP See also \fIerlang:trace_pattern/3\fR\&\&. .RE .TP 2 .B \fIcall_time\fR\&: Returns the call time values for this function or \fItrue\fR\& for the pseudo function \fIon_load\fR\& if call time tracing is active\&. Otherwise \fIfalse\fR\& is returned\&. The call time values returned, \fI[{Pid, Count, S, Us}]\fR\&, is a list of each process that executed the function and its specific counters\&. .RS 2 .LP See also \fIerlang:trace_pattern/3\fR\&\&. .RE .TP 2 .B \fIall\fR\&: Returns a list containing the \fI{Item, Value}\fR\& tuples for all other items, or returns \fIfalse\fR\& if no tracing is active for this function\&. .RE .LP \fITo get information about an event\fR\&, \fIPidPortFuncEvent\fR\& is to be one of the atoms \fIsend\fR\& or \fI\&'receive\&'\fR\&\&. .LP One valid \fIItem\fR\& for events exists: .RS 2 .TP 2 .B \fImatch_spec\fR\&: Returns the match specification for this event, if it has one, or \fItrue\fR\& if no match specification has been set\&. .RE .LP The return value is \fI{Item, Value}\fR\&, where \fIValue\fR\& is the requested information as described earlier\&. If a pid for a dead process was specified, or the name of a non-existing function, \fIValue\fR\& is \fIundefined\fR\&\&. .RE .LP .nf .B erlang:trace_pattern(MFA, MatchSpec) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 MFA = trace_pattern_mfa() | send | \&'receive\&' .br MatchSpec = .br (MatchSpecList :: trace_match_spec()) | .br boolean() | .br restart | pause .br .nf \fBtrace_pattern_mfa()\fR\& = {atom(), atom(), arity() | \&'_\&'} | on_load .fi .br .nf \fBtrace_match_spec()\fR\& = .br [{[term()] | \&'_\&' | match_variable(), [term()], [term()]}] .fi .br .nf \fBmatch_variable()\fR\& = atom() .fi .br .RS 2 Approximation of \&'$1\&' | \&'$2\&' | \&'$3\&' | \&.\&.\&. .RE .RE .RE .RS .LP The same as \fIerlang:trace_pattern(Event, MatchSpec, [])\fR\&, retained for backward compatibility\&. .RE .LP .nf .B erlang:trace_pattern(MFA :: send, MatchSpec, FlagList :: []) -> .B integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 MatchSpec = (MatchSpecList :: trace_match_spec()) | boolean() .br .nf \fBtrace_match_spec()\fR\& = .br [{[term()] | \&'_\&' | match_variable(), [term()], [term()]}] .fi .br .nf \fBmatch_variable()\fR\& = atom() .fi .br .RS 2 Approximation of \&'$1\&' | \&'$2\&' | \&'$3\&' | \&.\&.\&. .RE .RE .RE .RS .LP Sets trace pattern for \fImessage sending\fR\&\&. Must be combined with \fIerlang:trace/3\fR\& to set the \fIsend\fR\& trace flag for one or more processes\&. By default all messages sent from \fIsend\fR\& traced processes are traced\&. To limit traced send events based on the message content, the sender and/or the receiver, use \fIerlang:trace_pattern/3\fR\&\&. .LP Argument \fIMatchSpec\fR\& can take the following forms: .RS 2 .TP 2 .B \fIMatchSpecList\fR\&: A list of match specifications\&. The matching is done on the list \fI[Receiver, Msg]\fR\&\&. \fIReceiver\fR\& is the process or port identity of the receiver and \fIMsg\fR\& is the message term\&. The pid of the sending process can be accessed with the guard function \fIself/0\fR\&\&. An empty list is the same as \fItrue\fR\&\&. For more information, see section Match Specifications in Erlang in the User\&'s Guide\&. .TP 2 .B \fItrue\fR\&: Enables tracing for all sent messages (from \fIsend\fR\& traced processes)\&. Any match specification is removed\&. \fIThis is the default\fR\&\&. .TP 2 .B \fIfalse\fR\&: Disables tracing for all sent messages\&. Any match specification is removed\&. .RE .LP Argument \fIFlagList\fR\& must be \fI[]\fR\& for send tracing\&. .LP The return value is always \fI1\fR\&\&. .LP Examples: .LP Only trace messages to a specific process \fIPid\fR\&: .LP .nf > erlang:trace_pattern(send, [{[Pid, \&'_\&'],[],[]}], [])\&. 1 .fi .LP Only trace messages matching \fI{reply, _}\fR\&: .LP .nf > erlang:trace_pattern(send, [{[\&'_\&', {reply,\&'_\&'}],[],[]}], [])\&. 1 .fi .LP Only trace messages sent to the sender itself: .LP .nf > erlang:trace_pattern(send, [{[\&'$1\&', \&'_\&'],[{\&'=:=\&',\&'$1\&',{self}}],[]}], [])\&. 1 .fi .LP Only trace messages sent to other nodes: .LP .nf > erlang:trace_pattern(send, [{[\&'$1\&', \&'_\&'],[{\&'=/=\&',{node,\&'$1\&'},{node}}],[]}], [])\&. 1 .fi .LP .RS -4 .B Note: .RE A match specification for \fIsend\fR\& trace can use all guard and body functions except \fIcaller\fR\&\&. .LP Fails by raising an error exception with an error reason of: .RS 2 .TP 2 .B \fIbadarg\fR\&: If an argument is invalid\&. .TP 2 .B \fIsystem_limit\fR\&: If a match specification passed as argument has excessive nesting which causes scheduler stack exhaustion for the scheduler that the calling process is executing on\&. Scheduler stack size can be configured when starting the runtime system\&. .RE .RE .LP .nf .B erlang:trace_pattern(MFA :: \&'receive\&', MatchSpec, FlagList :: []) -> .B integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 MatchSpec = (MatchSpecList :: trace_match_spec()) | boolean() .br .nf \fBtrace_match_spec()\fR\& = .br [{[term()] | \&'_\&' | match_variable(), [term()], [term()]}] .fi .br .nf \fBmatch_variable()\fR\& = atom() .fi .br .RS 2 Approximation of \&'$1\&' | \&'$2\&' | \&'$3\&' | \&.\&.\&. .RE .RE .RE .RS .LP Sets trace pattern for \fImessage receiving\fR\&\&. Must be combined with \fIerlang:trace/3\fR\& to set the \fI\&'receive\&'\fR\& trace flag for one or more processes\&. By default all messages received by \fI\&'receive\&'\fR\& traced processes are traced\&. To limit traced receive events based on the message content, the sender and/or the receiver, use \fIerlang:trace_pattern/3\fR\&\&. .LP Argument \fIMatchSpec\fR\& can take the following forms: .RS 2 .TP 2 .B \fIMatchSpecList\fR\&: A list of match specifications\&. The matching is done on the list \fI[Node, Sender, Msg]\fR\&\&. \fINode\fR\& is the node name of the sender\&. \fISender\fR\& is the process or port identity of the sender, or the atom \fIundefined\fR\& if the sender is not known (which can be the case for remote senders)\&. \fIMsg\fR\& is the message term\&. The pid of the receiving process can be accessed with the guard function \fIself/0\fR\&\&. An empty list is the same as \fItrue\fR\&\&. For more information, see section Match Specifications in Erlang in the User\&'s Guide\&. .TP 2 .B \fItrue\fR\&: Enables tracing for all received messages (to \fI\&'receive\&'\fR\& traced processes)\&. Any match specification is removed\&. \fIThis is the default\fR\&\&. .TP 2 .B \fIfalse\fR\&: Disables tracing for all received messages\&. Any match specification is removed\&. .RE .LP Argument \fIFlagList\fR\& must be \fI[]\fR\& for receive tracing\&. .LP The return value is always \fI1\fR\&\&. .LP Examples: .LP Only trace messages from a specific process \fIPid\fR\&: .LP .nf > erlang:trace_pattern(\&'receive\&', [{[\&'_\&',Pid, \&'_\&'],[],[]}], [])\&. 1 .fi .LP Only trace messages matching \fI{reply, _}\fR\&: .LP .nf > erlang:trace_pattern(\&'receive\&', [{[\&'_\&',\&'_\&', {reply,\&'_\&'}],[],[]}], [])\&. 1 .fi .LP Only trace messages from other nodes: .LP .nf > erlang:trace_pattern(\&'receive\&', [{[\&'$1\&', \&'_\&', \&'_\&'],[{\&'=/=\&',\&'$1\&',{node}}],[]}], [])\&. 1 .fi .LP .RS -4 .B Note: .RE A match specification for \fI\&'receive\&'\fR\& trace can use all guard and body functions except \fIcaller\fR\&, \fIis_seq_trace\fR\&, \fIget_seq_token\fR\&, \fIset_seq_token\fR\&, \fIenable_trace\fR\&, \fIdisable_trace\fR\&, \fItrace\fR\&, \fIsilent\fR\&, and \fIprocess_dump\fR\&\&. .LP Fails by raising an error exception with an error reason of: .RS 2 .TP 2 .B \fIbadarg\fR\&: If an argument is invalid\&. .TP 2 .B \fIsystem_limit\fR\&: If a match specification passed as argument has excessive nesting which causes scheduler stack exhaustion for the scheduler that the calling process is executing on\&. Scheduler stack size can be configured when starting the runtime system\&. .RE .RE .LP .nf .B erlang:trace_pattern(MFA, MatchSpec, FlagList) -> .B integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 MFA = trace_pattern_mfa() .br MatchSpec = .br (MatchSpecList :: trace_match_spec()) | .br boolean() | .br restart | pause .br FlagList = [trace_pattern_flag()] .br .nf \fBtrace_pattern_mfa()\fR\& = {atom(), atom(), arity() | \&'_\&'} | on_load .fi .br .nf \fBtrace_match_spec()\fR\& = .br [{[term()] | \&'_\&' | match_variable(), [term()], [term()]}] .fi .br .nf \fBtrace_pattern_flag()\fR\& = .br global | local | meta | .br {meta, Pid :: pid()} | .br {meta, TracerModule :: module(), TracerState :: term()} | .br call_count | call_time .fi .br .nf \fBmatch_variable()\fR\& = atom() .fi .br .RS 2 Approximation of \&'$1\&' | \&'$2\&' | \&'$3\&' | \&.\&.\&. .RE .RE .RE .RS .LP Enables or disables \fIcall tracing\fR\& for one or more functions\&. Must be combined with \fIerlang:trace/3\fR\& to set the \fIcall\fR\& trace flag for one or more processes\&. .LP Conceptually, call tracing works as follows\&. Inside the Erlang virtual machine, a set of processes and a set of functions are to be traced\&. If a traced process calls a traced function, the trace action is taken\&. Otherwise, nothing happens\&. .LP To add or remove one or more processes to the set of traced processes, use \fIerlang:trace/3\fR\&\&. .LP To add or remove functions to the set of traced functions, use \fIerlang:trace_pattern/3\fR\&\&. .LP The BIF \fIerlang:trace_pattern/3\fR\& can also add match specifications to a function\&. A match specification comprises a pattern that the function arguments must match, a guard expression that must evaluate to \fItrue\fR\&, and an action to be performed\&. The default action is to send a trace message\&. If the pattern does not match or the guard fails, the action is not executed\&. .LP Argument \fIMFA\fR\& is to be a tuple, such as \fI{Module, Function, Arity}\fR\&, or the atom \fIon_load\fR\& (described below)\&. It can be the module, function, and arity for a function (or a BIF in any module)\&. The atom \fI\&'_\&'\fR\& can be used as a wildcard in any of the following ways: .RS 2 .TP 2 .B \fI{Module,Function,\&'_\&'}\fR\&: All functions of any arity named \fIFunction\fR\& in module \fIModule\fR\&\&. .TP 2 .B \fI{Module,\&'_\&',\&'_\&'}\fR\&: All functions in module \fIModule\fR\&\&. .TP 2 .B \fI{\&'_\&',\&'_\&',\&'_\&'}\fR\&: All functions in all loaded modules\&. .RE .LP Other combinations, such as \fI{Module,\&'_\&',Arity}\fR\&, are not allowed\&. Local functions match wildcards only if option \fIlocal\fR\& is in \fIFlagList\fR\&\&. .LP If argument \fIMFA\fR\& is the atom \fIon_load\fR\&, the match specification and flag list are used on all modules that are newly loaded\&. .LP Argument \fIMatchSpec\fR\& can take the following forms: .RS 2 .TP 2 .B \fIfalse\fR\&: Disables tracing for the matching functions\&. Any match specification is removed\&. .TP 2 .B \fItrue\fR\&: Enables tracing for the matching functions\&. Any match specification is removed\&. .TP 2 .B \fIMatchSpecList\fR\&: A list of match specifications\&. An empty list is equivalent to \fItrue\fR\&\&. For a description of match specifications, see section Match Specifications in Erlang in the User\&'s Guide\&. .TP 2 .B \fIrestart\fR\&: For the \fIFlagList\fR\& options \fIcall_count\fR\& and \fIcall_time\fR\&: restarts the existing counters\&. The behavior is undefined for other \fIFlagList\fR\& options\&. .TP 2 .B \fIpause\fR\&: For the \fIFlagList\fR\& options \fIcall_count\fR\& and \fIcall_time\fR\&: pauses the existing counters\&. The behavior is undefined for other \fIFlagList\fR\& options\&. .RE .LP Parameter \fIFlagList\fR\& is a list of options\&. The following are the valid options: .RS 2 .TP 2 .B \fIglobal\fR\&: Turns on or off call tracing for global function calls (that is, calls specifying the module explicitly)\&. Only exported functions match and only global calls generate trace messages\&. \fIThis is the default\fR\&\&. .TP 2 .B \fIlocal\fR\&: Turns on or off call tracing for all types of function calls\&. Trace messages are sent whenever any of the specified functions are called, regardless of how they are called\&. If flag \fIreturn_to\fR\& is set for the process, a \fIreturn_to\fR\& message is also sent when this function returns to its caller\&. .TP 2 .B \fImeta | {meta, Pid} | {meta, TracerModule, TracerState}\fR\&: Turns on or off meta-tracing for all types of function calls\&. Trace messages are sent to the tracer whenever any of the specified functions are called\&. If no tracer is specified, \fIself()\fR\& is used as a default tracer process\&. .RS 2 .LP Meta-tracing traces all processes and does not care about the process trace flags set by \fIerlang:trace/3\fR\&, the trace flags are instead fixed to \fI[call, timestamp]\fR\&\&. .RE .RS 2 .LP The match specification function \fI{return_trace}\fR\& works with meta-trace and sends its trace message to the same tracer\&. .RE .TP 2 .B \fIcall_count\fR\&: Starts (\fIMatchSpec == true\fR\&) or stops (\fIMatchSpec == false\fR\&) call count tracing for all types of function calls\&. For every function, a counter is incremented when the function is called, in any process\&. No process trace flags need to be activated\&. .RS 2 .LP If call count tracing is started while already running, the count is restarted from zero\&. To pause running counters, use \fIMatchSpec == pause\fR\&\&. Paused and running counters can be restarted from zero with \fIMatchSpec == restart\fR\&\&. .RE .RS 2 .LP To read the counter value, use \fIerlang:trace_info/2\fR\&\&. .RE .TP 2 .B \fIcall_time\fR\&: Starts (\fIMatchSpec == true\fR\&) or stops (\fIMatchSpec == false\fR\&) call time tracing for all types of function calls\&. For every function, a counter is incremented when the function is called\&. Time spent in the function is accumulated in two other counters, seconds and microseconds\&. The counters are stored for each call traced process\&. .RS 2 .LP If call time tracing is started while already running, the count and time restart from zero\&. To pause running counters, use \fIMatchSpec == pause\fR\&\&. Paused and running counters can be restarted from zero with \fIMatchSpec == restart\fR\&\&. .RE .RS 2 .LP To read the counter value, use \fIerlang:trace_info/2\fR\&\&. .RE .RE .LP The options \fIglobal\fR\& and \fIlocal\fR\& are mutually exclusive, and \fIglobal\fR\& is the default (if no options are specified)\&. The options \fIcall_count\fR\& and \fImeta\fR\& perform a kind of local tracing, and cannot be combined with \fIglobal\fR\&\&. A function can be globally or locally traced\&. If global tracing is specified for a set of functions, then local, meta, call time, and call count tracing for the matching set of local functions is disabled, and conversely\&. .LP When disabling trace, the option must match the type of trace set on the function\&. That is, local tracing must be disabled with option \fIlocal\fR\& and global tracing with option \fIglobal\fR\& (or no option), and so on\&. .LP Part of a match specification list cannot be changed directly\&. If a function has a match specification, it can be replaced with a new one\&. To change an existing match specification, use the BIF \fIerlang:trace_info/2\fR\& to retrieve the existing match specification\&. .LP Returns the number of functions matching argument \fIMFA\fR\&\&. This is zero if none matched\&. .LP Fails by raising an error exception with an error reason of: .RS 2 .TP 2 .B \fIbadarg\fR\&: If an argument is invalid\&. .TP 2 .B \fIsystem_limit\fR\&: If a match specification passed as argument has excessive nesting which causes scheduler stack exhaustion for the scheduler that the calling process is executing on\&. Scheduler stack size can be configured when starting the runtime system\&. .RE .RE .LP .nf .B trunc(Number) -> integer() .br .fi .br .RS .LP Types: .RS 3 Number = number() .br .RE .RE .RS .LP Truncates the decimals of \fINumber\fR\&, for example: .LP .nf > trunc(5\&.7)\&. 5 .fi .LP .nf > trunc(-5\&.7)\&. -5 .fi .LP .nf > trunc(5)\&. 5 .fi .LP .nf > trunc(36028797018963969\&.0)\&. 36028797018963968 .fi .LP In the last example, \fItrunc(36028797018963969\&.0)\fR\& evaluates to \fI36028797018963968\fR\&\&. The reason for this is that the number \fI36028797018963969\&.0\fR\& cannot be represented exactly as a float value\&. Instead, the float literal is represented as \fI36028797018963968\&.0\fR\&, which is the closest number that can be represented exactly as a float value\&. See Representation of Floating Point Numbers for additional information\&. .LP Allowed in guard tests\&. .RE .LP .nf .B tuple_size(Tuple) -> integer() >= 0 .br .fi .br .RS .LP Types: .RS 3 Tuple = tuple() .br .RE .RE .RS .LP Returns an integer that is the number of elements in \fITuple\fR\&, for example: .LP .nf > tuple_size({morni, mulle, bwange})\&. 3 .fi .LP Allowed in guard tests\&. .RE .LP .nf .B tuple_to_list(Tuple) -> [term()] .br .fi .br .RS .LP Types: .RS 3 Tuple = tuple() .br .RE .RE .RS .LP Returns a list corresponding to \fITuple\fR\&\&. \fITuple\fR\& can contain any Erlang terms\&. Example: .LP .nf > tuple_to_list({share, {\&'Ericsson_B\&', 163}})\&. [share,{'Ericsson_B',163}] .fi .RE .LP .nf .B unalias(Alias) -> boolean() .br .fi .br .RS .LP Types: .RS 3 Alias = reference() .br .RE .RE .RS .LP Deactivate the alias \fIAlias\fR\& previously created by the calling process\&. An alias can for example be created via \fIalias/0\fR\&, or \fImonitor/3\fR\&\&. \fIunalias/1\fR\& will always deactivate the alias regardless of options used when creating the alias\&. .LP Returns true if \fIAlias\fR\& was a currently active alias for current processes; otherwise, false\&. .LP For more information on process aliases see the \fIProcess Aliases\fR\& section of the \fIErlang Reference Manual\fR\& \&. .RE .LP .nf .B erlang:unique_integer() -> integer() .br .fi .br .RS .LP Generates and returns an integer unique on current runtime system instance\&. The same as calling \fIerlang:unique_integer([])\fR\&\&. .RE .LP .nf .B erlang:unique_integer(ModifierList) -> integer() .br .fi .br .RS .LP Types: .RS 3 ModifierList = [Modifier] .br Modifier = positive | monotonic .br .RE .RE .RS .LP Generates and returns an integer unique on current runtime system instance\&. The integer is unique in the sense that this BIF, using the same set of modifiers, does not return the same integer more than once on the current runtime system instance\&. Each integer value can of course be constructed by other means\&. .LP By default, when \fI[]\fR\& is passed as \fIModifierList\fR\&, both negative and positive integers can be returned\&. This to use the range of integers that do not need heap memory allocation as much as possible\&. By default the returned integers are also only guaranteed to be unique, that is, any returned integer can be smaller or larger than previously returned integers\&. .LP \fIModifier\fR\&s: .RS 2 .TP 2 .B positive: Returns only positive integers\&. .RS 2 .LP Notice that by passing the \fIpositive\fR\& modifier you will get heap allocated integers (bignums) quicker\&. .RE .TP 2 .B monotonic: Returns strictly monotonically increasing integers corresponding to creation time\&. That is, the integer returned is always larger than previously returned integers on the current runtime system instance\&. .RS 2 .LP These values can be used to determine order between events on the runtime system instance\&. That is, if both \fIX = erlang:unique_integer([monotonic])\fR\& and \fIY = erlang:unique_integer([monotonic])\fR\& are executed by different processes (or the same process) on the same runtime system instance and \fIX < Y\fR\&, we know that \fIX\fR\& was created before \fIY\fR\&\&. .RE .LP .RS -4 .B Warning: .RE Strictly monotonically increasing values are inherently quite expensive to generate and scales poorly\&. This is because the values need to be synchronized between CPU cores\&. That is, do not pass the \fImonotonic\fR\& modifier unless you really need strictly monotonically increasing values\&. .RE .LP All valid \fIModifier\fR\&s can be combined\&. Repeated (valid) \fIModifier\fR\&s in the \fIModifierList\fR\& are ignored\&. .LP .RS -4 .B Note: .RE The set of integers returned by \fIerlang:unique_integer/1\fR\& using different sets of \fIModifier\fR\&s \fIwill overlap\fR\&\&. For example, by calling \fIunique_integer([monotonic])\fR\&, and \fIunique_integer([positive, monotonic])\fR\& repeatedly, you will eventually see some integers that are returned by both calls\&. .LP Failures: .RS 2 .TP 2 .B \fIbadarg\fR\&: if \fIModifierList\fR\& is not a proper list\&. .TP 2 .B \fIbadarg\fR\&: if \fIModifier\fR\& is not a valid modifier\&. .RE .RE .LP .nf .B erlang:universaltime() -> DateTime .br .fi .br .RS .LP Types: .RS 3 DateTime = calendar:datetime() .br .RE .RE .RS .LP Returns the current date and time according to Universal Time Coordinated (UTC) in the form \fI{{Year, Month, Day}, {Hour, Minute, Second}}\fR\& if supported by the underlying OS\&. Otherwise \fIerlang:universaltime()\fR\& is equivalent to \fIerlang:localtime()\fR\&\&. The return value is based on the OS System Time\&. Example: .LP .nf > erlang:universaltime()\&. {{1996,11,6},{14,18,43}} .fi .RE .LP .nf .B erlang:universaltime_to_localtime(Universaltime) -> Localtime .br .fi .br .RS .LP Types: .RS 3 Localtime = Universaltime = calendar:datetime() .br .RE .RE .RS .LP Converts Universal Time Coordinated (UTC) date and time to local date and time in the form \fI{{Year, Month, Day}, {Hour, Minute, Second}}\fR\& if supported by the underlying OS\&. Otherwise no conversion is done, and \fIUniversaltime\fR\& is returned\&. Example: .LP .nf > erlang:universaltime_to_localtime({{1996,11,6},{14,18,43}})\&. {{1996,11,7},{15,18,43}} .fi .LP Failure: \fIbadarg\fR\& if \fIUniversaltime\fR\& denotes an invalid date and time\&. .RE .LP .nf .B unlink(Id) -> true .br .fi .br .RS .LP Types: .RS 3 Id = pid() | port() .br .RE .RE .RS .LP Removes a link between the calling process and another process or a port identified by \fIId\fR\&\&. We will from here on call the identified process or port unlinkee\&. .LP A link can be set up using the \fIlink/1\fR\& BIF\&. For more information on links and exit signals due to links, see the \fIProcesses\fR\& chapter in the \fIErlang Reference Manual\fR\& : .RS 2 .TP 2 * Links .LP .TP 2 * Sending Exit Signals .LP .TP 2 * Receiving Exit Signals .LP .RE .LP Once \fIunlink(Id)\fR\& has returned, it is guaranteed that the link between the caller and the unlinkee has no effect on the caller in the future (unless the link is setup again)\&. Note that if the caller is trapping exits, an \fI{\&'EXIT\&', Id, ExitReason}\fR\& message due to the link may have been placed in the message queue of the caller before the \fIunlink(Id)\fR\& call completed\&. Also note that the \fI{\&'EXIT\&', Id, ExitReason}\fR\& message may be the result of the link, but may also be the result of the unlikee sending the caller an exit signal by calling the \fIexit/2\fR\& BIF\&. Therefore, it may or may not be appropriate to clean up the message queue after a call to \fIunlink(Id)\fR\& as follows, when trapping exits: .LP .nf unlink(Id), receive {'EXIT', Id, _} -> true after 0 -> true end .fi .LP The link removal is performed asynchronously\&. If such a link does not exist, nothing is done\&. A detailed description of the link protocol can be found in the \fIDistribution Protocol\fR\& chapter of the \fIERTS User\&'s Guide\fR\& \&. .LP Failure: \fIbadarg\fR\& if \fIId\fR\& does not identify a process or a node local port\&. .RE .LP .nf .B unregister(RegName) -> true .br .fi .br .RS .LP Types: .RS 3 RegName = atom() .br .RE .RE .RS .LP Removes the \fIregistered name\fR\& \fIRegName\fR\& associated with a process identifier or a port identifier from the \fIname registry\fR\&\&. For example: .LP .nf > unregister(db)\&. true .fi .LP Keep in mind that you can still receive signals associated with the registered name after it has been unregistered as the sender may have looked up the name before sending to it\&. .LP Users are advised not to unregister system processes\&. .LP Failure: \fIbadarg\fR\& if \fIRegName\fR\& is not a registered name\&. .RE .LP .nf .B whereis(RegName) -> pid() | port() | undefined .br .fi .br .RS .LP Types: .RS 3 RegName = atom() .br .RE .RE .RS .LP Returns the process identifier or port identifier with the \fIregistered name\fR\& \fIRegName\fR\& from the \fIname registry\fR\&\&. Returns \fIundefined\fR\& if the name is not registered\&. Example: .LP .nf > whereis(db)\&. <0.43.0> .fi .RE .LP .nf .B erlang:yield() -> true .br .fi .br .RS .LP Tries to give other processes with the same or higher priority (if any) a chance to execute before returning\&. There is no guarantee that any other process runs between the invocation and return of \fIerlang:yield/0\fR\&\&. .LP See the documentation for \fIreceive-after\fR\& expressions for how to make the current process sleep for a specific number of milliseconds\&. .LP .RS -4 .B Warning: .RE There is seldom or never any need to use this BIF\&. Using this BIF without a thorough grasp of how the scheduler works can cause performance degradation\&. The current implementation of this function puts the current process last in the current scheduler\&'s queue for processes of the same priority as the current process\&. .RE