By convention, most built-in functions (BIFs) are seen as being
in the module
In the text, auto-imported BIFs are listed without module prefix. BIFs listed with module prefix are not auto-imported.
BIFs may fail for a variety of reasons. All BIFs fail with
reason
Some BIFs may be used in guard tests, these are marked with "Allowed in guard tests".
ext_binary()
a binary data object,
structured according to the Erlang external term format
iodata() = iolist() | binary()
iolist() = [char() | binary() | iolist()]
a binary is allowed as the tail of the list
Returns an integer or float which 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
Continue computing the adler32 checksum by combining
the previous checksum,
The following code:
X = adler32(Data1),
Y = adler32(X,Data2).
- would assign the same value to
Y = 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 = adler32(Data1),
Z = adler32(Y,Data2).
- would assign the same value to
X = adler32(Data1),
Y = adler32(Data2),
Z = adler32_combine(X,Y,iolist_size(Data2)).
Returns a new tuple which has one element more than
> erlang:append_element({one, two}, three). {one,two,three}
Call a fun, passing the elements in
Note: 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"
Note: If the number of arguments are known at compile-time,
the call is better written as
Failure:
Returns a binary which corresponds to the text
representation of
Currently,
> atom_to_binary('Erlang', latin1). <<"Erlang">>
Returns a string which corresponds 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:
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>>
If
1> Bin = <<1,2,3>>
2> binary_part(Bin,{0,2}).
<<1,2>>
See the STDLIB module
Allowed in guard tests.
The same as
Allowed in guard tests.
Returns the atom whose text representation is
> binary_to_atom(<<"Erlang">>, latin1). 'Erlang' > binary_to_atom(<<1024/utf8>>, utf8). ** exception error: bad argument in function binary_to_atom/2 called as binary_to_atom(<<208,128>>,utf8)
Works like
Failure:
Returns a list of integers which correspond to the bytes of
As
This function's indexing style of using one-based indices for
binaries is deprecated. New code should use the functions in
the STDLIB module
Returns a list of integers which correspond to the bytes of
Returns an Erlang term which is the result of decoding
the binary object
When decoding binaries from untrusted sources, consider using
See also
As
Use this option when receiving binaries from an untrusted source.
When enabled, it prevents decoding data that may be used to attack the Erlang system. In the event of receiving unsafe data, decoding fails with a badarg error.
Currently, this prevents creation of new atoms directly, creation of new atoms indirectly (as they are embedded in certain structures like pids, refs, funs, etc.), and creation of new external function references. None of those resources are currently garbage collected, so unchecked creation of them can exhaust available memory.
Failure:
See also
Returns an integer which is the size in bits of
> bit_size(<<433:16,3:3>>). 19 > bit_size(<<1,2,3>>). 24
Allowed in guard tests.
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, and a context switch is forced when the counter reaches the maximum number of reductions for a process (2000 reductions in R12B).
This BIF might 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 which 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, where
See also
Note: Cancelling a timer does not guarantee that the message has not already been delivered to the message queue.
Returns
> check_process_code(Pid, lists). false
See also
Do not use; use
Computes and returns the crc32 (IEEE 802.3 style) checksum for
Continue computing the crc32 checksum by combining
the previous checksum,
The following code:
X = crc32(Data1),
Y = crc32(X,Data2).
- would assign the same value to
Y = 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 = crc32(Data1),
Z = crc32(Y,Data2).
- would assign the same value to
X = crc32(Data1),
Y = crc32(Data2),
Z = 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.
> 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
The following values of
No packet handling is done. 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 header can be one, two, or four bytes; the order of the bytes is big-endian. The header will be stripped off when the packet is returned.
A packet is a line terminated with newline. The
newline character is included in the returned packet
unless the line was truncated according to the 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.
The protocol type
The variants
The following options are available:
Sets the max allowed size of the packet body. If the packet header indicates that the length of the packet is longer than the max allowed length, the packet is considered invalid. Default is 0 which means no size limit.
Applies only to line oriented protocols
(
> erlang:decode_packet(1,<<3,"abcd">>,[]). {ok,<<"abc">>,<<"d">>} > erlang:decode_packet(1,<<5,"abcd">>,[]). {more,6}
Makes the current code for
This BIF is intended for the code server (see
Failure:
If
Once
Prior to OTP release R11B (erts version 5.5)
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
Currently the following
Remove (one)
Calling
erlang: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 the
More options may be added in the future.
Failure:
Forces the disconnection of a node. This will appear to
the node
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.
> 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 erlang: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 the exit
reason
> exit(foobar). ** exception exit: foobar > catch exit(foobar). {'EXIT',foobar}
Sends an exit signal with exit reason
The following behavior apply if
If
If
If
Returns a float by converting
> float(55). 55.0
Allowed in guard tests.
Note that if used on the top-level in a guard, it will
test whether the argument is a floating point number; for
clarity, use
When
Returns a string which corresponds to the text
representation of
> float_to_list(7.0). "7.00000000000000000000e+00"
Returns a list containing information about the fun
This BIF is mainly intended for debugging, but it can occasionally be useful in library functions that might need to verify, for instance, the arity of a fun.
There are two types of funs with 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 will be called (even if newer version of the module has been loaded).
The following elements will always be present in the list for both local and external funs:
If
If
If
If
The following elements will only be present in the list if
Returns information about
For any fun,
For a local fun,
See
Returns a string which corresponds to the text
representation of
Returns
Returns
Forces an immediate garbage collection of the currently executing process. The function should not 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 may seriously degrade system performance.
Compatibility note: In versions of OTP prior to R7,
the garbage collection took place at the next context switch,
not immediately. To force a context switch after a call to
Works like
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 keys which 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]
Get 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 []. After a code change for the process, the stacktrace may also be reset to [].
The stacktrace is the same data as the
See also
Returns the pid of the group leader for the process which evaluates the function.
Every process is a member of some process group and all
groups have a group leader. All IO 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 start-up,
Sets the group leader of
See also
Halts the Erlang runtime system and indicates normal exit to the calling environment. Has no return value.
> halt(). os_prompt%
Note that on many platforms, only the status codes 0-255 are supported by the operating system.
Returns a hash value for
This BIF is deprecated as the hash value may differ on
different architectures. Also the hash values for integer
terms larger than 2^27 as well as large binaries are very
poor. The BIF is retained for backward compatibility
reasons (it may have been used to hash records into a file),
but all new code should use one of the BIFs
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, which is useful if the process does not expect to receive any messages in the near future.
The process will be awaken when a message is sent to it, and
control will resume in
If the process has any message in its message queue, the process will be awaken immediately in the same way as described above.
In more technical terms, what
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 has been awaken will ensure that the heap size is changed to a size not smaller than the minimum heap size.
Note that emptying the call stack means that any surrounding
Returns a string which corresponds to the text
representation of
> integer_to_list(77). "77"
Returns a string which corresponds to the text
representation of
> erlang:integer_to_list(1023, 16). "3FF"
Returns a binary which 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 integer which is the size in bytes
of the binary that would be the result of
> iolist_size([1,2|<<3,4>>]). 4
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.
Returns
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Returns
Allowed in guard tests.
Currently,
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
Normally the compiler treats calls to
Allowed in guard tests, if
Allowed in guard tests, provided that
This BIF is documented for completeness. In most cases
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
Returns the atom whose text representation is
> list_to_atom("Erlang"). 'Erlang'
Returns a binary which 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 which 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>> > list_to_binary([Bin1,1,[2,3,Bin2],4|Bin3]). <<1,2,3,1,2,3,4,5,4,6,7:46>>
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
> erlang:list_to_integer("3FF", 16). 1023
Failure:
Returns a pid whose text representation is
This BIF is intended for debugging and for use in the Erlang operating system. It should not be used in application programs.
> list_to_pid("<0.4.1>"). <0.4.1>
Failure:
Returns a tuple which corresponds to
> list_to_tuple([share, ['Ericsson_B', 163]]). {share, ['Ericsson_B', 163]}
If
The object code in
The object code contains code for another module than
This BIF is intended for the code server (see
In releases older than OTP R14B, NIFs were an
experimental feature. Versions of OTP older than R14B might
have different and possibly incompatible NIF semantics and
interfaces. For example, in R13B03 the return value on
failure was
Loads and links a dynamic library containing native
implemented functions (NIFs) for a module.
The call to
It returns either
The OS failed to load the NIF library.
The library did not fulfil the requirements as a NIF library of the calling module.
The corresponding library callback was not successful.
The call to
Returns a list of all loaded Erlang modules (current and/or old code), including preloaded modules.
See also
Returns the current local date and time
The time zone and daylight saving time correction depend on the underlying OS.
> erlang:localtime(). {{1996,11,6},{14,45,17}}
Converts local date and time to Universal Time Coordinated
(UTC), if this is 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) just like
If
> 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 an almost unique reference.
The returned reference will re-occur after approximately 2^82 calls; therefore it is unique enough for practical purposes.
> make_ref(). #Ref<0.0.0.135>
Returns a new tuple of the given
> erlang:make_tuple(4, []). {[],[],[],[]}
> erlang:make_tuple(5, [], [{2,ignored},{5,zz},{2,aa}]). {{[],aa,[],[],zz}
Return the largest of
Computes an
See The MD5 Message Digest Algorithm (RFC 1321) for more information about MD5.
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 subsequent calls to
Updates an MD5
Returns a list containing information about memory
dynamically allocated by the Erlang emulator. Each element of
the list is a tuple
The total amount of memory currently allocated, which is
the same as the sum of memory size for
The total amount of memory currently allocated by the Erlang processes.
The total amount of memory currently used by the Erlang processes.
This memory is part of the memory presented as
The total amount of memory currently allocated by 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
Since the
The different amounts of memory that are summed are not gathered atomically which also introduce an error in the result.
The different values has 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 may be added in the future.
The
Since erts version 5.6.4
Failure:
Returns the memory size in bytes allocated for memory of
type
Since erts version 5.6.4
Failures:
See also
Return the smallest of
Returns
This BIF is intended for the code server (see
The calling process starts monitoring
Currently only processes can be monitored, i.e. the only
allowed
The pid of the process to monitor.
A tuple consisting of a registered name of a process and
a node name. The process residing on the node
The process locally registered as
When a process is monitored by registered name, the process
that has the registered name at the time when
A
{'DOWN', MonitorRef, Type, Object, Info}
where
A reference to the monitored object:
Either the exit reason of the process,
If/when
The monitoring is turned off either when the
If an attempt is made to monitor a process on an older node
(where remote process monitoring is not implemented or one
where remote process monitoring by registered name is not
implemented), the call fails with
Making several calls to
The format of the
Monitors the status of the node
Making several calls to
If
Nodes connected through hidden connections can be monitored as any other node.
Failure:
Behaves as
The
Failure:
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, excluding
the local node. Same as
Returns a list of nodes according to argument given. The result returned 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 which are known to this node, i.e., connected, previously connected, etc.
Some equalities:
If the local node is not alive,
Returns the tuple
It can only be used to check the local time of day if the time-zone info of the underlying operating system 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.
Starts an external program.
When starting external programs on Solaris, the system
call
For external programs, the
Works like
Works like
The shell is not usually invoked to start the
program, it's executed directly. Neither is the
Only if a shell script or
If the
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 one single message. The message data format
is
The
This is only valid for
This is only valid for
This option is only valid for
The arguments are not expanded by the shell prior to
being supplied to the executable, most notably this
means that file wildcard expansion will not happen. Use
Note also that the actual executable name (a.k.a.
If one, for any reason, wants to explicitly set the
program name in the argument vector, the
This option is only valid for
This is only valid for
When the external process connected to the port exits, a
message of the form
If the
If the port program closes its stdout without exiting,
the
This is 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 will, if this option is supplied, be opened with the flag FILE_FLAG_OVERLAPPED, so that the port program can (and has to) do overlapped I/O on its standard handles. This is not normally the case for simple port programs, but an option of value for the experienced Windows programmer. On all other platforms, this option is silently discarded.
The port can only be used for input.
The port can only be used for output.
All IO from the port are binary data objects as opposed to lists of bytes.
The port will not be closed at the end of the file and
produce an exit signal. Instead, it will remain open and
a
When running on Windows, suppress creation of a new console window when spawning the port program. (This option has no effect on other platforms.)
The default is
Failure: If the port cannot be opened, the exit reason is
Bad input arguments to
All available ports in the Erlang emulator are in use.
There was not enough memory to create the port.
There are no more available operating system processes.
The external command given was too long.
There are no more available file descriptors (for the operating system process that the Erlang emulator runs in).
The file table is full (for the entire operating system).
The
The
During use of a port opened using
Portable hash function that will give 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). Range
can be between 1 and 2^32, the function returns a hash value
for
This BIF could be used instead of the old deprecated
Portable hash function that will give the same hash for
the same Erlang term regardless of machine architecture and
ERTS version (the BIF was introduced in ERTS 5.2). Range can
be between 1 and 2^32, the function returns a hash value for
This BIF should always be used for hashing terms. It
distributes small integers better than
Note that the range
Returns a string which corresponds to the text
representation of
This BIF is intended for debugging and for use in the Erlang operating system. It should not be used in application programs.
Closes an open port. Roughly the same as
For comparison:
Note that any process can close a port using
In short:
Failure:
Sends data to a port. Same as
For comparison:
Note that any process can send to a port using
In short:
If the port is busy, the calling process will be suspended until the port is not busy anymore.
Failures:
Sends data to a port.
If the port command is aborted
If the port is busy, the calling process will be suspended until the port is not busy anymore.
Currently the following
More options may be added in the future.
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 have to call
For comparison:
Note that any process can set the port owner using
In short:
Failure:
Performs a synchronous control operation on a port.
The meaning of
Returns: a list of integers in the range 0 through 255, or a binary, depending on the port driver. The meaning of the returned data also depends on the port driver.
Failure:
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.
Failure:
Returns a list containing tuples with information about
the
Failure:
Returns information about
For valid values of
Failure:
Returns a string which corresponds to the text
representation of the port identifier
This BIF is intended for debugging and for use in the Erlang operating system. It should not be used in application programs.
Returns a list of all ports on the local node.
Returns a list of Erlang modules which are pre-loaded 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
Sets certain flags for the process which calls this function. Returns the old value of the flag.
When
See also
This is used by a process to redefine the error handler for undefined function calls and undefined registered processes. Inexperienced users should not use this flag since code auto-loading is dependent on the correct operation of the error handling module.
This changes the minimum heap size for the calling process.
This changes the minimum binary virtual heap size for the calling process.
This sets the process priority.
Internally in each priority level processes are scheduled in a round robin fashion.
Execution of processes on priority
When there are runnable processes on priority
When there are runnable processes on priority
Scheduling is preemptive. Regardless of priority, a process is preempted when it has consumed more than a certain amount of reductions since the last time it was selected for execution.
NOTE: You should not depend on the scheduling to remain exactly as it is today. Scheduling, at least on the runtime system with SMP support, is very likely to be modified in the future in order to better utilize available processor cores.
There is currently no automatic mechanism for avoiding priority inversion, such as priority inheritance, or priority ceilings. When using priorities you have to take this into account and handle such scenarios by yourself.
Making calls from a
Other priorities than
When there are runnable processes on priority
Set or clear the
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 will be generated.
(If the
Sequential tracing: The sequential trace token will be propagated as usual, but no sequential trace messages will be generated.
Stack back-traces cannot be displayed for the process.
In crash dumps, the stack, messages, and the process dictionary will be omitted.
If
Sets certain flags for the process
Failure:
Returns a list containing
The order of the
See
This BIF is intended for debugging only, use
Failure:
Returns information about the process identified by
If the process is alive and
If
If
Currently the following
The binary
The value is
A list of pids that are monitoring the process (with
A list of monitors (started by
Note however, that not all implementations support every one
of the above
Failure:
Returns a list of process identifiers corresponding to all the processes currently existing on the local node.
Note that a process that is exiting, exists but is not alive, i.e.,
> 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
Failure:
Adds a new
The values stored when
> X = put(name, walrus), Y = put(name, carpenter), Z = get(name), {X, Y, Z}. {undefined,walrus,carpenter}
Stops the execution of the calling process with an exception of given class, reason and call stack backtrace (stacktrace).
This BIF is intended for debugging and for use in the Erlang operating system. In general, it should be avoided in applications, unless you know very well what you are doing.
The stacktrace is used as the exception stacktrace for the calling process; it will be truncated to the current maximum stacktrace depth.
Because 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, that is
See also
Returns a string which corresponds to the text
representation of
This BIF is intended for debugging and for use in the Erlang operating system. It should not be used in application programs.
Associates the name
> register(db, Pid). true
Failure:
Returns a list of names which 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 pid (process identifier) of the calling process.
> self(). <0.26.0>
Allowed in guard tests.
Sends a message and returns
Sends a message and returns
The possible options are:
If the sender would have to be suspended to do the send,
If the destination node would have to be auto-connected
before doing the send,
As with
Starts a timer which will send the message
If
If
See also
Failure:
The same as
This function is intended for send operations towards 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 will not send the message but return
The same happens, if
This function is only to be used in very 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 will actually
be shut down (due to tick timeouts) by
Note that ignoring the return value from this function would
result in unreliable message passing, which is
contradictory to the Erlang programming model. The message is
not sent if this function returns
Note also that in many systems, transient states of
overloaded queues are normal. The fact that 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 which is a copy of the argument
> setelement(2, {10, green, bottles}, red). {10,red,bottles}
Returns an integer which is the size of the argument
> size({morni, mulle, bwange}). 3
Allowed in guard tests.
Returns the pid of a new process started by the application
of
Returns the pid of a new process started by the application
of
Returns the pid of a new process started by the application
of
> spawn(speed, regulator, [high_speed, thin_cut]). <0.13.1>
Returns the pid of a new process started by the application
of
Returns the pid of a new process started by the application
of
Returns the pid of a new process started by the application
of
Returns the pid of a new process started by the application
of
Returns the pid of a new process started by the application
of
Returns the pid of a new process started by the application
of
A new process is started by the application
of
Returns the pid of a new process started by the application
of
If the option
Returns the pid of a new process started by the application
of
Works exactly like
If the option
Sets a link to the parent process (like
Monitor the new process (just like
Sets the priority of the new process. Equivalent to
executing
This option is only useful for performance tuning. In general, you should not use this option unless you know that there is problem with execution times and/or memory consumption, and you should measure to make sure that the option improved 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 will be done.
The
Here are a few cases when it could be useful to change
This option is only useful for performance tuning. In general, you should not use this option unless you know that there is problem with execution times and/or memory consumption, and you should measure to make sure that the option improved matters.
Gives a minimum heap size in words. Setting this value
higher than the system default might speed up some
processes because less garbage collection is done.
Setting too high value, however, might waste memory and
slow down the system due to worse data locality.
Therefore, it is recommended to use this option only for
fine-tuning an application and to measure the execution
time with various
This option is only useful for performance tuning. In general, you should not use this option unless you know that there is problem with execution times and/or memory consumption, and you should measure to make sure that the option improved matters.
Gives a minimum binary virtual heap size in words. Setting this value
higher than the system default might speed up some
processes because less garbage collection is done.
Setting too high value, however, might waste memory.
Therefore, it is recommended to use this option only for
fine-tuning an application and to measure the execution
time with various
Returns the pid of a new process started by the application
of
Returns a tuple containing the binaries which 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 which will send the message
If
If
See also
Failure:
Returns information about the system as specified by
Returns
Returns
NOTE:
Returns
Returns
Returns
NOTE: From erts version 5.5 (OTP release 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 length of the run queue, that is, the number of processes that are ready to run.
Returns
Returns
All times are in milliseconds.
> statistics(runtime). {1690,1620} > statistics(reductions). {2046,11} > statistics(garbage_collection). {85,23961,0}
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 will not leave the suspended state until its suspend
count reach zero. The suspend count of
Currently the following options (
If the suspend count on the process identified by
This BIF is intended for debugging only.
Failures:
Suspends the process identified by
This BIF is intended for debugging only.
Sets various system properties of the Erlang node. Returns the old value of the flag.
Sets the maximum depth of call stack back-traces in the
exit reason element of
Sets the user defined
The CPU topology is used when binding schedulers to logical processors. If schedulers are already bound when the CPU topology is changed, the schedulers will be sent a request to rebind according to the new CPU topology.
The user defined CPU topology can also be set by passing
the
For information on the
In low-memory systems (especially without virtual memory), setting the value to 0 can help to conserve memory.
An alternative way to set this value is through the
(operating system) environment variable
Sets the default minimum heap size for processes. The
size is given in words. The new
Sets the default minimum binary virtual heap size for processes. The
size is given in words. The new
If multi-scheduling is enabled, more than one scheduler thread is used by the emulator. Multi-scheduling can be blocked. When multi-scheduling has been blocked, only one scheduler thread will schedule Erlang processes.
If
The return values are
NOTE: Blocking of multi-scheduling should normally not be needed. If you feel that you need to block multi-scheduling, think through the problem at least a couple of times again. Blocking multi-scheduling should only be used as a last resort since it will most likely be a very inefficient way to solve the problem.
See also
Controls if and how schedulers are bound to logical processors.
When
Schedulers can currently only be bound on newer Linux, Solaris, and Windows systems, but more systems will be supported in the future.
In order for the runtime system to be able to bind schedulers,
the CPU topology needs to be known. If the runtime system fails
to automatically detect the CPU topology, it can be defined.
For more information on how to define the CPU topology, see
The runtime system will by default bind schedulers to logical
processors using the
NOTE: If the Erlang runtime system is the only
operating system process that binds threads to logical processors,
this improves the performance of the runtime system. However,
if other operating system processes (as for example another Erlang
runtime system) also bind threads to logical processors, there
might be a performance penalty instead. If this is the case you,
are are advised to unbind the schedulers using the
Schedulers can be bound in different ways. The
Schedulers will not be bound to logical processors, i.e., the operating system decides where the scheduler threads execute, and when to migrate them. This is the default.
Schedulers with close scheduler identifiers will be bound as close as possible in hardware.
Thread refers to hardware threads (e.g. Intels hyper-threads). Schedulers with low scheduler identifiers, will be bound to the first hardware thread of each core, then schedulers with higher scheduler identifiers will be bound to the second hardware thread of each core, etc.
Schedulers will be spread like
Schedulers will be spread as much as possible.
Like
Like
A combination of
Binds schedulers the default way. Currently the default
is
How schedulers are bound matters. For example, in situations when there are fewer running processes than schedulers online, the runtime system tries to migrate processes to schedulers with low scheduler identifiers. The more the schedulers are spread over the hardware, the more resources will be available to the runtime system in such situations.
The value returned equals
Failure:
If binding of schedulers is not supported.
If
If no CPU topology information is available.
The scheduler bind type can also be set by passing
the
For more information, see
Sets the amount of schedulers online. Valid range is .
For more information see,
Sets the value of the node's trace control word to
The
Returns various information about 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 type of memory as first element and amount of allocated memory in bytes as second element. In those cases when there is information present about allocated and used memory, a third element is present. This third element contains the amount of used memory in bytes.
Note: 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. If you are interested
in the total amount of memory allocated by the emulator
see
Returns
Types:
Explanation:
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 of erts version 5.6.1 the return value is a list
of
Note: The information returned is highly implementation dependent and may be changed, or removed at any time without prior notice. It was initially intended as a tool when developing new allocators, but since it might be of interest for others it has been briefly documented.
The recognized allocators are listed in
Returns various size information for the specified
allocator. The information returned is a subset of the
information returned by
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 regarding the emulators internal I/O checking. Note, the content of the returned list may vary between platforms and over time. The only thing guaranteed is that a list is returned.
Returns the compatibility mode of the local node as
an integer. The integer returned represents the
Erlang/OTP release which the current emulator has been
set to be backward compatible with. The compatibility
mode can be configured at startup by using the command
line flag
Returns the
Types:
A level in the
Returns the user defined
Returns the automatically detected
For more information see the documentation of the
Returns the
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. Currently valid creations are integers in the range 1..3, but this may (probably will) change in the future. If the node is not alive, 0 is returned.
Returns
Returns a binary containing a string of distribution
information formatted as in Erlang crash dumps. For more
information see the
Returns a list of tuples
Returns a string containing the erlang driver version
used by the runtime system. It will be on the form
This option will be removed in a future release.
The return value will always be
Returns
Returns a list describing the default garbage collection
settings. A process spawned on the local node by a
Returns the current size of the shared (global) heap.
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. Currently the following heap types exist:
Each process has a heap reserved for its use and no references between heaps of different processes are allowed. Messages passed between processes are copied between heaps.
One heap for use by all processes. Messages passed between processes are passed by reference.
A hybrid of the
Returns a binary containing a string of miscellaneous
system information formatted as in Erlang crash dumps.
For more information see the
Returns
Returns a binary containing a string of loaded module
information formatted as in Erlang crash dumps. For more
information see the
Returns the detected number of logical processors configured
on 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
Returns
Returns the modified timing level (an integer) if
modified timing has been enabled; otherwise,
Returns
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 but one have been blocked, i.e., only one scheduler thread will schedule Erlang processes and execute Erlang code.
The emulator has more than one scheduler thread, and no scheduler threads have been blocked, i.e., all available scheduler threads will schedule Erlang processes and execute Erlang code.
See also
Returns a list of
See also
Returns a string containing the OTP release number.
Returns the number of processes currently existing at
the local node as an integer. The same value as
Returns the maximum number of concurrently existing
processes at the local node as an integer. This limit
can be configured at startup by using the command line
flag
Returns a binary containing a string of process and port
information formatted as in Erlang crash dumps. For more
information see the
Returns information on how user has requested schedulers to be bound or not bound.
NOTE: Even though user has requested
schedulers to be bound via
For more information, see
Returns information on currently used scheduler bindings.
A tuple of a size equal to
Note that only schedulers online can be bound to logical processors.
For more information, see
Returns the scheduler id (
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 after that. The amount of schedulers online can however be changed at any time.
See also
Returns the amount of schedulers online. The scheduler
identifiers of schedulers online satisfy the following
relationship:
For more information, see
Returns
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 the value of the node's trace control word.
For more information see documentation of the function
The runtime system rereads the CPU information available and
updates its internally stored information about the
Returns a string containing the version number of the emulator.
Same as
Returns the size of Erlang term words in bytes as an integer, i.e. on a 32-bit architecture 4 is returned, and on a pure 64-bit architecture 8 is returned. On a halfword 64-bit emulator, 4 is returned, as the Erlang terms are stored using a virtual wordsize of half the systems wordsize.
Returns the true wordsize of the emulator, i.e. the size of a pointer, in bytes as an integer. On a pure 32-bit architecture 4 is returned, on both a halfword and pure 64-bit architecture, 8 is returned.
The
Returns the current system monitoring settings set by
When called with the argument
Calling the function with
Returns the previous system monitor settings just like
Sets system performance monitoring options.
If a garbage collection in the system takes at least
If a garbage collection in the system results in
the allocated size of a heap being at least
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 will enlarge the process's message queue and probably make the problem worse.
Keep the monitoring process neat and do not set the system monitor limits too tight.
Failure:
Returns the current system profiling settings set by
Sets system profiler options.
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,
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
Returns a binary data object which is the result of encoding
This can be used for a variety of 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.
See also
Returns a binary data object which is the result of encoding
If the option
It is also possible to specify a compression level by giving
the option
Currently,
The option
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.
> time(). {9,42,44}
Returns the tail of
> tl([geesties, guilies, beasties]). [guilies, beasties]
Allowed in guard tests.
Failure:
Turns on (if
All processes currently existing.
All processes that will be created in the future.
All currently existing processes and all processes that will be created in the future.
Set all trace flags except
Trace sending of messages.
Message tags:
Trace receiving of messages.
Message tags:
Trace process related events.
Message tags:
Trace certain function calls. Specify which function
calls to trace by calling
Message tags:
Used in conjunction with the
Silent mode is inhibited by executing
The
Message tags:
Used in conjunction with the
The semantics is that a trace message is sent when a
call traced function actually returns, that is, when a
chain of tail recursive calls is ended. There will be
only one trace message sent per chain of tail recursive
calls, why 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:
Trace scheduling of processes.
Message tags:
Trace scheduling of an exiting processes.
Message tags:
Trace garbage collections of processes.
Message tags:
Include a time stamp in all trace messages. The time
stamp (Ts) is of the same form as returned by
A global trace flag for the Erlang node that makes all
trace timestamps be in CPU time, not wallclock. It is
only allowed with
Used in conjunction with the
Makes any process created by a traced process inherit
its trace flags, including the
Makes the first process created by a traced process
inherit its trace flags, excluding
the
Makes any process linked by a traced process inherit its
trace flags, including the
Makes the first process linked to by a traced process
inherit its trace flags, excluding
the
Specify where to send the trace messages.
The effect of combining
If the
If the
When
When
When
When
Note that the trace flag
When
When
When
When
Note that
When
When
When
When
When
When
When
When
When
Sent when garbage collection is about to be started.
All sizes are in words.
Sent when garbage collection is finished.
If the tracing process dies, the flags will be silently removed.
Only one process can trace a particular process. For this reason, attempts to trace an already traced process will fail.
Returns: A number indicating the number of processes that
matched
Failure: If specified arguments are not supported. For
example
The delivery of trace messages is dislocated on the time-line
compared to other events in the system. If you know that the
Note that the
Note that
An example: Process
Failure:
Returns trace information about a process or function.
To get information about a process,
Return a list of atoms indicating what kind of traces is
enabled for the process. The list will be empty if no
traces are enabled, and one or more of the followings
atoms if traces are enabled:
Return the identifier for process or port tracing this
process. If this process is not being traced, the return
value will be
To get information about a function,
Return
Return 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
Return the meta trace tracer process or port for this
function, if it has one. If the function is not meta
traced the returned value is
Return 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
Return the call count value for this function or
Return the call time values for this function or
Return a list containing the
The actual return value will be
If
The same as
This BIF is used to enable or disable call tracing for
exported functions. It must be combined with
Conceptually, call tracing works like this: Inside the Erlang virtual machine there is a set of processes to be traced and a set of functions to be traced. Tracing will be enabled on the intersection of the set. That is, if a process included in the traced process set calls a function included in the traced function set, the trace action will be taken. Otherwise, nothing will happen.
Use
The
The
All exported functions of any arity named
All exported functions in module
All exported functions in all loaded modules.
Other combinations, such as
If the
The
Disable tracing for the matching function(s). Any match specification will be removed.
Enable tracing for the matching function(s).
A list of match specifications. An empty list is
equivalent to
For the
For the
The
Turn on or off call tracing for global function calls (that is, calls specifying the module explicitly). Only exported functions will match and only global calls will generate trace messages. This is the default.
Turn on or off call tracing for all types of function
calls. Trace messages will be sent whenever any of
the specified functions are called, regardless of how they
are called. If the
Turn on or off meta tracing for all types of function
calls. Trace messages will be sent to the tracer process
or port
Meta tracing traces all processes and does not care
about the process trace flags set by
The match spec function
Starts (
If call count tracing is started while already running,
the count is restarted from zero. Running counters can be
paused with
The counter value can be read with
Starts (
If call time tracing is started while already running,
the count and time is restarted from zero. Running counters can be
paused with
The counter value can be read with
The
When disabling trace, the option must match the type of trace
that is set on the function, so that local tracing must be
disabled with the
There is no way to directly change part of a match
specification list. If a function has a match specification,
you can replace it with a completely new one. If you need to
change an existing match specification, use the
Returns the number of exported functions that matched
the
Returns an integer by the truncating
> trunc(5.5). 5
Allowed in guard tests.
Returns an integer which is the number of elements in
> tuple_size({morni, mulle, bwange}). 3
Allowed in guard tests.
Returns a list which corresponds to
> tuple_to_list({share, {'Ericsson_B', 163}}). [share,{'Ericsson_B',163}]
Returns the current date and time according to Universal
Time Coordinated (UTC), also called GMT, in the form
> erlang:universaltime(). {{1996,11,6},{14,18,43}}
Converts Universal Time Coordinated (UTC) date and time to
local date and time, if this is supported by the underlying
OS. Otherwise, no conversion is done, and
> 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
unlink(Id),
receive
{'EXIT', Id, _} ->
true
after 0 ->
true
end
Prior to OTP release R11B (erts version 5.5)
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 pid or port identifier with the registered name
> whereis(db). <0.43.0>
Voluntarily let other processes (if any) get a chance to
execute. Using
There is seldom or never any need to use this BIF, especially in the SMP-emulator as other processes will have a chance to run in another scheduler thread anyway. Using this BIF without a thorough grasp of how the scheduler works may cause performance degradation.