By convention, most Built-In Functions (BIFs) are included
in this module. Some of the BIFs 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.
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".
A binary data object, structured according to the Erlang external term format.
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
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)).
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:
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 string corresponding to the text
representation of
> atom_to_list('Erlang'). "Erlang"
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.
Returns the atom whose text representation is
As from Erlang/OTP 20,
Examples:
> binary_to_atom(<<"Erlang">>, latin1). 'Erlang' > binary_to_atom(<<1024/utf8>>, utf8). 'Ѐ'
As
Failure:
Returns the float whose text representation is
> binary_to_float(<<"2.2017764e+0">>). 2.2017764
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,
consider using
See also
As
Option:
Use this option when receiving binaries from an untrusted source.
When enabled, it prevents decoding data that can be used to
attack the Erlang system. 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.
Failure:
> binary_to_term(<<131,100,0,5,104,101,108,108,111>>, [safe]). ** exception error: bad argument > hello. hello > binary_to_term(<<131,100,0,5,104,101,108,108,111>>, [safe]). hello
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
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 (2000 reductions in Erlang/OTP R12B).
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. Example:
> 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
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
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
Prints a text representation of
This BIF is intended for debugging only.
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}
Stops the execution of the calling process with the reason
> catch error(foobar). {'EXIT',{foobar,[{erl_eval,do_apply,5}, {erl_eval,expr,5}, {shell,exprs,6}, {shell,eval_exprs,6}, {shell,eval_loop,3}]}}
Stops the execution of the calling process with the reason
Stops the execution of the calling process with exit reason
> exit(foobar). ** exception exit: foobar > catch exit(foobar). {'EXIT',foobar}
Sends an exit signal with exit reason
The following behavior applies if
If
If
If
If
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">>
The same as
Returns a string corresponding to the text representation
of
Available options:
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"
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
Returns information about
For any fun,
For a local fun,
See
Returns a string corresponding to the text
representation of
Returns
This function used to return
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 a list of all keys present in the process dictionary, for 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]
Gets the call stack back-trace (stacktrace) of the
last exception in the calling process as a list of
If there has not been any exceptions in a process, the
stacktrace is
The stacktrace is the same data as operator
{'EXIT',{badarg,Stacktrace}} = catch abs(x)
See also
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
See also
The same as
> halt(). os_prompt%
The same as
> halt(17). os_prompt% echo $? 17 os_prompt%
On many platforms, the OS supports only status codes 0-255. A too large status code is truncated by clearing the high bits.
For integer
For statuses
Returns the head of
> hd([1,2,3,4,5]). 1
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
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
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
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.
Creates a link between the calling process and another
process (or port)
If
If the calling process is not trapping exits, and
checking
Otherwise, if the calling process is trapping exits,
and/or
Returns the atom whose text representation is
As from Erlang/OTP 20,
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:
Returns the float whose text representation is
> list_to_float("2.2017764e+0"). 2.2017764
Failure:
Returns an integer whose text representation is
> list_to_integer("123"). 123
Failure:
Returns an integer whose text representation in base
> list_to_integer("3FF", 16). 1023
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 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
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.
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
Known issue: 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 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
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
Only on 64-bit halfword emulator. The total amount of memory allocated in low memory areas that are restricted to < 4 GB, although the system can have more memory.
Can be removed in a future release of the halfword emulator.
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
Returns
This BIF is intended for the code server (see
Sends a monitor request of type
{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 local process or port,
Either the exit reason of the process,
If an attempt is made to monitor a process on an older node
(where remote process monitoring is not implemented or
where remote process monitoring by registered name is not
implemented), the call fails with
The format of the
Creates monitor between the current process and another
process identified by
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
Monitor the status of the node
Making several calls to
If
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 visible nodes in the system, except
the local node. Same as
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:
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
specifed 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.
When starting external programs on Solaris, the system
call
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
Only valid 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
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
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
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:
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
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:
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:
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 system. As all loading of code is done through the file
system, the file system must have been loaded previously.
Hence, at least the module
Writes information about the local process
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 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
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
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
This flag determines how messages in the message queue are stored, as follows:
All messages in the message queue will be stored outside of 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 heap. They can however temporarily be stored off heap. This is how messages always have been stored up until ERTS 8.0.
The default
If the process potentially can get many messages,
you are advised to set the flag to
When changing this flag messages will be moved. This work has been initiated but not completed when this function call returns.
Returns the old value of the flag.
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, at least on the runtime system with SMP support, 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
If
Valid
Binary
Returns the current call stack back-trace (stacktrace)
of the process. The stack has the same format as returned by
The value is
A list of process identifiers monitoring the process (with
A list of monitors (started by
Returns the current state of process flag
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
Stops the execution of the calling process with an exception of the specified class, reason, and call stack backtrace (stacktrace).
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
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.
Associates the name
> register(db, Pid). true
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(5.5). 6
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
Either sends a message and returns
Options:
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
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
A new process is started by the application
of
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
Works as
If option
Options:
Sets a link to the parent process (like
Monitors the new process (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 state of the
Returns the process identifier (pid) of a new process started
by the application
of
Option
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 a list where each element represents the amount of active processes and ports on each run queue and its associated scheduler. That is, the number of processes and ports that are ready to run, or are currently running. The element location in the list corresponds to the scheduler and its run queue. The first element corresponds to scheduler number 1 and so on. The information is not gathered atomically. That is, the result is not necessarily a consistent snapshot of the state, but instead quite efficiently gathered.
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 the run-queues. That is, the number
of processes and ports that are ready to run on all available
run-queues. 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 a list where each element represents the amount of processes and ports ready to run for each run queue. The element location in the list corresponds to the run queue of a scheduler. The first element corresponds to the run queue of scheduler number 1 and so on. The information is not gathered atomically. That is, the result is not necessarily a consistent snapshot of the state, but instead quite efficiently gathered.
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.
Example:
> statistics(runtime). {1690,1620}
Returns a list of tuples with
The definition of a busy scheduler is when it is not idle and is not scheduling (selecting) a process or port, that is:
Notice that a scheduler can also be busy even if the OS has scheduled out the scheduler thread.
Returns
The list of scheduler information is unsorted and can appear in different order between calls.
As of ERTS version 9.0, also dirty CPU schedulers will
be included in the result. That is, all scheduler threads
that are expected to handle CPU bound work. If you also
want information about dirty I/O schedulers, use
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.
Using
> 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 with SMP support 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.
Returns the total amount of active processes and ports in the system. That is, the number of processes and ports that are ready to run, or are currently running. The information is not gathered atomically. That is, the result is not necessarily a consistent snapshot of the state, but instead quite efficiently gathered.
See also
Returns the total length of the run queues. That is, the number
of processes and ports that are ready to run on all available
run queues. The information is not gathered atomically.
That is, the result is not necessarily a consistent snapshot of
the state, but much more efficiently gathered compared to
See also
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
The process identified by
If the suspend count on the process identified by
This BIF is intended for debugging only.
Failures:
Sets the maximum depth of call stack back-traces in the
exit reason element of
Returns the old value of the flag.
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
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 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
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.
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
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,
it is reported to
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
For more information, see
Returns the old value of the flag.
If the emulator was built with support for
For more information, see
Sets the value of the node trace control word to
Returns the old value of the flag.
Returns the old state identifier, that is:
If
If
If
Returns various information about the 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 a list of the names of all allocators using
the ERTS internal
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 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 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
Returns the default value of the
Returns
Returns
Returns various information about the current system
(emulator) 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 an atom describing the build type of the runtime
system. This is normally the atom
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
See
Returns the creation of the local node as an integer.
The creation is changed when a node is restarted. The
creation of a node is stored in process identifiers, port
identifiers, and references. This makes it (to some
extent) possible to distinguish between identifiers from
different incarnations of a node. The valid
creations are integers in the range 1..3, but this will
probably change in a future release. If the node is not
alive,
Returns
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 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 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 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
The last
This option will be removed in a future release.
The return value will always be
Returns the value of command-line flag
Returns the maximum number of ETS tables allowed. This
limit can be increased at startup by passing
command-line flag
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 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 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 a string containing the Erlang machine name.
Returns the modified timing-level (an integer) if
modified timing is enabled, otherwise
Returns one of the following:
The emulator has only one scheduler thread. The emulator does not have SMP support, or have 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 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 list of
See also
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 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
Returns the default port parallelism scheduling hint used.
For more information, see command-line argument
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 a binary containing a string of process and port
information formatted as in Erlang crash dumps. For more
information, see section
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
The
See also
Returns a string containing version number and some important properties, such as the number of schedulers.
Returns a string containing the processor and OS architecture the emulator is built for.
Returns
Returns the number of async threads in the async thread
pool used for asynchronous driver calls
(
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 the value of the node trace control word. For
more information, see function
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 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 pure 64-bit architecture. On a halfword 64-bit emulator, 4 is returned, as the Erlang terms are stored using a virtual word size of half the system word size.
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 both a half word and on a pure 64-bit architecture, 8 is returned.
Argument
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
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
Returns a binary data object that is the result of encoding
If option
A compression level can be specified by giving option
Option
As from Erlang/OTP 17.0,
As from Erlang/OTP R11B-4,
See also
A non-local return from a function. If evaluated within a
> catch throw({hello, there}). {hello,there}
Failure:
Returns the current time as
The time zone and Daylight Saving Time correction depend on the underlying OS. Example:
> 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 1000000000000,
Secs = ErlangSystemTime div 1000000 - MegaSecs*1000000,
MicroSecs = ErlangSystemTime rem 1000000,
{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
> tl([geesties, guilies, beasties]). [guilies, beasties]
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
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
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 followings
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 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
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
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
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
Returns an integer by truncating
> trunc(5.5). 5
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}]
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 the link, if there is one, between the calling
process and the process or port referred to by
Returns
Once
Notice that the
unlink(Id),
receive
{'EXIT', Id, _} ->
true
after 0 ->
true
end
Before Erlang/OTP R11B (ERTS 5.5)
The current behavior can be viewed as two combined operations: asynchronously send an "unlink signal" to the linked entity and ignore any future results of the link.
Removes the registered name
> unregister(db). true
Users are advised not to unregister system processes.
Failure:
Returns the process identifier or port identifier with
the registered name
> whereis(db). <0.43.0>
Voluntarily lets other processes (if any) get a chance to
execute. Using this function is similar to
There is seldom or never any need to use this BIF, especially in the SMP emulator, as other processes have a chance to run in another scheduler thread anyway. Using this BIF without a thorough grasp of how the scheduler works can cause performance degradation.