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
auto-imported. Thus, it is not necessary to specify the
module name. For example, the calls
Auto-imported BIFs are listed without module prefix. BIFs listed with module prefix are not auto-imported.
Predefined types are listed in the
BIFs can fail for various reasons. All BIFs fail with
reason
Some BIFs can be used in guard tests and are marked with "Allowed in guard tests".
All possible Erlang terms. Synonym for
The arity of a function or type.
An Erlang
An Erlang
An Erlang
A
A byte of data represented by an integer.
An ASCII character or a
An Erlang
An Erlang
An unique identifier for some entity, for example a
An Erlang
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:
To convert an iodata() term to binary() you can use
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:
In most use cases you want to use
An Erlang
An Erlang
An Erlang
An Erlang
An Erlang
A three-tuple representing a
An Erlang module represented by an atom.
A negative integer.
The empty
The type used to show that a function will never return a value, that is it will always throw an exception.
An Erlang
A non-negative integer, that is any positive integer or 0.
This type is used to show that a function will never return a value;
that is it will always throw an exception. In a spec, use
A
A
A
A
A
A
A
A
An Erlang
An Erlang
An Erlang
An integer greater than zero.
An Erlang
A character string represented by a list of ASCII characters or unicode codepoints.
All possible Erlang terms. Synonym for
A timeout value that can be passed to a
An Erlang
A binary data object, structured according to the Erlang external term format.
A term of type
A list of binaries. This datatype is useful to use
together with
See
See
See
Supported time unit representations:
Time unit expressed in parts per second. That is,
the time unit equals
Symbolic representation of the time unit
represented by the integer
Symbolic representation of the time unit
represented by the integer
Symbolic representation of the time unit
represented by the integer
Symbolic representation of the time unit
represented by the integer
Symbolic representation of the native time unit used by the Erlang runtime system.
The
One can get an approximation of the
The value of the
Symbolic representation of the performance counter time unit used by the Erlang runtime system.
The
Deprecated symbolic representations kept for backwards-compatibility.
The
The
Same as
Same as
Same as
Same as
An opaque handle identifying a distribution channel.
An opaque handle identifying a
Options for
Process priority level. For more info see
Process max heap size configuration. For more info see
Process message queue data configuration. For more information, see
An Erlang stacktrace as described by
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
Returns an integer or float that is the arithmetical
absolute value of
> abs(-3.33). 3.33 > abs(-3). 3
Allowed in guard tests.
Computes and returns the adler32 checksum for
Continues computing the adler32 checksum by combining
the previous checksum,
The following code:
X = erlang:adler32(Data1),
Y = erlang:adler32(X,Data2).
assigns the same value to
Y = erlang:adler32([Data1,Data2]).
Combines two previously computed adler32 checksums. This computation requires the size of the data object for the second checksum to be known.
The following code:
Y = erlang:adler32(Data1),
Z = erlang:adler32(Y,Data2).
assigns the same value to
X = erlang:adler32(Data1),
Y = erlang:adler32(Data2),
Z = erlang:adler32_combine(X,Y,iolist_size(Data2)).
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
The alias can only be deactivated via a
call to
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
Example:
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.
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.
For more information on process aliases see the
Returns a new tuple that has one element more than
> erlang:append_element({one, two}, three). {one,two,three}
Calls a fun, passing the elements in
If the number of elements in the arguments are known at
compile time, the call is better written as
Earlier,
Returns the result of applying
> apply(lists, reverse, [[a, b, c]]). [c,b,a] > apply(erlang, atom_to_list, ['Erlang']). "Erlang"
If the number of arguments are known at compile time,
the call is better written as
Failure:
The same as
Returns a binary corresponding to the text
representation of
As from Erlang/OTP 20, atoms can contain any Unicode character
and
Example:
> atom_to_binary('Erlang', latin1). <<"Erlang">>
Returns a list of unicode code points corresponding to the text
representation of
> atom_to_list('Erlang'). "Erlang"
> atom_to_list('你好'). [20320,22909]
See
Extracts the part of the binary described by
Negative length can be used to extract bytes at the end of a binary, for example:
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>>
Failure:
1> Bin = <<1,2,3>>
2> binary_part(Bin,{0,2}).
<<1,2>>
For details about the
Allowed in guard tests.
The same as
Allowed in guard tests.
The same as
Returns the atom whose text representation is
As from Erlang/OTP 20,
The number of characters that are permitted in an atom
name is limited. The default limits can be found in the
There is configurable limit on how many atoms that can
exist and atoms are not garbage collected. Therefore, it is
recommended to consider whether
Examples:
> binary_to_atom(<<"Erlang">>, latin1). 'Erlang'
> binary_to_atom(<<1024/utf8>>, utf8). 'Ѐ'
The same as
As
The Erlang system has a
An atom exists in an Erlang system when included in a
loaded Erlang module or when created programmatically (for
example, by
Failure:
Note that the compiler may optimize away atoms. For
example, the compiler will rewrite
The number of characters that are permitted in an atom
name is limited. The default limits can be found in the
Returns the float whose text representation is
> binary_to_float(<<"2.2017764e+0">>). 2.2017764
The float string format is the same as the format for
Failure:
Returns an integer whose text representation is
> binary_to_integer(<<"123">>). 123
Failure:
Returns an integer whose text representation in base
> binary_to_integer(<<"3FF">>, 16). 1023
Failure:
Returns a list of integers corresponding to the bytes of
As
The one-based indexing for binaries used by
this function is deprecated. New code is to use
Returns an Erlang term that is the result of decoding
binary object
> Bin = term_to_binary(hello). <<131,100,0,5,104,101,108,108,111>> > hello = binary_to_term(Bin). hello
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
See also
As
Use this option when receiving binaries from an untrusted source.
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
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.
> 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
The
Changes the return value to
> 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">>}
Failure:
See also
Returns an integer that is the size in bits of
> bit_size(<<433:16,3:3>>). 19 > bit_size(<<1,2,3>>). 24
Allowed in guard tests.
Returns a list of integers corresponding to the bytes of
> bitstring_to_list(<<433:16>>). [1,177]
> bitstring_to_list(<<433:16,3:3>>). [1,177,<<3:3>>]
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).
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.
Returns an integer that is the number of bytes needed to
contain
> byte_size(<<433:16,3:3>>). 3 > byte_size(<<1,2,3>>). 3
Allowed in guard tests.
Cancels a timer. The same as calling
Cancels a timer that has been created by
Asynchronous request for cancellation.
Requests information about the
When
When
More
If
If
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
See also
Returns the smallest integer not less than
> ceil(5.5). 6
Allowed in guard tests.
Returns
See also
The same as
Checks if the node local process identified by
Determines if garbage collection is allowed when performing
the operation. If
The function
If
The process identified by
The process identified by
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
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 (
As of ERTS version 9.0, the check process code operation
only checks for direct references to the code. Indirect
references via
See also
Failures:
Converts the
You can lose accuracy and precision when converting
between time units. To minimize such loss, collect all
data at
Computes and returns the crc32 (IEEE 802.3 style) checksum
for
Continues computing the crc32 checksum by combining
the previous checksum,
The following code:
X = erlang:crc32(Data1),
Y = erlang:crc32(X,Data2).
assigns the same value to
Y = erlang:crc32([Data1,Data2]).
Combines two previously computed crc32 checksums. This computation requires the size of the data object for the second checksum to be known.
The following code:
Y = erlang:crc32(Data1),
Z = erlang:crc32(Y,Data2).
assigns the same value to
X = erlang:crc32(Data1),
Y = erlang:crc32(Data2),
Z = erlang:crc32_combine(X,Y,iolist_size(Data2)).
Returns the current date as
The time zone and Daylight Saving Time correction depend on
the underlying OS. The return value is based on the
> date(). {1995,2,19}
Decodes the binary
If an entire packet is contained in
If
If the packet does not conform to the protocol format,
No packet handling is done. The entire binary is returned unless it is empty.
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.
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
The header is not stripped off.
The meanings of the packet types are as follows:
The Hypertext Transfer Protocol. The packets
are returned with the format according to
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,
The protocol type
The variants
Since OTP 26.0,
Options:
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.
For packet type
Option
For packet type
Examples:
> erlang:decode_packet(1,<<3,"abcd">>,[]). {ok,<<"abc">>,<<"d">>} > erlang:decode_packet(1,<<5,"abcd">>,[]). {more,6}
Returns a new tuple with element at
> erlang:delete_element(2, {one, two, three}). {one,three}
Makes the current code for
This BIF is intended for the code server (see
Failure:
If
Once
For some important information about distributed signals, see the
Before Erlang/OTP R11B (ERTS 5.5)
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.
Failure: It is an error if
The returned value is
Removes (one)
Calling
demonitor(MonitorRef),
receive
{_, MonitorRef, _, _, _} ->
true
after 0 ->
true
end
The returned value is one of the following:
The monitor was found and removed. In this case,
no
The monitor was not found and could not be removed.
This probably because someone already has placed a
If option
More options can be added in a future release.
Failures:
Forces the disconnection of a node. This appears to
the node
Returns
This function may return before
Prints a text representation of
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.
Get distribution channel data from the local node that is
to be passed to the remote node. The distribution channel
is identified by
The returned value when there are data available depends
on the value of the
Only the process registered as distribution
controller for the distribution channel identified by
This function is used when implementing an alternative
distribution carrier using processes as distribution
controllers.
Returns the value of the
Only the process registered as distribution
controller for the distribution channel identified by
This function is used when implementing an alternative
distribution carrier using processes as distribution
controllers.
Request notification when more data is available to
fetch using
Only the process registered as distribution
controller for the distribution channel identified by
This function is used when implementing an alternative
distribution carrier using processes as distribution
controllers.
Register an alternate input handler process for the
distribution channel identified by
Only the process registered as distribution
controller for the distribution channel identified by
This function is used when implementing an alternative
distribution carrier using processes as distribution
controllers.
Deliver distribution channel data from a remote node to the local node.
Only the process registered as distribution
controller for the distribution channel identified by
This function is used when implementing an alternative
distribution carrier using processes as distribution
controllers.
Sets the value of the
All options are set to default when a channel is closed.
Only the process registered as distribution
controller for the distribution channel identified by
This function is used when implementing an alternative
distribution carrier using processes as distribution
controllers.
Returns the
> element(2, {a, b, c}). b
Allowed in guard tests.
Returns the process dictionary and deletes it, for example:
> put(key1, {1, 2, 3}), put(key2, [a, b, c]), erase(). [{key1,{1,2,3}},{key2,[a,b,c]}]
Returns the value
> put(key1, {merry, lambs, are, playing}), X = erase(key1), {X, erase(key1)}. {{merry,lambs,are,playing},undefined}
Raises an exception of class
The intent of the exception class
> 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}]}]}}
Raises an exception of class
The intent of the exception class
-module(test).
-export([example_fun/2]).
example_fun(A1, A2) ->
erlang:error(my_error, [A1, A2]).
Erlang shell:
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")
Raises an exception of class
If the
The default
The intent of the exception class
Raises an exception of class
The intent of the exception class
This function differ from
See the guide about
Example:
> exit(foobar). ** exception exit: foobar > catch exit(foobar). {'EXIT',foobar}
If a process calls
Sends an exit signal with exit reason
The following behavior applies if
If
If
The following behavior applies if
If
The functions
The only scenario that has not been covered by the
description above is when a process
Note that the behavior described above is different from
when a process sends an exit signal with reason
For some important information about distributed signals, see the
Calculates, without doing the encoding, the maximum byte size for a term encoded in the Erlang external term format. The following condition applies always:
> Size1 = byte_size(term_to_binary(Term )), > Size2 = erlang:external_size(Term ), > true = Size1 =< Size2. true
This is equivalent to a call to:
erlang:external_size(Term , [])
Calculates, without doing the encoding, the maximum byte size for a term encoded in the Erlang external term format. The following condition applies always:
> Size1 = byte_size(term_to_binary(Term ,Options )), > Size2 = erlang:external_size(Term ,Options ), > true = Size1 =< Size2. true
Option
Returns a float by converting
> float(55). 55.0
Allowed in guard tests.
If used on the top level in a guard, it tests whether the
argument is a floating point number; for clarity, use
When
The same as
Returns a binary corresponding to the text
representation of
> 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">>
The same as
Returns a string corresponding to the text representation
of
Available options:
If option
If option
If option
If option
If
Examples:
> 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"
In the last example,
Returns the largest integer not greater than
> floor(-10.5). -11
Allowed in guard tests.
Returns a list with information about the fun
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.
Two types of funs have slightly different semantics:
A fun created by
All other funs are called local. 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).
The following elements are always present in the list for both local and external funs:
If
If
If
If
The following elements are only present in the list if
It might point to the
In Erlang/OTP 27, we plan to change the return value so that
it always points to the local
Returns information about
For any fun,
For a local fun,
See
Returns
The form of
Generally, one can not use
The output of
Examples:
-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}.
> {fun test:add/1, test:add2()}. {fun test:add/1,#Fun<test.1.107738983>}
Explanation:
> {test:add(1), test:add(42)}. {#Fun<test.0.107738983>,#Fun<test.0.107738983>}
Explanation:
>test:fun_tuple(). {#Fun<test.2.107738983>,#Fun<test.3.107738983>}
Explanation: The string representations differ because the funs come from different fun expressions.
> {fun() -> 1 end, fun() -> 1 end}. > {#Fun<erl_eval.45.97283095>,#Fun<erl_eval.45.97283095>}
Explanation: All funs created from fun expressions of this form in
uncompiled code with the same arity are mapped to the same list by
Returns
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.
Improper use can seriously degrade system performance.
The same as
Garbage collects the node local process identified by
If
Notice that the same caveats apply as for
Failures:
Returns the process dictionary as a list of
> put(key1, merry), put(key2, lambs), put(key3, {are, playing}), get(). [{key1,merry},{key2,lambs},{key3,{are,playing}}]
Returns the value
> put(key1, merry), put(key2, lambs), put({any, [valid, term]}, {are, playing}), get({any, [valid, term]}). {are,playing}
Returns the magic cookie of the local node if the node is
alive, otherwise the atom
Returns the magic cookie for node
Returns a list of all keys present in the process dictionary. The items in the returned list can be in any order. Example:
> put(dog, {animal,1}), put(cow, {animal,2}), put(lamb, {animal,3}), get_keys(). [dog,cow,lamb]
Returns a list of keys that are associated with the value
> 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]
Returns the process identifier of the group leader for the process evaluating the function.
Every process is a member of some process group and all
groups have a group leader. 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,
Sets the group leader of
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.
Setting the group leader follows the signal ordering guarantees
described in the
See also
For some important information about distributed signals, see the
The same as calling
> halt(). os_prompt%
The same as calling
> halt(17). os_prompt% echo $? 17 os_prompt%
The same as calling
The same as calling
Halt the runtime system with status code
On many platforms, the OS supports only status codes 0-255. A too large status code is truncated by clearing the high bits.
Currently the following options are valid:
If
Flush all outstanding output.
Send all Erlang ports exit signals and wait for them to exit.
Wait for all async threads to complete all outstanding async jobs.
Call all installed
Wait for all ongoing
Call all installed
If
Runtime systems prior to OTP @OTP-17771@ called all installed
Halt the Erlang runtime system by aborting and produce a core dump if core dumping has been enabled in the environment that the runtime system is executing in.
The
Halt the Erlang runtime system and generate an
The
Behavior changes compared to earlier versions:
Before OTP 24.2, the slogan was truncated if
Before OTP 20.1, only code points in the range 0-255 were accepted in the slogan. Now any Unicode string is valid.
Returns the head of
It works with improper lists.
Examples:
> hd([1,2,3,4,5]). 1
> hd([first, second, third, so_on | improper_end]). first
Allowed in guard tests.
Failure:
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.
The process is awaken when a message is sent to it, and control
resumes in
If the process has any message in its message queue, the process is awakened immediately in the same way as described earlier.
In more technical terms,
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.
Notice that emptying the call stack means that any surrounding
Returns a new tuple with element
> erlang:insert_element(2, {one, two, three}, new). {one,new,two,three}
Returns a binary corresponding to the text
representation of
> integer_to_binary(77). <<"77">>
Returns a binary corresponding to the text
representation of
> integer_to_binary(1023, 16). <<"3FF">>
Returns a string corresponding to the text
representation of
> integer_to_list(77). "77"
Returns a string corresponding to the text
representation of
> integer_to_list(1023, 16). "3FF"
Returns an integer, that is the size in bytes,
of the binary that would be the result of
> iolist_size([1,2|<<3,4>>]). 4
Returns a binary that is made from the integers and
binaries in
> 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>>
Returns an
> 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,...>>]
Returns
A node
can also be alive if it has got a name from a call to
Returns
Allowed in guard tests.
Returns
A binary always contains a complete number of bytes.
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
This BIF is useful for builders of cross-reference tools.
Returns
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
The call fails with a
Example:
> Map = #{"42" => value}.
#{"42" => value}
> is_map_key("42",Map).
true
> is_map_key(value,Map).
false
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
If process
exit(P2Pid, kill), % P2 might not be killed is_process_alive(P2Pid), % P2 is not alive (the call above always return false)
See the documentation about
Returns
Normally the compiler treats calls to
Allowed in guard tests, if
Returns
Allowed in guard tests if
This BIF is documented for completeness. Usually
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns the length of
> length([1,2,3,4,5,6,7,8,9]). 9
Allowed in guard tests.
Sets up and activates a link between the calling process and
another process or a port identified by
If one of the participants of a link terminates, it will
An existing link can be removed by calling
For historical reasons,
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
For some important information about distributed signals, see the
Failure:
Returns the atom whose text representation is
As from Erlang/OTP 20,
The number of characters that are permitted in an atom
name is limited. The default limits can be found in the
There is configurable limit on how many atoms that can
exist and atoms are not garbage collected. Therefore, it is
recommended to consider if
Example:
> list_to_atom("Erlang"). 'Erlang'
Returns a binary that is made from the integers and
binaries in
> 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>>
Returns a bitstring that is made from the integers and
bitstrings in
> 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>>
Returns the atom whose text representation is
Failure:
Note that the compiler may optimize away atoms. For
example, the compiler will rewrite
Returns the float whose text representation is
> list_to_float("2.2017764e+0"). 2.2017764
The float string format is the same as the format for
Failure:
Returns an integer whose text representation is
> list_to_integer("123"). 123
> list_to_integer("-123"). -123
> list_to_integer("+123234982304982309482093833234234"). 123234982304982309482093833234234
Failure:
Returns an integer whose text representation in base
> list_to_integer("3FF", 16). 1023
> list_to_integer("+3FF", 16). 1023
> list_to_integer("3ff", 16). 1023
> list_to_integer("3fF", 16). 1023
> list_to_integer("-3FF", 16). -1023
For example, when
Failure:
Returns a process identifier whose text representation is a
> list_to_pid("<0.4.1>"). <0.4.1>
Failure:
This BIF is intended for debugging and is not to be used in application programs.
Returns a port identifier whose text representation is a
> list_to_port("#Port<0.4>"). #Port<0.4>
Failure:
This BIF is intended for debugging and is not to be used in application programs.
Returns a reference whose text representation is a
> list_to_ref("#Ref<0.4192537678.4073193475.71181>"). #Ref<0.4192537678.4073193475.71181>
Failure:
This BIF is intended for debugging and is not to be used in application programs.
Returns a tuple corresponding to
> list_to_tuple([share, ['Ericsson_B', 163]]). {share, ['Ericsson_B', 163]}
If
Returns either
This BIF is intended for the code server (see
Loads and links a dynamic library containing native
implemented functions (NIFs) for a module.
The call to
If the
Returns a list of all loaded Erlang modules (current and old code), including preloaded modules.
See also
Returns the current local date and time,
> erlang:localtime(). {{1996,11,6},{14,45,17}}
The time zone and Daylight Saving Time correction depend on
the underlying OS. The return value is based on the
Converts local date and time to Universal Time Coordinated
(UTC), if supported by the underlying OS. Otherwise
no conversion is done and
> erlang:localtime_to_universaltime({{1996,11,6},{14,45,17}}). {{1996,11,6},{13,45,17}}
Failure:
Converts local date and time to Universal Time Coordinated
(UTC) as
If
Examples:
> 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}}
Failure:
Returns a
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.
Creates a new tuple of the specified
> erlang:make_tuple(4, []). {[],[],[],[]}
Creates a tuple of size
> erlang:make_tuple(5, [], [{2,ignored},{5,zz},{2,aa}]). {[],aa,[],[],zz}
Returns value
The call fails with a
Example:
> Key = 1337,
Map = #{42 => value_two,1337 => "value one","a" => 1},
map_get(Key,Map).
"value one"
Allowed in guard tests.
Returns an integer, which is the number of key-value pairs
in
> map_size(#{a=>1, b=>2, c=>3}). 3
Allowed in guard tests.
Tests a match specification used in calls to
If
If
This is a useful debugging and test tool, especially when writing complicated match specifications.
See also
Returns the largest of
The
Examples:
> max(1, 2). 2
> max(1.0, 1). 1.0
> max(1, 1.0). 1
> max("abc", "b"). "b"
Allowed in guard tests.
Allowed in guards tests from Erlang/OTP 26.
Computes an MD5 message digest from
For more information about MD5, see
The MD5 Message-Digest Algorithm is not considered safe for code-signing or software-integrity purposes.
Finishes the update of an MD5
Creates an MD5 context, to be used in the following calls to
Update an MD5
Returns a list with information about memory
dynamically allocated by the Erlang emulator. Each list
element is a tuple
Memory types:
The total amount of memory currently allocated. This is
the same as the sum of the memory size for
The total amount of memory currently allocated for the Erlang processes.
The total amount of memory currently used by the Erlang
processes. This is part of the memory presented as
The total amount of memory currently allocated for
the emulator that is not directly related to any Erlang
process. Memory presented as
The total amount of memory currently allocated for atoms.
This memory is part of the memory presented as
The total amount of memory currently used for atoms.
This memory is part of the memory presented as
The total amount of memory currently allocated for
binaries. This memory is part of the memory presented
as
The total amount of memory currently allocated for
Erlang code. This memory is part of the memory presented
as
The total amount of memory currently allocated for ETS
tables. This memory is part of the memory presented as
The maximum total amount of memory allocated since the emulator was started. This tuple is only present when the emulator is run with instrumentation.
For information on how to run the emulator with
instrumentation, see
The
When the emulator is run with instrumentation,
the
As the
The different amounts of memory that are summed are not gathered atomically, which introduces an error in the result.
The different values have the following relation to each other. Values beginning with an uppercase letter is not part of the result.
total = processes + system
processes = processes_used + ProcessesNotUsed
system = atom + binary + code + ets + OtherSystem
atom = atom_used + AtomNotUsed
RealTotal = processes + RealSystem
RealSystem = system + MissedSystem
More tuples in the returned list can be added in a future release.
The
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.
As from ERTS 5.6.4,
Failure:
Returns the memory size in bytes allocated for memory of type
As from ERTS 5.6.4,
Failures:
See also
Returns the smallest of
The
Examples:
> min(1, 2). 1
> min(1.0, 1). 1.0
> min(1, 1.0). 1
> min("abc", "b"). "abc"
Allowed in guard tests.
Allowed in guards tests from Erlang/OTP 26.
Returns
{Tag, MonitorRef , Type , Object, Info}
The monitor request is an asynchronous signal. That is, it takes time before the signal reaches its destination.
A
A
When a
{'DOWN', MonitorRef, Type, Object, Info}
In the monitor message
The monitored entity, which triggered the event. When monitoring
a process or a local port,
Either the exit reason of the process,
Creates monitor between the current process and another
process identified by
Before ERTS 10.0 (OTP 21.0), monitoring a process could fail with
Now, such a call to
Creates monitor between the current process and a port
identified by
Monitors changes in
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
If the runtime system is in
The monitor is not automatically removed after it has been triggered. That is, repeated changes of the time offset trigger the monitor repeatedly.
When the monitor is triggered a
{'CHANGE', MonitorRef, Type, Item, NewTimeOffset}
where
When the
Making several calls to
The monitor functionality is expected to be extended. That is,
other
If or when
For some important information about distributed signals, see the
Provides an option list for modification of monitoring
functionality provided by
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
Only an explicit call to
The alias will be automatically deactivated when
the monitor is removed. This either via an explicit
call to
The alias will be automatically deactivated when
the monitor is removed (see
Example:
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.
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.
For more information on process aliases see the
Replace the default
An example of how the
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]).
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.
Monitor the status of the node
Making several calls to
If
The delivery of the
Nodes connected through hidden connections can be monitored as any other nodes.
Failure:
Behaves as
Option
Failure:
Returns the current
This is a
Different runtime system instances will use different unspecified
points in time as base for their Erlang monotonic clocks.
That is, it is pointless 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
Returns the current
Same as calling
Works exactly like
Works exactly like
Returns the name of the local node. If the node is not alive,
Allowed in guard tests.
Returns the node where
Allowed in guard tests.
Returns a list of all nodes connected to this node through
normal connections (that is,
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.
Nodes connected to this node through normal connections.
Nodes connected to this node through hidden connections.
All nodes connected to this node.
This node.
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
Some equalities:
Returns a list of
If the value of the association equals
If the value of the association equals
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
The node is connected to the node of the calling process
through a hidden connection. That is, the node
name would not appear in the result returned by
This is the node of the calling process.
The node is not connected but known to the node of the calling process.
Example:
(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>
This function is deprecated. Do not use it.
For more information, see section
Returns the tuple
Can only be used to check the local time of day if the time-zone information of the underlying OS is properly configured.
Returns a port identifier as the result of opening a new Erlang port. A port can be seen as an external Erlang process.
The name of the executable as well as the arguments
specified in
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.
Starts an external program.
For external programs,
Works like
Works like
The shell is usually not invoked to start the
program, it is executed directly.
Only if a shell script or
If
Allows an Erlang process to access any currently opened
file descriptors used by Erlang. The file descriptor
Messages are preceded by their length, sent in
Output messages are sent without packet lengths. A user-defined protocol must be used between the Erlang process and the external object.
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
The
Only valid for
Types:
Only valid for
For information about encoding requirements, see documentation
of the types for
Only valid for
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
The executable name (also known as
If you explicitly want to set the
program name in the argument vector, option
Only valid for
Only valid for
When the external process connected to the port exits, a
message of the form
If option
If the port program closes its
Only valid for
The opposite of
Affects ports to external programs. The executed program
gets its standard error file redirected to its standard
output file.
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
The port can only be used for input.
The port can only be used for output.
All I/O from the port is binary data objects as opposed to lists of bytes.
The port is not closed at the end of the file and does not
produce an exit signal. Instead, it remains open and
a
When running on Windows, suppresses creation of a new console window when spawning the port program. (This option has no effect on other platforms.)
Sets scheduler hint for port parallelism. If set to
Sets limits that will be used for controlling the busy state of the port.
When the ports internal output queue size becomes
larger than or equal to
The
The defaults are
Note that this option is only valid when
spawning an executable (port program) by opening the
spawn driver and when opening the
Sets limits that will be used for controlling the busy state of the port message queue.
When the ports message queue size becomes larger
than or equal to
The
Note that if the driver statically has
disabled the use of this feature, a failure with a
The defaults are
Note that the driver might fail if it also adjust these limits by itself and you have disabled this feature.
The spawn driver (used when spawning an executable)
and the
For more information see the documentation
Default is
Failure: if the port cannot be opened, the exit reason is
During use of a port opened using
The maximum number of ports that can be open at the same
time can be configured by passing command-line flag
This function is deprecated as
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
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
This BIF is always to be used for hashing terms. It
distributes small integers better than
Notice that the range
Returns a string corresponding to the text
representation of
> erlang:pid_to_list(self()). "<0.85.0>"
The
Performs a synchronous call to a port. The meaning of
Returns a term from the driver. The meaning of the returned data also depends on the port driver.
Failures:
If the port driver so decides for any reason (probably
something wrong with
Do not call
Closes an open port. Roughly the same as
For comparison:
Notice that any process can close a port using
As from Erlang/OTP R16,
Failure:
Sends data to a port. Same as
For comparison:
Notice that any process can send to a port using
If the port is busy, the calling process is suspended until the port is not busy any more.
As from Erlang/OTP R16,
Failures:
If
If
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.
Sends data to a port.
If the port command is aborted,
If the port is busy, the calling process is suspended until the port is not busy anymore.
More options can be added in a future release.
Failures:
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.
Sets the port owner (the connected port) to
The error behavior differs, see below.
The port does not reply with
The new port owner gets linked to the port.
The old port owner stays linked to the port and must call
For comparison:
Notice that any process can set the port owner using
As from Erlang/OTP R16,
Failures:
Performs a synchronous control operation on a port.
The meaning of
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.
Failures:
Do not call
Returns a list containing tuples with information about
The result contains information about the following
For more information about the different
Failure:
If the port identified by
Failure:
If the port identified by
Failure:
If the port identified by
Failure:
If the port identified by
Failure:
Notice that these results are highly implementation-specific and can change in a future release.
If the port identified by
Failure:
If the port identified by
Failure:
If the port identified by
Failure:
Returns list of pids that are monitoring given port at the moment.
If the port identified by
Failure:
If the port identified by
Failure:
If the port identified by
Failure:
If the port identified by
Failure:
If the port identified by
Failure:
If the port identified by
Failure:
Returns a string corresponding to the text
representation of the port identifier
Returns a list of port identifiers corresponding to all the ports existing on the local node.
Notice that an exiting port exists, but is not open.
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
Writes information about the local process
Enable or disable fully asynchronous distributed signaling
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
Since no flow control is enforced by the runtime system when
Blocking due to disabled
The
You can inspect the state of the
Returns the old value of the
When
Returns the old value of the flag.
See also
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.
Returns the old value of the flag.
Changes the maximum number of generational collections before forcing a fullsweep for the calling process.
Returns the old value of the flag.
Changes the minimum heap size for the calling process.
Returns the old value of the flag.
Changes the minimum binary virtual heap size for the calling process.
Returns the old value of the flag.
This flag sets the maximum heap size for the calling process.
If
For details on how the heap grows, see
The maximum size in words of the process. If set to zero, the
heap size limit is disabled.
When set to
If
When set to
If
When set to
If
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
Determines how messages in the message queue are stored, as follows:
All messages in the message queue will be stored outside the process heap. This implies that no messages in the message queue will be part of a garbage collection of the process.
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.
The default value of the
If the process may potentially accumulate a large number of messages
in its queue it is recommended to set the flag value to
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.
Returns the old value of the flag.
Sets the process priority.
Priority level
Internally in each priority level, processes are scheduled in a round robin fashion.
Execution of processes on priority
When runnable processes on priority
When runnable processes on priority
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.
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.
There is no 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.
Making calls from a
Other priorities than
Returns the old value of the flag.
A tuple
The atoms
If
Returns the old value of the flag.
Sets or clears flag
Features that are disabled include (but are not limited to) the following:
Tracing. Trace flags can still be set for the process,
but no trace messages of any kind are generated. (If flag
Sequential tracing. The sequential trace token is propagated as usual, but no sequential trace messages are generated.
Stack back-traces cannot be displayed for the process.
In crash dumps, the stack, messages, and the process dictionary are omitted.
If
Returns the old value of the flag.
Sets certain flags for the process
Failure:
Returns a list containing
The order of the
The
If the process identified by
For information about specific
This BIF is intended for debugging only. For
all other purposes, use
Failure:
Returns information about the process identified by
If the process is alive and a single
If
Getting process information follows the signal ordering guarantees
described in the
If
Valid
Since: OTP 25.3
Current value of the
Binary
Depending on the value of the
Returns the current call stack back-trace
(stacktrace) of the process. The stack has the
same format as in the
The value is
A list of identifiers for all the processes, ports and NIF resources, that are monitoring the process.
A list of monitors (started by
If
If
Notice that
Notice that not all implementations support all
these
Failures:
Returns a list of process identifiers corresponding to all the processes currently existing on the local node.
Notice that an exiting process exists, but is not alive.
That is,
Example:
> processes(). [<0.0.0>,<0.2.0>,<0.4.0>,<0.5.0>,<0.7.0>,<0.8.0>]
Removes old code for
This BIF is intended for the code server (see
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.
Failure:
Adds a new
> X = put(name, walrus), Y = put(name, carpenter), Z = get(name), {X, Y, Z}. {undefined,walrus,carpenter}
The values stored when
Raises an exception of the specified class, reason, and call stack backtrace (stacktrace).
try ... catch Class:Reason:Stacktrace -> ... end
That is, a list of
four-tuples
Element
The stacktrace is used as the exception stacktrace for the calling process; it is truncated to the current maximum stacktrace depth.
As evaluating this function causes the process to
terminate, it has no return value unless the arguments are
invalid, in which case the function returns the error
reason
See the reference manual about
Reads the state of a timer. The same as calling
Reads the state of a timer that has been created by either
Asynchronous request for state information.
More
If
If
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
See also
Returns a string corresponding to the text
representation of
This BIF is intended for debugging and is not to be used in application programs.
Registers the name
> register(db, Pid). true
The registered name is considered a
Failures:
Returns a list of names that have been registered using
> registered(). [code_server, file_server, init, user, my_db]
Decreases the suspend count on the process identified by
This BIF is intended for debugging only.
Failures:
Returns an integer by rounding
round(42.1). 42
round(5.5). 6
round(-5.5). -6
round(36028797018963969.0). 36028797018963968
In the last example,
Allowed in guard tests.
Returns the process identifier of the calling process, for example:
> self(). <0.26.0>
Allowed in guard tests.
Sends a message and returns
The function fails with a
For some important information about distributed signals, see the
Either sends a message and returns
Options:
For some important information about distributed signals, see the
As with
Starts a timer. The same as calling
Starts a timer. When the timer expires, the message
The same as
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 does not send the message
and returns
The same occurs if
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
Notice that ignoring the return value from this function would
result in an unreliable message passing, which is
contradictory to the Erlang programming model. The message is
not sent if this function returns
In many systems, transient states of
overloaded queues are normal. Although this function
returns
Use with extreme care.
The same as
This function behaves like
Whenever the function returns
Use with extreme care.
Sets the magic cookie of the local node to the atom
You can get this value using
Failure:
Sets the magic cookie for
You can get this value using
Failure:
Returns a tuple that is a copy of argument
> setelement(2, {10, green, bottles}, red). {10,red,bottles}
Returns the number of elements in a tuple or the number of bytes in a binary or bitstring, for example:
> size({morni, mulle, bwange}). 3 > size(<<11, 22, 33>>). 3
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 down.
Allowed in guard tests.
See also
Returns the process identifier of a new process started by the
application of
Returns the process identifier of a new process started
by the application of
Returns the process identifier of a new process started by
the application of
Example:
> spawn(speed, regulator, [high_speed, thin_cut]). <0.13.1>
Returns the process identifier (pid) of a new process started
by the application
of
Returns the process identifier of a new process started by
the application of
Returns the process identifier (pid) of a new process started
by the application of
Returns the process identifier of a new process started by
the application of
Returns the process identifier (pid) of a new process
started by the application
of
Returns the process identifier of a new process, started by
the application of
Returns the process identifier of a new process, started by
the application of
If the node identified by
A new process is started by the application
of
A new process is started by the application
of
If the node identified by
Returns the process identifier (pid) of a new process
started by the application of
If option
Returns the process identifier (pid) of a new process started
by the application of
Valid options depends on what options are
supported by the node identified by
Works as
If option
Options:
Sets a link to the parent process (like
Monitors the new process (like
Monitors the new process with options (like
Sets the priority of the new process. Equivalent to
executing
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.
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.
Option
A few cases when it can be useful to change
If binaries that are no longer used are to be
thrown away as soon as possible. (Set
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
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.
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
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.
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
Sets the
Sets the value of the
Since: OTP 25.3
Set the
Returns the process identifier (pid) of a new process started
by the application
of
Valid options depends on what options are
supported by the node identified by
The same as the call
The same as the call
The same as the call
The same as
This function will fail with a
The same as the call
The same as the call
The same as the call
Asynchronously send a spawn request. Returns a request
identifier
If the spawn operation succeeds, a new process is
created on the node identified by
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
An invalid
The node identified by
Failure to set up a connection to the node
identified by
Could not create a new process due to that some system limit was reached. Typically the process table was full.
Valid
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
The monitor will not be activated for the calling
process until the spawn operation has succeeded.
The monitor can not be
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
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
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.
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
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
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
Valid
A spawn reply message will be sent to the caller
regardless of whether the operation succeeds or
not. If the call to
No spawn reply message will be sent to the caller when the spawn operation completes. This regardless of whether the operation succeeds or not.
No spawn reply message will be sent to the caller
if the spawn operation succeeds, but an
No spawn reply message will be sent to the caller
if the spawn operation fails, but a
Sets the reply tag to
Other valid options depends on what options are
supported by the node identified by
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.
This function will fail with a
Note that not all individual
A spawn request can be abandoned by calling
For some important information about distributed signals, see the
Abandon a previously issued spawn request.
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
A process created due to a spawn request that has been abandoned may communicate with its parent as any other process. It is only the direct effects on the parent of the actual spawn request, that will be canceled by abandoning a spawn request.
Return values:
The spawn request was successfully abandoned.
No spawn request was abandoned. The
This function fail with a
Returns a tuple containing the binaries that are the result
of splitting
> 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
Starts a timer. The same as calling
Starts a timer. When the timer expires, the message
This is the default. It means the
Absolute
More
The absolute point in time, the timer is set to expire on,
must be in the interval
If
If
See also
Failure:
Returns the same as
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 not gathered atomically. That is, the result is not necessarily a consistent snapshot of the state, but instead quite efficiently gathered.
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 not 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.
See also
Returns the total number of context switches since the system started.
Returns the number of exact reductions.
Returns information about garbage collection, for example:
> statistics(garbage_collection). {85,23961,0}
This information can be invalid for some implementations.
Returns
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
Example:
> erlang:statistics(microstate_accounting). [#{counters => #{aux => 1899182914, check_io => 2605863602, emulator => 45731880463, gc => 1512206910, other => 5421338456, port => 221631, sleep => 5150294100}, id => 1, type => scheduler}|...]
The time unit is the same as returned by
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)).
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.
The following
More fine-grained
The utility module
Returns
The list of thread information is unsorted and can appear in different order between calls.
The threads and states are subject to change without any prior notice.
Returns information about reductions, for example:
> statistics(reductions). {2046,11}
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
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
Returns the same as
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 not gathered atomically. That is, the result is not necessarily a consistent snapshot of the state, but instead quite efficiently gathered.
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 not 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.
See also
Returns information about runtime, in milliseconds.
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.
This value might wrap due to limitations in the underlying functionality provided by the operating system that is used.
Example:
> statistics(runtime). {1690,1620}
Returns information describing how much time
The definition of a busy scheduler is when it is not idle
and not
Notice that a scheduler can also be busy even if the OS has scheduled out the scheduler thread.
It is recommended to use the module
If
The
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
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
Normal schedulers will have scheduler identifiers in
the range
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.
You can use
> erlang:system_flag(scheduler_wall_time, true). false > Ts0 = lists:sort(erlang:statistics(scheduler_wall_time)), ok. ok
Some time later the user takes another snapshot and calculates scheduler utilization per scheduler, for example:
> 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}]
Using the same snapshots to calculate a total scheduler utilization:
> {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
Total scheduler utilization will equal
Another (probably more) useful value is to calculate total scheduler utilization weighted against maximum amount of available CPU time:
> WeightedSchedulerUtilization = (TotalSchedulerUtilization * (erlang:system_info(schedulers) + erlang:system_info(dirty_cpu_schedulers))) / erlang:system_info(logical_processors_available). 0.9769136803764825
This weighted scheduler utilization will reach
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.
The same as
Dirty IO schedulers will have scheduler identifiers in
the range
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 not expected to be high due to this work.
The same as calling
The same as calling
The same as calling
The same as calling
Returns information about wall clock.
Suspends the process identified by
This BIF is intended for debugging only.
Increases the suspend count on the process identified by
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
Options (
A suspend request is sent to the process identified by
A suspend request is sent to the process identified by
Apart from the reply message, the
The process identified by
If the suspend count on the process identified by
This BIF is intended for debugging only.
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.
Failures:
Sets the maximum depth of call stack back-traces in the
exit reason element of
Returns the old value of the flag.
This argument is deprecated.
Instead of using this argument, use command-line argument
When this argument is removed, a final CPU topology to use is determined at emulator boot time.
Sets the user-defined
Returns the old value of the flag.
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.
The user-defined CPU topology can also be set by passing
command-line argument
For information on type
Sets the number of dirty CPU schedulers online. Range is
Returns the old value of the flag.
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
For more information, see
Sets system flags for
Only a subset of all
Returns
Sets system flag
Returns the old value of the flag.
In low-memory systems (especially without virtual
memory), setting the value to
This value can also be set through (OS)
environment variable
Turns on/off microstate accounting measurements. When passing reset, all counters are reset to 0.
For more information see
Sets the default minimum heap size for processes. The size
is specified in words. The new
Returns the old value of the flag.
Sets the default minimum binary virtual heap size for
processes. The size is specified in words.
The new
Returns the old value of the flag.
Sets the default maximum heap size settings for processes.
The size is specified in words. The new
Returns the old value of the flag.
For details on how the heap grows, see
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 normal schedulers but one is blocked. When only normal schedulers are blocked, dirty schedulers are free to continue to schedule processes.
If
If
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.
The return values are
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 very inefficient way to solve the problem.
See also
Sets a limit on the amount of outstanding requests made by a system process orchestrating system wide changes. Currently there are two such processes:
The code purger orchestrates checking of references to old code before old code is removed from the system.
The literal area collector orchestrates copying of references from old literal areas before removal of such areas from the system.
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
This limit can also be set by passing the command line argument
This argument is deprecated.
Instead of using this argument, use command-line argument
Controls if and how schedulers are bound to logical processors.
When
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
Schedulers can be bound on newer Linux, Solaris, FreeBSD, and Windows systems, but more systems will be supported in future releases.
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
The runtime system does by default not bind schedulers to logical processors.
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.
Schedulers can be bound in different ways. Argument
The returned value equals
Failures:
The scheduler bind type can also be set by passing command-line
argument
For more information, see
Try enable or disable scheduler wall time measurements by passing
For more information about how to use scheduler wall time
measurements, see
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
Returns the old value of the node global state,
Scheduler wall time measurements do consume some cpu overhead and should not be left turned on unless used.
Sets the number of schedulers online. Range is
Returns the old value of the flag.
If the emulator was built with support for
For more information, see
Sets the process that will receive the logging
messages generated by ERTS. If set to
{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() }
If the
The default is the process named
Returns the old value of the flag.
This function is designed to be used by the
KERNEL
Sets the value of the node trace control word to
Returns the old value of the flag.
Finalizes the
Returns the old state identifier, that is:
If
If
If
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.
Returns various information about the memory allocators
of the current system (emulator) as specified by
Returns a list of tuples with information about miscellaneous allocated memory areas.
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.
Notice that the sum of these values is not
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
Returns
See also "System Flags Effecting erts_alloc" in
Returns information about the specified allocator.
As from ERTS 5.6.1, the return value is a list
of
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.
The recognized allocators are listed in
After reading the
If only one value is present, it is the current value.
Returns a list of the names of all allocators using
the ERTS internal
Returns various size information for the specified
allocator. The information returned is a subset of the
information returned by
Returns various information about the CPU topology of
the current system (emulator) as specified by
Returns the
A level in term
Returns the user-defined
Returns the automatically detected
For more information, see argument
Returns
Returns the detected number of logical processors configured
in the system. The return value is either an integer, or
the atom
Returns the detected number of logical processors available
to the Erlang runtime system. The return value is either an
integer, or the atom
Returns the detected number of logical processors online on
the system. The return value is either an integer,
or the atom
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
The runtime system rereads the CPU information available
and updates its internally stored information about the
If the CPU information has changed since the last time
it was read, the atom
Returns information about the default process heap settings:
Returns
Returns a list describing the default garbage collection
settings. A process spawned on the local node by a
Returns a list of integers representing valid heap sizes in words. All Erlang heaps are sized from sizes in this list.
Returns the heap type used by the current emulator. One heap type exists:
Returns
Returns the default value of the
Returns
Returns
Returns a binary containing a string of process and port
information formatted as in Erlang crash dumps. For more
information, see section
Returns information about the current system
(emulator) limits as specified by
Returns the number of atoms currently existing at the local node. The value is given as an integer.
Returns the maximum number of atoms allowed.
This limit can be increased at startup by passing
command-line flag
Returns the number of ETS tables currently existing at the local node.
Returns the limit for number of ETS tables. This limit is
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
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
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
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
Returns information about the current system
(emulator) time as specified by
The last
Returns a list containing information about the source of
If
This tuple only exists if
Highest possible
Returns a list containing information about the source of
The list contains two-tuples with
Exists only if
Highest possible
The
See also
Returns a boolean value indicating whether
Returns the state of the time offset:
The time offset is preliminary, and will be changed
and finalized later. The preliminary time offset
is used during the preliminary phase of the
The time offset is final. This either because
The time offset is volatile. That is, it can
change at any time. This is because
Returns a value identifying the
Returns whether a pre ERTS 7.0 backwards compatible
compensation for sudden changes of system time is
Returns information about schedulers, scheduling and threads in the
current system as specified by
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.
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
See also
Returns the number of dirty CPU schedulers online.
The return value satisfies
The number of dirty CPU schedulers online can be set at
startup by passing command-line flag
For more information, see
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.
This value can be set at startup by passing command-line
argument
For more information, see
Returns one of the following:
The emulator has been started with only one scheduler thread.
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.
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.
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.
See also
Returns a list of
See also
Returns a list of
See also
Returns information about how the user has requested schedulers to be bound or not bound.
Notice that although a user has requested
schedulers to be bound, they can silently have failed
to bind. To inspect the scheduler bindings, call
For more information, see command-line argument
Returns information about the currently used scheduler bindings.
A tuple of a size equal to
Notice that only schedulers online can be bound to logical processors.
For more information, see command-line argument
Returns the scheduler ID (
See also
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.
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.
See also
Returns the number of schedulers online. The scheduler
identifiers of schedulers online satisfy the relationship
For more information, see
Returns
Returns
Returns the number of async threads in the async thread
pool used for asynchronous driver calls
(
Returns information about Erlang Distribution in the
current system as specified by
Since: OTP 25.3
Returns the value of the command line argument
Returns the "creation" value 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 possible to distinguish
between identifiers from different incarnations of a node.
Creation values are currently 32-bit positive integers, but this
may change in future releases. If the node is not
alive,
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
Returns a binary containing a string of distribution
information formatted as in Erlang crash dumps. For more
information, see section
Returns the value of the distribution buffer busy limit
in bytes. This limit can be set at startup by passing
command-line flag
Returns a list of tuples
Returns various information about the current system
(emulator) as specified by
Deprecated, use
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
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.
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
Returns
Returns a string containing the Erlang driver version
used by the runtime system. It has the form
Returns an atom describing the dynamic trace framework
compiled into the virtual machine. It can be
Returns a
Returns an atom describing the flavor of the runtime system.
This will be either
Returns an atom describing the build type of the runtime
system. This is normally the atom
Returns a binary containing a string of miscellaneous
system information formatted as in Erlang crash dumps.
For more information, see section
Returns
Returns a binary containing a string of loaded module
information formatted as in Erlang crash dumps. For more
information, see section
Returns a string containing the Erlang machine name.
Returns the modified timing-level (an integer) if
modified timing is enabled, otherwise
Returns a string containing the version of the Erlang NIF interface used by the runtime system. It is on the form "<major ver>.<minor ver>".
Returns a string containing the OTP release number of the OTP release that the currently executing ERTS application is part of.
As from Erlang/OTP 17, the OTP release number corresponds to
the major OTP version number. No
Returns the limit on the amount of outstanding requests
made by a system process orchestrating system wide changes.
See
Returns the default port parallelism scheduling hint used.
For more information, see command-line argument
Returns a string containing the processor and OS architecture the emulator is built for.
Returns the current
Returns a string containing version number and some important properties, such as the number of schedulers.
Returns the value of the node trace control word. For
more information, see function
Returns a string containing the version number of the emulator.
Same as
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.
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.
Returns the current system monitoring settings set by
When called with argument
Calling the function with
Returns the previous system monitor settings just like
Sets the system performance monitoring options.
If a garbage collection in the system takes at least
One of the tuples is
If a process or port in the system runs uninterrupted
for at least
If a
If a
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.
If a garbage collection in the system results in
the allocated size of a heap being at least
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
When a process is killed by
If a process in the system gets suspended because it
sends to a busy port, a message
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
Returns the previous system monitor settings just like
The arguments to
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
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.
Keep the monitoring process neat and do not set the system monitor limits too tight.
Failures:
Returns the current system profiling settings set by
Sets system profiler options.
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
Time stamps in profile messages use
If a process is put into or removed from the run queue, a
message,
If a port is put into or removed from the run queue, a
message,
If a scheduler is put to sleep or awoken, a message,
Time stamps in profile messages consist of
Time stamps in profile messages include a
time stamp (Ts) that has the same form as returned by
Returns current
Calling
This time is not a monotonically increasing time
in the general case. For more information, see the documentation of
Returns current
Calling
This time is not a monotonically increasing time
in the general case. For more information, see the documentation of
Returns a binary data object that is the result of encoding
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.
> Bin = term_to_binary(hello). <<131,100,0,5,104,101,108,108,111>> > hello = binary_to_term(Bin). hello
See also
There is no guarantee that this function will return the same encoded representation for the same term.
Returns a binary data object that is the result of encoding
Currently supported options:
Compress the external term format. The compressed
format is automatically recognized by
Compress the external term format to a given level.
The compression level is specified by
No compression is done (it is the same as giving no
Takes least time but may not compress as well as the higher levels.
Default level when option
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.
The option can be used to control some encoding details. Valid
values for
Floats are encoded using a textual representation.
Atoms that can be represented by a latin1 string are encoded using latin1 while only atoms that cannot be represented by latin1 are encoded using utf8.
Floats are 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,
Atoms that can be represented by a latin1 string are encoded using latin1 while only atoms that cannot be represented by latin1 are encoded using utf8.
This is as of Erlang/OTP 26.0 the default. Atoms are unconditionally encoded using utf8. Erlang/OTP systems as of R16B can decode this representation.
This option 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.
This option cannot be combined with the
This option will cause encoding of
Node name and creation of a runtime system instance change
when the distribution is started or stopped. The distribution is
started when the runtime system is started using the
The decoding of a term encoded with the
Since it is only the runtime system that encoded a term using
the
A good example of when you want to use the
This option cannot be combined with the
For more information see the
See also
Returns the encoding of
This function produce the same encoding as
See also
Returns the encoding of
This function produce the same encoding as
Currently recognised options are all options recognised by
See also
Raises an exception of class
If evaluated within a
> catch throw({hello, there}). {hello,there}
If evaluated within a
try
throw({my_exception, "Something happened"})
catch
throw:{my_exception, Desc} ->
io:format(standard_error, "Error: ~s~n", [Desc])
end
Failure:
See the guide about
Returns the current time as
The time zone and Daylight Saving Time correction depend on
the underlying OS. The return value is based on the
> time(). {9,42,44}
Returns the current time offset between
The time offset may or may not change during operation depending
on the
A change in time offset can be observed at slightly different points in time by different processes.
If the runtime system is in
Returns the current time offset between
Same as calling
Returns current
The
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}.
It, however, uses a native implementation that does not build garbage on the heap and with slightly better performance.
This time is not a monotonically increasing time
in the general case. For more information, see the documentation of
Returns the tail of
It works with improper lists.
Examples:
> tl([geesties, guilies, beasties]). [guilies, beasties]
> tl([geesties]). []
> tl([geesties, guilies, beasties | improper_end]). [guilies, beasties | improper_end]
> tl([geesties | improper_end]). improper_end
Allowed in guard tests.
Failure:
Turns on (if
Sets all trace flags except
Traces sending of messages.
Message tags:
Traces receiving of messages.
Message tags:
Traces certain function calls. Specify which function
calls to trace by calling
Message tags:
Used with the
Silent mode is inhibited by executing
The
Message tags:
Used with the
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
To get trace messages containing return values from
functions, use the
Message tags:
Traces process-related events.
Message tags:
Traces port-related events.
Message tags:
Traces scheduling of processes.
Message tags:
Traces scheduling of exiting processes.
Message tags:
Traces scheduling of processes just like
Message tags:
Traces scheduling of ports.
Message tags:
Traces garbage collections of processes.
Message tags:
Includes a time stamp in all trace messages. The
time stamp (Ts) has the same form as returned by
A global trace flag for the Erlang node that makes all
trace time stamps using flag
Includes an
Includes an time stamp consisting of
Used with the
Makes any process created by a traced process inherit
its trace flags, including flag
Makes the first process created by a traced process
inherit its trace flags, excluding flag
Makes any process linked by a traced process inherit its
trace flags, including flag
Makes the first process linked to by a traced process
inherit its trace flags, excluding flag
Specifies where to send the trace messages.
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
If no
The effect of combining
The tracing process receives the trace messages described
in the following list.
If flag
If a match specification (applicable only for
Trace messages:
When
When
When
When
Trace flag
When
When
When
When
When
When
When
When
When
When
When
When
When
When
When
When
When
The possible commands are
When
Sent when a young garbage collection is about to be started.
All sizes are in words.
Sent when the
Sent when young garbage collection is finished.
Sent when fullsweep garbage collection is about to be started.
Sent when fullsweep garbage collection is finished.
If the tracing process/port dies or the tracer module returns
Each process can only be traced by one tracer. Therefore, attempts to trace an already traced process fail.
Returns a number indicating the number of processes that
matched
Failure:
The delivery of trace messages (generated by
When it is guaranteed that all trace messages are delivered to
the tracer up to the point that
Notice that message
Notice that
When used together with a
Example: Process
Failure:
Returns trace information about a port, process, function, or event.
To get information about a port or process,
Valid
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:
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
To get information about a function,
Valid
Returns
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
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
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
Returns the call count value for this function or
See also
Returns the call time values for this function or
See also
Returns the accumulated number of words allocated by this function.
Accumulation stops at the next memory traced function: if there
are
See also
Returns a list containing the
To get information about an event,
One valid
Returns the match specification for this event, if it
has one, or
The return value is
The same as
Sets trace pattern for message sending.
Must be combined with
Argument
A list of match specifications. The matching is done
on the list
Enables tracing for all sent messages (from
Disables tracing for all sent messages. Any match specification is removed.
Argument
The return value is always
Examples:
Only trace messages to a specific process
> erlang:trace_pattern(send, [{[Pid, '_'],[],[]}], []). 1
Only trace messages matching
> erlang:trace_pattern(send, [{['_', {reply,'_'}],[],[]}], []). 1
Only trace messages sent to the sender itself:
> erlang:trace_pattern(send, [{['$1', '_'],[{'=:=','$1',{self}}],[]}], []). 1
Only trace messages sent to other nodes:
> erlang:trace_pattern(send, [{['$1', '_'],[{'=/=',{node,'$1'},{node}}],[]}], []). 1
A match specification for
Fails by raising an error exception with an error reason of:
If an argument is invalid.
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.
Sets trace pattern for message receiving.
Must be combined with
Argument
A list of match specifications. The matching is done
on the list
Enables tracing for all received messages (to
Disables tracing for all received messages. Any match specification is removed.
Argument
The return value is always
Examples:
Only trace messages from a specific process
> erlang:trace_pattern('receive', [{['_',Pid, '_'],[],[]}], []). 1
Only trace messages matching
> erlang:trace_pattern('receive', [{['_','_', {reply,'_'}],[],[]}], []). 1
Only trace messages from other nodes:
> erlang:trace_pattern('receive', [{['$1', '_', '_'],[{'=/=','$1',{node}}],[]}], []). 1
A match specification for
Fails by raising an error exception with an error reason of:
If an argument is invalid.
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.
Enables or disables call tracing for one or more functions.
Must be combined with
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.
To add or remove one or more processes to the set of traced
processes, use
To add or remove functions to the set of traced
functions, use
The BIF
Argument
All functions of any arity named
All functions in module
All functions in all loaded modules.
Other combinations, such as
If argument
Argument
Disables tracing for the matching functions. Any match specification is removed.
Enables tracing for the matching functions. Any match specification is removed.
A list of match specifications. An empty list is
equivalent to
For the
For the
Parameter
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. This is the default.
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
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,
Meta-tracing traces all processes and does not care
about the process trace flags set by
The match specification function
Starts (
If call count tracing is started while already running,
the count is restarted from zero. To pause running
counters, use
To read the counter value, use
Starts (
If call time tracing is started while already running,
the count and time restart from zero. To pause
running counters, use
To read the counter value, use
Starts (
If call memory tracing is started while already running,
counters and allocations restart from zero. To pause
running counters, use
To read the counter value, use
The options
When disabling trace, the option must match the type of trace
set on the function. That is, local tracing must be
disabled with option
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
Returns the number of functions matching
argument
Fails by raising an error exception with an error reason of:
If an argument is invalid.
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.
Truncates the decimals of
> trunc(5.7). 5
> trunc(-5.7). -5
> trunc(5). 5
> trunc(36028797018963969.0). 36028797018963968
In the last example,
Allowed in guard tests.
Returns an integer that is the number of elements in
> tuple_size({morni, mulle, bwange}). 3
Allowed in guard tests.
Returns a list corresponding to
> tuple_to_list({share, {'Ericsson_B', 163}}). [share,{'Ericsson_B',163}]
Deactivate the alias
Returns true if
For more information on process aliases see the
Generates and returns an
Generates and returns an
By default, when
Returns only positive integers.
Notice that by passing the
Returns
These values can be used to determine order between events
on the runtime system instance. That is, if both
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
All valid
The set of integers returned by
Failures:
Returns the current date and time according to Universal
Time Coordinated (UTC) in the form
> erlang:universaltime(). {{1996,11,6},{14,18,43}}
Converts Universal Time Coordinated (UTC) date and time to
local date and time in the form
> erlang:universaltime_to_localtime({{1996,11,6},{14,18,43}}). {{1996,11,7},{15,18,43}}
Failure:
Removes a link between the calling process and another process
or a port identified by
A link can be set up using the
Once
unlink(Id),
receive
{'EXIT', Id, _} ->
true
after 0 ->
true
end
The link removal is performed asynchronously. If such a link
does not exist, nothing is done. A detailed description of the
For some important information about distributed signals, see the
Failure:
Removes the
> unregister(db). true
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.
Users are advised not to unregister system processes.
Failure:
Returns the process identifier or port identifier with
the
> whereis(db). <0.43.0>
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
See the documentation for
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.