Earlier, Fun could also be given as {Module, Function}, equivalent to apply(Module, Function, Args). This usage is deprecated and will stop working in a future release of Erlang/OTP.
By convention, most built-in functions (BIFs) are seen as being in the module erlang. A number 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 and both the calls atom_to_list(Erlang) and erlang:atom_to_list(Erlang) are identical.
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 badarg if they are called with arguments of an incorrect type. The other reasons that may make BIFs fail are described in connection with the description of each individual BIF.
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
abs(Number) -> int() | float()
Types:
Number = number()
Returns an integer or float which is the arithmetical absolute value of Number.
> abs(-3.33). 3.33 > abs(-3). 3
Allowed in guard tests.
Types:
Data = iodata()
Computes and returns the adler32 checksum for Data.
adler32(OldAdler, Data) -> int()
Types:
OldAdler = int()
Data = iodata()
Continue computing the adler32 checksum by combining the previous checksum, OldAdler, with the checksum of Data.
The following code:
X = adler32(Data1), Y = adler32(X,Data2).
- would assign the same value to Y as this would:
Y = adler32([Data1,Data2]).
adler32_combine(FirstAdler, SecondAdler, SecondSize) -> int()
Types:
FirstAdler = SecondAdler = int()
SecondSize = int()
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 Z as this would:
X = adler32(Data1), Y = adler32(Data2), Z = adler32_combine(X,Y,iolist_size(Data2)).
erlang:append_element(Tuple1, Term) -> Tuple2
Types:
Tuple1 = Tuple2 = tuple()
Term = term()
Returns a new tuple which has one element more than Tuple1, and contains the elements in Tuple1 followed by Term as the last element. Semantically equivalent to list_to_tuple(tuple_to_list(Tuple ++ [Term]), but much faster.
> erlang:append_element({one, two}, three). {one,two,three}
apply(Fun, Args) -> term() | empty()
Types:
Fun = fun()
Args = [term()]
Call a fun, passing the elements in Args as arguments.
Note: If the number of elements in the arguments are known at compile-time, the call is better written as Fun(Arg1, Arg2, ... ArgN).
Earlier, Fun could also be given as {Module, Function}, equivalent to apply(Module, Function, Args). This usage is deprecated and will stop working in a future release of Erlang/OTP.
apply(Module, Function, Args) -> term() | empty()
Types:
Module = Function = atom()
Args = [term()]
Returns the result of applying Function in Module to Args. The applied function must be exported from Module. The arity of the function is the length of Args.
> apply(lists, reverse, [[a, b, c]]). [c,b,a]
apply can be used to evaluate BIFs by using the module name erlang.
> apply(erlang, atom_to_list, ['Erlang']). "Erlang"
Note: If the number of arguments are known at compile-time, the call is better written as Module:Function(Arg1, Arg2, ..., ArgN).
Failure: error_handler:undefined_function/3 is called if the applied function is not exported. The error handler can be redefined (see process_flag/2). If the error_handler is undefined, or if the user has redefined the default error_handler so the replacement module is undefined, an error with the reason undef is generated.
atom_to_list(Atom) -> string()
Types:
Atom = atom()
Returns a string which corresponds to the text representation of Atom.
> atom_to_list('Erlang'). "Erlang"
binary_to_list(Binary) -> [char()]
Types:
Binary = binary()
Returns a list of integers which correspond to the bytes of Binary.
binary_to_list(Binary, Start, Stop) -> [char()]
Types:
Binary = binary()
Start = Stop = 1..byte_size(Binary)
As binary_to_list/1, but returns a list of integers corresponding to the bytes from position Start to position Stop in Binary. Positions in the binary are numbered starting from 1.
bitstring_to_list(Bitstring) -> [char()|bitstring()]
Types:
Bitstring = bitstring()
Returns a list of integers which correspond to the bytes of Bitstring. If the number of bits in the binary is not divisible by 8, the last element of the list will be a bitstring containing the remaining bits (1 up to 7 bits).
binary_to_term(Binary) -> term()
Types:
Binary = ext_binary()
Returns an Erlang term which is the result of decoding the binary object Binary, which must be encoded according to the Erlang external term format. See also term_to_binary/1.
Types:
Bitstring = bitstring()
Returns an integer which is the size in bits of Bitstring.
> bit_size(<<433:16,3:3>>). 19 > bit_size(<<1,2,3>>). 24
Allowed in guard tests.
erlang:bump_reductions(Reductions) -> void()
Types:
Reductions = int()
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 1000.
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.
Types:
Bitstring = bitstring()
Returns an integer which is the number of bytes needed to contain Bitstring. (That is, if the number of bits in Bitstring is not divisible by 8, the resulting number of bytes will be rounded up.)
> byte_size(<<433:16,3:3>>). 3 > byte_size(<<1,2,3>>). 3
Allowed in guard tests.
erlang:cancel_timer(TimerRef) -> Time | false
Types:
TimerRef = ref()
Time = int()
Cancels a timer, where TimerRef was returned by either erlang:send_after/3 or erlang:start_timer/3. If the timer is there to be removed, the function returns the time in milliseconds left until the timer would have expired, otherwise false (which means that TimerRef was never a timer, that it has already been cancelled, or that it has already delivered its message).
See also erlang:send_after/3, erlang:start_timer/3, and erlang:read_timer/1.
Note: Cancelling a timer does not guarantee that the message has not already been delivered to the message queue.
check_process_code(Pid, Module) -> bool()
Types:
Pid = pid()
Module = atom()
Returns true if the process Pid is executing old code for Module. That is, if the current call of the process executes old code for this module, or if the process has references to old code for this module, or if the process contains funs that references old code for this module. Otherwise, it returns false.
> check_process_code(Pid, lists). false
See also code(3).
Do not use; use list_to_binary/1 instead.
Types:
Data = iodata()
Computes and returns the crc32 (IEEE 802.3 style) checksum for Data.
Types:
OldCrc = int()
Data = iodata()
Continue computing the crc32 checksum by combining the previous checksum, OldCrc, with the checksum of Data.
The following code:
X = crc32(Data1), Y = crc32(X,Data2).
- would assign the same value to Y as this would:
Y = crc32([Data1,Data2]).
crc32_combine(FirstCrc, SecondCrc, SecondSize) -> int()
Types:
FirstCrc = SecondCrc = int()
SecondSize = int()
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 Z as this would:
X = crc32(Data1), Y = crc32(Data2), Z = crc32_combine(X,Y,iolist_size(Data2)).
Types:
Year = Month = Day = int()
Returns the current date as {Year, Month, Day}.
The time zone and daylight saving time correction depend on the underlying OS.
> date(). {1995,2,19}
decode_packet(Type,Bin,Options) -> {ok,Packet,Rest} | {more,Length} | {error,Reason}
Types:
Bin = binary()
Options = [Opt]
Packet = binary() | HttpPacket
Rest = binary()
Length = int() | undefined
Reason = term()
Type, Opt -- see below
HttpPacket = HttpRequest | HttpResponse | HttpHeader | http_eoh | HttpError
HttpRequest = {http_request, HttpMethod, HttpUri, HttpVersion}
HttpResponse = {http_response, HttpVersion, integer(), string()}
HttpHeader = {http_header, int(), HttpField, Reserved=term(), Value=string()}
HttpError = {http_error, string()}
HttpMethod = HttpMethodAtom | string()
HttpMethodAtom = 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE'
HttpUri = '*' | {absoluteURI, http|https, Host=string(), Port=int()|undefined, Path=string()} |
{scheme, Scheme=string(), string()} | {abs_path, string} | string()
HttpVersion = {Major=int(), Minor=int()}
HttpField = HttpFieldAtom | string()
HttpFieldAtom = 'Cache-Control' | 'Connection' | 'Date' | 'Pragma' | 'Transfer-Encoding' | 'Upgrade' | 'Via' | 'Accept' | 'Accept-Charset' | 'Accept-Encoding' | 'Accept-Language' | 'Authorization' | 'From' | 'Host' | 'If-Modified-Since' | 'If-Match' | 'If-None-Match' | 'If-Range' | 'If-Unmodified-Since' | 'Max-Forwards' | 'Proxy-Authorization' | 'Range' | 'Referer' | 'User-Agent' | 'Age' | 'Location' | 'Proxy-Authenticate' | 'Public' | 'Retry-After' | 'Server' | 'Vary' | 'Warning' | 'Www-Authenticate' | 'Allow' | 'Content-Base' | 'Content-Encoding' | 'Content-Language' | 'Content-Length' | 'Content-Location' | 'Content-Md5' | 'Content-Range' | 'Content-Type' | 'Etag' | 'Expires' | 'Last-Modified' | 'Accept-Ranges' | 'Set-Cookie' | 'Set-Cookie2' | 'X-Forwarded-For' | 'Cookie' | 'Keep-Alive' | 'Proxy-Connection'
Decodes the binary Bin according to the packet protocol specified by Type. Very simular to the packet handling done by sockets with the option {packet,Type}.
If an entire packet is contained in Bin it is returned together with the remainder of the binary as {ok,Packet,Rest}.
If Bin does not contain the entire packet, {more,Length} is returned. Length is either the expected total size of the packet or undefined if the expected packet size is not known. decode_packet can then be called again with more data added.
If the packet does not conform to the protocol format {error,Reason} is returned.
The following values of Type are valid:
The following options are available:
> erlang:decode_packet(1,<<3,"abcd">>,[]). {ok,<<"abc">>,<<"d">>} > erlang:decode_packet(1,<<5,"abcd">>,[]). {more,6}
delete_module(Module) -> true | undefined
Types:
Module = atom()
Makes the current code for Module become old code, and deletes all references for this module from the export table. Returns undefined if the module does not exist, otherwise true.
This BIF is intended for the code server (see code(3)) and should not be used elsewhere.
Failure: badarg if there is already an old version of Module.
erlang:demonitor(MonitorRef) -> true
Types:
MonitorRef = ref()
If MonitorRef is a reference which the calling process obtained by calling erlang:monitor/2, this monitoring is turned off. If the monitoring is already turned off, nothing happens.
Once erlang:demonitor(MonitorRef) has returned it is guaranteed that no {'DOWN', MonitorRef, _, _, _} message due to the monitor will be placed in the callers message queue in the future. A {'DOWN', MonitorRef, _, _, _} message might have been placed in the callers message queue prior to the call, though. Therefore, in most cases, it is advisable to remove such a 'DOWN' message from the message queue after monitoring has been stopped. erlang:demonitor(MonitorRef, [flush]) can be used instead of erlang:demonitor(MonitorRef) if this cleanup is wanted.
Prior to OTP release R11B (erts version 5.5) erlang:demonitor/1 behaved completely asynchronous, i.e., the monitor was active until the "demonitor signal" reached the monitored entity. This had one undesirable effect, though. You could never know when you were guaranteed not to receive a DOWN message due to the monitor.
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 MonitorRef refers to a monitoring started by another process. Not all such cases are cheap to check; if checking is cheap, the call fails with badarg (for example if MonitorRef is a remote reference).
erlang:demonitor(MonitorRef, OptionList) -> true
Types:
MonitorRef = ref()
OptionList = [Option]
Option = flush
erlang:demonitor(MonitorRef, []) is equivalent to erlang:demonitor(MonitorRef).
Currently the following Options are valid:
erlang:demonitor(MonitorRef), receive {_, MonitorRef, _, _, _} -> true after 0 -> true end
More options may be added in the future.
Failure: badarg if OptionList is not a list, or if Option is not a valid option, or the same failure as for erlang:demonitor/1
disconnect_node(Node) -> bool() | ignored
Types:
Node = atom()
Forces the disconnection of a node. This will appear to the node Node as if the local node has crashed. This BIF is mainly used in the Erlang network authentication protocols. Returns true if disconnection succeeds, otherwise false. If the local node is not alive, the function returns ignored.
Types:
Term = term()
Prints a text representation of Term on the standard output.
This BIF is intended for debugging only.
Types:
N = 1..tuple_size(Tuple)
Tuple = tuple()
Returns the Nth element (numbering from 1) of Tuple.
> element(2, {a, b, c}). b
Allowed in guard tests.
Types:
Key = Val = term()
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]}]
Types:
Key = Val = term()
Returns the value Val associated with Key and deletes it from the process dictionary. Returns undefined if no value is associated with Key.
> put(key1, {merry, lambs, are, playing}), X = erase(key1), {X, erase(key1)}. {{merry,lambs,are,playing},undefined}
Types:
Reason = term()
Stops the execution of the calling process with the reason Reason, where Reason is any term. The actual exit reason will be {Reason, Where}, where Where is a list of the functions most recently called (the current function first). Since evaluating this function causes the process to terminate, it has no return value.
> 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}]}}
Types:
Reason = term()
Args = [term()]
Stops the execution of the calling process with the reason Reason, where Reason is any term. The actual exit reason will be {Reason, Where}, where Where is a list of the functions most recently called (the current function first). Args is expected to be the list of arguments for the current function; in Beam it will be used to provide the actual arguments for the current function in the Where term. Since evaluating this function causes the process to terminate, it has no return value.
Types:
Reason = term()
Stops the execution of the calling process with the exit reason Reason, where Reason is any term. Since evaluating this function causes the process to terminate, it has no return value.
> exit(foobar). ** exception exit: foobar > catch exit(foobar). {'EXIT',foobar}
Types:
Pid = pid()
Reason = term()
Sends an exit signal with exit reason Reason to the process Pid.
The following behavior apply if Reason is any term except normal or kill:
If Pid is not trapping exits, Pid itself will exit with exit reason Reason. If Pid is trapping exits, the exit signal is transformed into a message {'EXIT', From, Reason} and delivered to the message queue of Pid. From is the pid of the process which sent the exit signal. See also process_flag/2.
If Reason is the atom normal, Pid will not exit. If it is trapping exits, the exit signal is transformed into a message {'EXIT', From, normal} and delivered to its message queue.
If Reason is the atom kill, that is if exit(Pid, kill) is called, an untrappable exit signal is sent to Pid which will unconditionally exit with exit reason killed.
Types:
Reason = term()
This function is deprecated and will be removed in the next release. Used erlang:error(Reason) instead.
Types:
Reason = term()
Args = [term()]
This function is deprecated and will be removed in the next release. Use erlang:error(Reason, Args) instead.
Types:
Number = number()
Returns a float by converting Number to a float.
> 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 is_float/1 instead.
When float/1 is used in an expression in a guard, such as 'float(A) == 4.0', it converts a number as described above.
float_to_list(Float) -> string()
Types:
Float = float()
Returns a string which corresponds to the text representation of Float.
> float_to_list(7.0). "7.00000000000000000000e+00"
erlang:fun_info(Fun) -> [{Item, Info}]
Types:
Fun = fun()
Item, Info -- see below
Returns a list containing information about the fun Fun. Each element of the list is a tuple. The order of the tuples is not defined, and more tuples may be added in a future release.
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 fun M:F/A is called an external fun. Calling it will always call the function F with arity A in the latest code for module M. Note that module M does not even need to be loaded when the fun fun M:F/A is created.
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:
The following elements will only be present in the list if Fun is local:
erlang:fun_info(Fun, Item) -> {Item, Info}
Types:
Fun = fun()
Item, Info -- see below
Returns information about Fun as specified by Item, in the form {Item,Info}.
For any fun, Item can be any of the atoms module, name, arity, or env.
For a local fun, Item can also be any of the atoms index, new_index, new_uniq, uniq, and pid. For an external fun, the value of any of these items is always the atom undefined.
See erlang:fun_info/1.
erlang:fun_to_list(Fun) -> string()
Types:
Fun = fun()
Returns a string which corresponds to the text representation of Fun.
erlang:function_exported(Module, Function, Arity) -> bool()
Types:
Module = Function = atom()
Arity = int()
Returns true if the module Module is loaded and contains an exported function Function/Arity; otherwise false.
Returns false for any BIF (functions implemented in C rather than in Erlang).
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 erlang:garbage_collect(), it was sufficient to make any function call.
garbage_collect(Pid) -> bool()
Types:
Pid = pid()
Works like erlang:garbage_collect() but on any process. The same caveats apply. Returns false if Pid refers to a dead process; true otherwise.
Types:
Key = Val = term()
Returns the process dictionary as a list of {Key, Val} tuples.
> put(key1, merry), put(key2, lambs), put(key3, {are, playing}), get(). [{key1,merry},{key2,lambs},{key3,{are,playing}}]
Types:
Key = Val = term()
Returns the value Valassociated with Key in the process dictionary, or undefined if Key does not exist.
> put(key1, merry), put(key2, lambs), put({any, [valid, term]}, {are, playing}), get({any, [valid, term]}). {are,playing}
erlang:get_cookie() -> Cookie | nocookie
Types:
Cookie = atom()
Returns the magic cookie of the local node, if the node is alive; otherwise the atom nocookie.
Types:
Val = Key = term()
Returns a list of keys which are associated with the value Val in the process dictionary.
> 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]
erlang:get_stacktrace() -> [{Module, Function, Arity | Args}]
Types:
Module = Function = atom()
Arity = int()
Args = [term()]
Get the call stack back-trace (stacktrace) of the last exception in the calling process as a list of {Module,Function,Arity} tuples. The Arity field in the first tuple may be the argument list of that function call instead of an arity integer, depending on the exception.
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 catch operator returns, for example:
{'EXIT',{badarg,Stacktrace}} = catch abs(x)
See also erlang:error/1 and erlang:error/2.
Types:
GroupLeader = pid()
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, init is both its own group leader and the group leader of all processes.
group_leader(GroupLeader, Pid) -> true
Types:
GroupLeader = Pid = pid()
Sets the group leader of Pid to GroupLeader. Typically, this is used when a processes started from a certain shell should have another group leader than init.
See also group_leader/0.
Halts the Erlang runtime system and indicates normal exit to the calling environment. Has no return value.
> halt(). os_prompt%
Types:
Status = int()>=0 | string()
Status must be a non-negative integer, or a string. Halts the Erlang runtime system. Has no return value. If Status is an integer, it is returned as an exit status of Erlang to the calling environment. If Status is a string, produces an Erlang crash dump with String as slogan, and then exits with a non-zero status code.
Note that on many platforms, only the status codes 0-255 are supported by the operating system.
erlang:hash(Term, Range) -> Hash
Returns a hash value for Term within the range 1..Range. The allowed range is 1..2^27-1.
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 erlang:phash/2 or erlang:phash2/1,2 instead.
Types:
List = [term()]
Returns the head of List, that is, the first element.
> hd([1,2,3,4,5]). 1
Allowed in guard tests.
Failure: badarg if List is the empty list [].
erlang:hibernate(Module, Function, Args)
Types:
Module = Function = atom()
Args = [term()]
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 Module:Function with the arguments given by Args with the call stack emptied, meaning that the process will terminate when that function returns. Thus erlang:hibernate/3 will never return to its caller.
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 erlang:hibernate/3 does is the following. It discards the call stack for the process. Then it garbage collects the process. After the garbage collection, all live data is in one continuous heap. The heap is then shrunken to the exact same size as the live data which it holds (even if that size is less than the minimum heap size for the process).
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 catch is removed and has to be re-inserted after hibernation. One effect of this is that processes started using proc_lib (also indirectly, such as gen_server processes), should use proc_lib:hibernate/3 instead to ensure that the exception handler continues to work when the process wakes up.
integer_to_list(Integer) -> string()
Types:
Integer = int()
Returns a string which corresponds to the text representation of Integer.
> integer_to_list(77). "77"
erlang:integer_to_list(Integer, Base) -> string()
Types:
Integer = int()
Base = 2..36
Returns a string which corresponds to the text representation of Integer in base Base.
> erlang:integer_to_list(1023, 16). "3FF"
iolist_to_binary(IoListOrBinary) -> binary()
Types:
IoListOrBinary = iolist() | binary()
Returns a binary which is made from the integers and binaries in IoListOrBinary.
> 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>>
Types:
Item = iolist() | binary()
Returns an integer which is the size in bytes of the binary that would be the result of iolist_to_binary(Item).
> iolist_size([1,2|<<3,4>>]). 4
Returns true if the local node is alive; that is, if the node can be part of a distributed system. Otherwise, it returns false.
Types:
Term = term()
Returns true if Term is an atom; otherwise returns false.
Allowed in guard tests.
Types:
Term = term()
Returns true if Term is a binary; otherwise returns false.
A binary always contains a complete number of bytes.
Allowed in guard tests.
Types:
Term = term()
Returns true if Term is a bitstring (including a binary); otherwise returns false.
Allowed in guard tests.
Types:
Term = term()
Returns true if Term is either the atom true or the atom false (i.e. a boolean); otherwise returns false.
Allowed in guard tests.
erlang:is_builtin(Module, Function, Arity) -> bool()
Types:
Module = Function = atom()
Arity = int()
Returns true if Module:Function/Arity is a BIF implemented in C; otherwise returns false. This BIF is useful for builders of cross reference tools.
Types:
Term = term()
Returns true if Term is a floating point number; otherwise returns false.
Allowed in guard tests.
Types:
Term = term()
Returns true if Term is a fun; otherwise returns false.
Allowed in guard tests.
is_function(Term, Arity) -> bool()
Types:
Term = term()
Arity = int()
Returns true if Term is a fun that can be applied with Arity number of arguments; otherwise returns false.
Allowed in guard tests.
Currently, is_function/2 will also return true if the first argument is a tuple fun (a tuple containing two atoms). In a future release, tuple funs will no longer be supported and is_function/2 will return false if given a tuple fun.
Types:
Term = term()
Returns true if Term is an integer; otherwise returns false.
Allowed in guard tests.
Types:
Term = term()
Returns true if Term is a list with zero or more elements; otherwise returns false.
Allowed in guard tests.
Types:
Term = term()
Returns true if Term is either an integer or a floating point number; otherwise returns false.
Allowed in guard tests.
Types:
Term = term()
Returns true if Term is a pid (process identifier); otherwise returns false.
Allowed in guard tests.
Types:
Term = term()
Returns true if Term is a port identifier; otherwise returns false.
Allowed in guard tests.
is_process_alive(Pid) -> bool()
Types:
Pid = pid()
Pid must refer to a process at the local node. Returns true if the process exists and is alive, that is, is not exiting and has not exited. Otherwise, returns false.
is_record(Term, RecordTag) -> bool()
Types:
Term = term()
RecordTag = atom()
Returns true if Term is a tuple and its first element is RecordTag. Otherwise, returns false.
Normally the compiler treats calls to is_record/2 specially. It emits code to verify that Term is a tuple, that its first element is RecordTag, and that the size is correct. However, if the RecordTag is not a literal atom, the is_record/2 BIF will be called instead and the size of the tuple will not be verified.
Allowed in guard tests, if RecordTag is a literal atom.
is_record(Term, RecordTag, Size) -> bool()
Types:
Term = term()
RecordTag = atom()
Size = int()
RecordTag must be an atom. Returns true if Term is a tuple, its first element is RecordTag, and its size is Size. Otherwise, returns false.
Allowed in guard tests, provided that RecordTag is a literal atom and Size is a literal integer.
This BIF is documented for completeness. In most cases is_record/2 should be used.
Types:
Term = term()
Returns true if Term is a reference; otherwise returns false.
Allowed in guard tests.
Types:
Term = term()
Returns true if Term is a tuple; otherwise returns false.
Allowed in guard tests.
Types:
List = [term()]
Returns the length of List.
> length([1,2,3,4,5,6,7,8,9]). 9
Allowed in guard tests.
Types:
Pid = pid() | port()
Creates a link between the calling process and another process (or port) Pid, if there is not such a link already. If a process attempts to create a link to itself, nothing is done. Returns true.
If Pid does not exist, the behavior of the BIF depends on if the calling process is trapping exits or not (see process_flag/2):
list_to_atom(String) -> atom()
Types:
String = string()
Returns the atom whose text representation is String.
> list_to_atom("Erlang"). 'Erlang'
list_to_binary(IoList) -> binary()
Types:
IoList = iolist()
Returns a binary which is made from the integers and binaries in IoList.
> 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>>
list_to_bitstring(BitstringList) -> bitstring()
Types:
BitstringList = [BitstringList | bitstring() | char()]
Returns a bitstring which is made from the integers and bitstrings in BitstringList. (The last tail in BitstringList is allowed to be a bitstring.)
> 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>>
list_to_existing_atom(String) -> atom()
Types:
String = string()
Returns the atom whose text representation is String, but only if there already exists such atom.
Failure: badarg if there does not already exist an atom whose text representation is String.
list_to_float(String) -> float()
Types:
String = string()
Returns the float whose text representation is String.
> list_to_float("2.2017764e+0"). 2.2017764
Failure: badarg if String contains a bad representation of a float.
list_to_integer(String) -> int()
Types:
String = string()
Returns an integer whose text representation is String.
> list_to_integer("123"). 123
Failure: badarg if String contains a bad representation of an integer.
erlang:list_to_integer(String, Base) -> int()
Types:
String = string()
Base = 2..36
Returns an integer whose text representation in base Base is String.
> erlang:list_to_integer("3FF", 16). 1023
Failure: badarg if String contains a bad representation of an integer.
Types:
String = string()
Returns a pid whose text representation is String.
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: badarg if String contains a bad representation of a pid.
list_to_tuple(List) -> tuple()
Types:
List = [term()]
Returns a tuple which corresponds to List. List can contain any Erlang terms.
> list_to_tuple([share, ['Ericsson_B', 163]]). {share, ['Ericsson_B', 163]}
load_module(Module, Binary) -> {module, Module} | {error, Reason}
Types:
Module = atom()
Binary = binary()
Reason = badfile | not_purged | badfile
If Binary contains the object code for the module Module, this BIF loads that object code. Also, if the code for the module Module already exists, all export references are replaced so they point to the newly loaded code. The previously loaded code is kept in the system as old code, as there may still be processes which are executing that code. It returns either {module, Module}, or {error, Reason} if loading fails. Reason is one of the following:
This BIF is intended for the code server (see code(3)) and should not be used elsewhere.
Types:
Module = atom()
Returns a list of all loaded Erlang modules (current and/or old code), including preloaded modules.
See also code(3).
erlang:localtime() -> {Date, Time}
Types:
Date = {Year, Month, Day}
Time = {Hour, Minute, Second}
Year = Month = Day = Hour = Minute = Second = int()
Returns the current local date and time {{Year, Month, Day}, {Hour, Minute, Second}}.
The time zone and daylight saving time correction depend on the underlying OS.
> erlang:localtime(). {{1996,11,6},{14,45,17}}
erlang:localtime_to_universaltime({Date1, Time1}) -> {Date2, Time2}
Types:
Date1 = Date2 = {Year, Month, Day}
Time1 = Time2 = {Hour, Minute, Second}
Year = Month = Day = Hour = Minute = Second = int()
Converts local date and time to Universal Time Coordinated (UTC), if this is supported by the underlying OS. Otherwise, no conversion is done and {Date1, Time1} is returned.
> erlang:localtime_to_universaltime({{1996,11,6},{14,45,17}}). {{1996,11,6},{13,45,17}}
Failure: badarg if Date1 or Time1 do not denote a valid date or time.
erlang:localtime_to_universaltime({Date1, Time1}, IsDst) -> {Date2, Time2}
Types:
Date1 = Date2 = {Year, Month, Day}
Time1 = Time2 = {Hour, Minute, Second}
Year = Month = Day = Hour = Minute = Second = int()
IsDst = true | false | undefined
Converts local date and time to Universal Time Coordinated (UTC) just like erlang:localtime_to_universaltime/1, but the caller decides if daylight saving time is active or not.
If IsDst == true the {Date1, Time1} is during daylight saving time, if IsDst == false it is not, and if IsDst == undefined the underlying OS may guess, which is the same as calling erlang:localtime_to_universaltime({Date1, Time1}).
> 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: badarg if Date1 or Time1 do not denote a valid date or time.
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>
erlang:make_tuple(Arity, InitialValue) -> tuple()
Types:
Arity = int()
InitialValue = term()
Returns a new tuple of the given Arity, where all elements are InitialValue.
> erlang:make_tuple(4, []). {[],[],[],[]}
Types:
Data = iodata()
Digest = binary()
Computes an MD5 message digest from Data, where the length of the digest is 128 bits (16 bytes). Data is a binary or a list of small integers and binaries.
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.
erlang:md5_final(Context) -> Digest
Types:
Context = Digest = binary()
Finishes the update of an MD5 Context and returns the computed MD5 message digest.
Types:
Context = binary()
Creates an MD5 context, to be used in subsequent calls to md5_update/2.
erlang:md5_update(Context, Data) -> NewContext
Types:
Data = iodata()
Context = NewContext = binary()
Updates an MD5 Context with Data, and returns a NewContext.
erlang:memory() -> [{Type, Size}]
Types:
Type, Size -- see below
Returns a list containing information about memory dynamically allocated by the Erlang emulator. Each element of the list is a tuple {Type, Size}. The first element Typeis an atom describing memory type. The second element Sizeis memory size in bytes. A description of each memory type follows:
The system value is not complete. Some allocated memory that should be part of the system value are not.
When the emulator is run with instrumentation, the system value is more accurate, but memory directly allocated by malloc (and friends) are still not part of the system value. Direct calls to malloc are only done from OS specific runtime libraries and perhaps from user implemented Erlang drivers that do not use the memory allocation functions in the driver interface.
Since the total value is the sum of processes and system the error in system will propagate to the total value.
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 total value is supposed to be the total amount of memory dynamically allocated by the emulator. Shared libraries, the code of the emulator itself, and the emulator stack(s) are not supposed to be included. That is, the total value is not supposed to be equal to the total size of all pages mapped to the emulator. Furthermore, due to fragmentation and pre-reservation of memory areas, the size of the memory segments which contain the dynamically allocated memory blocks can be substantially larger than the total size of the dynamically allocated memory blocks.
Since erts version 5.6.4 erlang:memory/0 requires that all erts_alloc(3) allocators are enabled (default behaviour).
Failure:
erlang:memory(Type | [Type]) -> Size | [{Type, Size}]
Types:
Type, Size -- see below
Returns the memory size in bytes allocated for memory of type Type. The argument can also be given as a list of Type atoms, in which case a corresponding list of {Type, Size} tuples is returned.
Since erts version 5.6.4 erlang:memory/1 requires that all erts_alloc(3) allocators are enabled (default behaviour).
Failures:
See also erlang:memory/0.
module_loaded(Module) -> bool()
Types:
Module = atom()
Returns true if the module Module is loaded, otherwise returns false. It does not attempt to load the module.
This BIF is intended for the code server (see code(3)) and should not be used elsewhere.
erlang:monitor(Type, Item) -> MonitorRef
Types:
Type = process
Item = pid() | {RegName, Node} | RegName
RegName = atom()
Node = node()
MonitorRef = reference()
The calling process starts monitoring Item which is an object of type Type.
Currently only processes can be monitored, i.e. the only allowed Type is process, but other types may be allowed in the future.
Item can be:
When a process is monitored by registered name, the process that has the registered name at the time when erlang:monitor/2 is called will be monitored. The monitor will not be effected, if the registered name is unregistered.
A 'DOWN' message will be sent to the monitoring process if Item dies, if Item does not exist, or if the connection is lost to the node which Item resides on. A 'DOWN' message has the following pattern:
{'DOWN', MonitorRef, Type, Object, Info}
where MonitorRef and Type are the same as described above, and:
If/when erlang:monitor/2 is extended (e.g. to handle other item types than process), other possible values for Object, and Info in the 'DOWN' message will be introduced.
The monitoring is turned off either when the 'DOWN' message is sent, or when erlang:demonitor/1 is called.
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 badarg.
Making several calls to erlang:monitor/2 for the same Item is not an error; it results in as many, completely independent, monitorings.
The format of the 'DOWN' message changed in the 5.2 version of the emulator (OTP release R9B) for monitor by registered name. The Object element of the 'DOWN' message could in earlier versions sometimes be the pid of the monitored process and sometimes be the registered name. Now the Object element is always a tuple consisting of the registered name and the node name. Processes on new nodes (emulator version 5.2 or greater) will always get 'DOWN' messages on the new format even if they are monitoring processes on old nodes. Processes on old nodes will always get 'DOWN' messages on the old format.
monitor_node(Node, Flag) -> true
Types:
Node = node()
Flag = bool()
Monitors the status of the node Node. If Flag is true, monitoring is turned on; if Flag is false, monitoring is turned off.
Making several calls to monitor_node(Node, true) for the same Node is not an error; it results in as many, completely independent, monitorings.
If Node fails or does not exist, the message {nodedown, Node} is delivered to the process. If a process has made two calls to monitor_node(Node, true) and Node terminates, two nodedown messages are delivered to the process. If there is no connection to Node, there will be an attempt to create one. If this fails, a nodedown message is delivered.
Nodes connected through hidden connections can be monitored as any other node.
Failure: badargif the local node is not alive.
erlang:monitor_node(Node, Flag, Options) -> true
Types:
Node = node()
Flag = bool()
Options = [Option]
Option = allow_passive_connect
Behaves as monitor_node/2 except that it allows an extra option to be given, namely allow_passive_connect. The option allows the BIF to wait the normal net connection timeout for the monitored node to connect itself, even if it cannot be actively connected from this node (i.e. it is blocked). The state where this might be useful can only be achieved by using the kernel option dist_auto_connect once. If that kernel option is not used, the allow_passive_connect option has no effect.
The allow_passive_connect option is used internally and is seldom needed in applications where the network topology and the kernel options in effect is known in advance.
Failure: badarg if the local node is not alive or the option list is malformed.
Types:
Node = node()
Returns the name of the local node. If the node is not alive, nonode@nohost is returned instead.
Allowed in guard tests.
Types:
Arg = pid() | port() | ref()
Node = node()
Returns the node where Arg is located. Arg can be a pid, a reference, or a port. If the local node is not alive, nonode@nohost is returned.
Allowed in guard tests.
Types:
Nodes = [node()]
Returns a list of all visible nodes in the system, excluding the local node. Same as nodes(visible).
Types:
Arg = visible | hidden | connected | this | known
Nodes = [node()]
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.
Arg can be any of the following:
Some equalities: [node()] = nodes(this), nodes(connected) = nodes([visible, hidden]), and nodes() = nodes(visible).
If the local node is not alive, nodes(this) == nodes(known) == [nonode@nohost], for any other Arg the empty list [] is returned.
now() -> {MegaSecs, Secs, MicroSecs}
Types:
MegaSecs = Secs = MicroSecs = int()
Returns the tuple {MegaSecs, Secs, MicroSecs} which is the elapsed time since 00:00 GMT, January 1, 1970 (zero hour) on the assumption that the underlying OS supports this. Otherwise, some other point in time is chosen. It is also guaranteed that subsequent calls to this BIF returns continuously increasing values. Hence, the return value from now() can be used to generate unique time-stamps. 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.
open_port(PortName, PortSettings) -> port()
Types:
PortName = {spawn, Command} | {fd, In, Out}
Command = string()
In = Out = int()
PortSettings = [Opt]
Opt = {packet, N} | stream | {line, L} | {cd, Dir} | {env, Env} | exit_status | use_stdio | nouse_stdio | stderr_to_stdout | in | out | binary | eof
N = 1 | 2 | 4
L = int()
Dir = string()
Env = [{Name, Val}]
Name = string()
Val = string() | false
Returns a port identifier as the result of opening a new Erlang port. A port can be seen as an external Erlang process. PortName is one of the following:
PortSettings is a list of settings for the port. Valid settings are:
The default is stream for all types of port and use_stdio for spawned ports.
Failure: If the port cannot be opened, the exit reason is badarg, system_limit, or the Posix error code which most closely describes the error, or einval if no Posix code is appropriate:
During use of a port opened using {spawn, Name}, errors arising when sending messages to it are reported to the owning process using signals of the form {'EXIT', Port, PosixCode}. See file(3) for possible values of PosixCode.
The maximum number of ports that can be open at the same time is 1024 by default, but can be configured by the environment variable ERL_MAX_PORTS.
erlang:phash(Term, Range) -> Hash
Types:
Term = term()
Range = 1..2^32
Hash = 1..Range
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 Term within the range 1..Range.
This BIF could be used instead of the old deprecated erlang:hash/2 BIF, as it calculates better hashes for all data-types, but consider using phash2/1,2 instead.
erlang:phash2(Term [, Range]) -> Hash
Types:
Term = term()
Range = 1..2^32
Hash = 0..Range-1
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 Term within the range 0..Range-1. When called without the Range argument, a value in the range 0..2^27-1 is returned.
This BIF should always be used for hashing terms. It distributes small integers better than phash/2, and it is faster for bignums and binaries.
Note that the range 0..Range-1 is different from the range of phash/2 (1..Range).
Types:
Pid = pid()
Returns a string which corresponds to the text representation of Pid.
This BIF is intended for debugging and for use in the Erlang operating system. It should not be used in application programs.
Types:
Port = port() | atom()
Closes an open port. Roughly the same as Port ! {self(), close} except for the error behaviour (see below), and that the port does not reply with {Port, closed}. Any process may close a port with port_close/1, not only the port owner (the connected process).
For comparison: Port ! {self(), close} fails with badarg if Port cannot be sent to (i.e., Port refers neither to a port nor to a process). If Port is a closed port nothing happens. If Port is an open port and the calling process is the port owner, the port replies with {Port, closed} when all buffers have been flushed and the port really closes, but if the calling process is not the port owner the port owner fails with badsig.
Note that any process can close a port using Port ! {PortOwner, close} just as if it itself was the port owner, but the reply always goes to the port owner.
In short: port_close(Port) has a cleaner and more logical behaviour than Port ! {self(), close}.
Failure: badarg if Port is not an open port or the registered name of an open port.
port_command(Port, Data) -> true
Types:
Port = port() | atom()
Data = iodata()
Sends data to a port. Same as Port ! {self(), {command, Data}} except for the error behaviour (see below). Any process may send data to a port with port_command/2, not only the port owner (the connected process).
For comparison: Port ! {self(), {command, Data}} fails with badarg if Port cannot be sent to (i.e., Port refers neither to a port nor to a process). If Port is a closed port the data message disappears without a sound. If Port is open and the calling process is not the port owner, the port owner fails with badsig. The port owner fails with badsig also if Data is not a valid IO list.
Note that any process can send to a port using Port ! {PortOwner, {command, Data}} just as if it itself was the port owner.
In short: port_command(Port, Data) has a cleaner and more logical behaviour than Port ! {self(), {command, Data}}.
Failure: badarg if Port is not an open port or the registered name of an open port.
port_connect(Port, Pid) -> true
Types:
Port = port() | atom()
Pid = pid()
Sets the port owner (the connected port) to Pid. Roughly the same as Port ! {self(), {connect, Pid}} except for the following:
The old port owner stays linked to the port and have to call unlink(Port) if this is not desired. Any process may set the port owner to be any process with port_connect/2.
For comparison: Port ! {self(), {connect, Pid}} fails with badarg if Port cannot be sent to (i.e., Port refers neither to a port nor to a process). If Port is a closed port nothing happens. If Port is an open port and the calling process is the port owner, the port replies with {Port, connected} to the old port owner. Note that the old port owner is still linked to the port, and that the new is not. If Port is an open port and the calling process is not the port owner, the port owner fails with badsig. The port owner fails with badsig also if Pid is not an existing local pid.
Note that any process can set the port owner using Port ! {PortOwner, {connect, Pid}} just as if it itself was the port owner, but the reply always goes to the port owner.
In short: port_connect(Port, Pid) has a cleaner and more logical behaviour than Port ! {self(),{connect,Pid}}.
Failure: badarg if Port is not an open port or the registered name of an open port, or if Pid is not an existing local pid.
port_control(Port, Operation, Data) -> Res
Types:
Port = port() | atom()
Operation = int()
Data = Res = iodata()
Performs a synchronous control operation on a port. The meaning of Operation and Data depends on the port, i.e., on the port driver. Not all port drivers support this control feature.
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: badarg if Port is not an open port or the registered name of an open port, if Operation cannot fit in a 32-bit integer, if the port driver does not support synchronous control operations, or if the port driver so decides for any reason (probably something wrong with Operation or Data).
erlang:port_call(Port, Operation, Data) -> term()
Types:
Port = port() | atom()
Operation = int()
Data = term()
Performs a synchronous call to a port. The meaning of Operation and Data depends on the port, i.e., on the port driver. Not all port drivers support this feature.
Port is a port identifier, referring to a driver.
Operation is an integer, which is passed on to the driver.
Data is any Erlang term. This data is converted to binary term format and sent to the port.
Returns: a term from the driver. The meaning of the returned data also depends on the port driver.
Failure: badarg if Port is not an open port or the registered name of an open port, if Operation cannot fit in a 32-bit integer, if the port driver does not support synchronous control operations, or if the port driver so decides for any reason (probably something wrong with Operation or Data).
erlang:port_info(Port) -> [{Item, Info}] | undefined
Types:
Port = port() | atom()
Item, Info -- see below
Returns a list containing tuples with information about the Port, or undefined if the port is not open. The order of the tuples is not defined, nor are all the tuples mandatory.
Failure: badarg if Port is not a local port.
erlang:port_info(Port, Item) -> {Item, Info} | undefined | []
Types:
Port = port() | atom()
Item, Info -- see below
Returns information about Port as specified by Item, or undefined if the port is not open. Also, if Item == registered_name and the port has no registered name, [] is returned.
For valid values of Item, and corresponding values of Info, see erlang:port_info/1.
Failure: badarg if Port is not a local port.
erlang:port_to_list(Port) -> string()
Types:
Port = port()
Returns a string which corresponds to the text representation of the port identifier Port.
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.
Types:
Module = atom()
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 init must be pre-loaded.
erlang:process_display(Pid, Type) -> void()
Types:
Pid = pid()
Type = backtrace
Writes information about the local process Pid on standard error. The currently allowed value for the atom Type is backtrace, which shows the contents of the call stack, including information about the call chain, with the current function printed first. The format of the output is not further defined.
process_flag(Flag, Value) -> OldValue
Types:
Flag, Value, OldValue -- see below
Sets certain flags for the process which calls this function. Returns the old value of the flag.
process_flag(Pid, Flag, Value) -> OldValue
Types:
Pid = pid()
Flag, Value, OldValue -- see below
Sets certain flags for the process Pid, in the same manner as process_flag/2. Returns the old value of the flag. The allowed values for Flag are only a subset of those allowed in process_flag/2, namely: save_calls.
Failure: badarg if Pid is not a local process.
process_info(Pid) -> InfoResult
Types:
Pid = pid()
Item = atom()
Info = term()
InfoTuple = {Item, Info}
InfoTupleList = [InfoTuple]
InfoResult = InfoTupleList | undefined
Returns a list containing InfoTuples with miscellaneous information about the process identified by Pid, or undefined if the process is not alive.
The order of the InfoTuples is not defined, nor are all the InfoTuples mandatory. The InfoTuples part of the result may be changed without prior notice. Currently InfoTuples with the following Items are part of the result: current_function, initial_call, status, message_queue_len, messages, links, dictionary, trap_exit, error_handler, priority, group_leader, total_heap_size, heap_size, stack_size, reductions, and garbage_collection. If the process identified by Pid has a registered name also an InfoTuple with Item == registered_name will appear.
See process_info/2 for information about specific InfoTuples.
This BIF is intended for debugging only, use process_info/2 for all other purposes.
Failure: badarg if Pid is not a local process.
process_info(Pid, ItemSpec) -> InfoResult
Types:
Pid = pid()
Item = atom()
Info = term()
ItemList = [Item]
ItemSpec = Item | ItemList
InfoTuple = {Item, Info}
InfoTupleList = [InfoTuple]
InfoResult = InfoTuple | InfoTupleList | undefined | []
Returns information about the process identified by Pid as specified by the ItemSpec, or undefined if the process is not alive.
If the process is alive and ItemSpec is a single Item, the returned value is the corresponding InfoTuple unless ItemSpec == registered_name and the process has no registered name. In this case [] is returned. This strange behavior is due to historical reasons, and is kept for backward compatibility.
If ItemSpec is an ItemList, the result is an InfoTupleList. The InfoTuples in the InfoTupleList will appear with the corresponding Items in the same order as the Items appeared in the ItemList. Valid Items may appear multiple times in the ItemList.
If registered_name is part of an ItemList and the process has no name registered a {registered_name, []} InfoTuple will appear in the resulting InfoTupleList. This behavior is different than when ItemSpec == registered_name, and than when process_info/1 is used.
Currently the following InfoTuples with corresponding Items are valid:
Note however, that not all implementations support every one of the above Items.
Failure: badarg if Pid is not a local process, or if Item is not a valid Item.
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., is_process_alive/1 will return false for a process that is exiting, but its process identifier will be part of the result returned from processes/0.
> processes(). [<0.0.0>,<0.2.0>,<0.4.0>,<0.5.0>,<0.7.0>,<0.8.0>]
purge_module(Module) -> void()
Types:
Module = atom()
Removes old code for Module. Before this BIF is used, erlang:check_process_code/2 should be called to check that no processes are executing old code in the module.
This BIF is intended for the code server (see code(3)) and should not be used elsewhere.
Failure: badarg if there is no old code for Module.
put(Key, Val) -> OldVal | undefined
Types:
Key = Val = OldVal = term()
Adds a new Key to the process dictionary, associated with the value Val, and returns undefined. If Key already exists, the old value is deleted and replaced by Val and the function returns the old value.
The values stored when put is evaluated within the scope of a catch will not be retracted if a throw is evaluated, or if an error occurs.
> X = put(name, walrus), Y = put(name, carpenter), Z = get(name), {X, Y, Z}. {undefined,walrus,carpenter}
erlang:raise(Class, Reason, Stacktrace)
Types:
Class = error | exit | throw
Reason = term()
Stacktrace = [{Module, Function, Arity | Args} | {Fun, Args}]
Module = Function = atom()
Arity = int()
Args = [term()]
Fun = [fun()]
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.
Class is one of error, exit or throw, so if it were not for the stacktrace erlang:raise(Class, Reason, Stacktrace) is equivalent to erlang:Class(Reason). Reason is any term and Stacktrace is a list as returned from get_stacktrace(), that is a list of 3-tuples {Module, Function, Arity | Args} where Module and Function are atoms and the third element is an integer arity or an argument list. The stacktrace may also contain {Fun, Args} tuples where Fun is a local fun and Args is an argument list.
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 badarg. If you want to be really sure not to return you can call erlang:error(erlang:raise(Class, Reason, Stacktrace)) and hope to distinguish exceptions later.
erlang:read_timer(TimerRef) -> int() | false
Types:
TimerRef = ref()
TimerRef is a timer reference returned by erlang:send_after/3 or erlang:start_timer/3. If the timer is active, the function returns the time in milliseconds left until the timer will expire, otherwise false (which means that TimerRef was never a timer, that it has been cancelled, or that it has already delivered its message).
See also erlang:send_after/3, erlang:start_timer/3, and erlang:cancel_timer/1.
erlang:ref_to_list(Ref) -> string()
Types:
Ref = ref()
Returns a string which corresponds to the text representation of Ref.
This BIF is intended for debugging and for use in the Erlang operating system. It should not be used in application programs.
register(RegName, Pid | Port) -> true
Types:
RegName = atom()
Pid = pid()
Port = port()
Associates the name RegName with a pid or a port identifier. RegName, which must be an atom, can be used instead of the pid / port identifier in the send operator (RegName ! Message).
> register(db, Pid). true
Failure: badarg if Pid is not an existing, local process or port, if RegName is already in use, if the process or port is already registered (already has a name), or if RegName is the atom undefined.
Types:
RegName = atom()
Returns a list of names which have been registered using register/2.
> registered(). [code_server, file_server, init, user, my_db]
erlang:resume_process(Suspendee) -> true
Types:
Suspendee = pid()
Decreases the suspend count on the process identified by Suspendee. Suspendee should previously have been suspended via erlang:suspend_process/2, or erlang:suspend_process/1 by the process calling erlang:resume_process(Suspendee). When the suspend count on Suspendee reach zero, Suspendee will be resumed, i.e., the state of the Suspendee is changed from suspended into the state Suspendee was in before it was suspended.
This BIF is intended for debugging only.
Failures:
Types:
Number = number()
Returns an integer by rounding Number.
> 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.
Types:
Dest = pid() | port() | RegName | {RegName, Node}
Msg = term()
RegName = atom()
Node = node()
Sends a message and returns Msg. This is the same as Dest ! Msg.
Dest may be a remote or local pid, a (local) port, a locally registered name, or a tuple {RegName, Node} for a registered name at another node.
erlang:send(Dest, Msg, [Option]) -> Res
Types:
Dest = pid() | port() | RegName | {RegName, Node}
RegName = atom()
Node = node()
Msg = term()
Option = nosuspend | noconnect
Res = ok | nosuspend | noconnect
Sends a message and returns ok, or does not send the message but returns something else (see below). Otherwise the same as erlang:send/2. See also erlang:send_nosuspend/2,3. for more detailed explanation and warnings.
The possible options are:
As with erlang:send_nosuspend/2,3: Use with extreme care!
erlang:send_after(Time, Dest, Msg) -> TimerRef
Types:
Time = int()
0 <= Time <= 4294967295
Dest = pid() | RegName
LocalPid = pid() (of a process, alive or dead, on the local node)
Msg = term()
TimerRef = ref()
Starts a timer which will send the message Msg to Dest after Time milliseconds.
If Dest is an atom, it is supposed to be the name of a registered process. The process referred to by the name is looked up at the time of delivery. No error is given if the name does not refer to a process.
If Dest is a pid, the timer will be automatically canceled if the process referred to by the pid is not alive, or when the process exits. This feature was introduced in erts version 5.4.11. Note that timers will not be automatically canceled when Dest is an atom.
See also erlang:start_timer/3, erlang:cancel_timer/1, and erlang:read_timer/1.
Failure: badarg if the arguments does not satisfy the requirements specified above.
erlang:send_nosuspend(Dest, Msg) -> bool()
Types:
Dest = pid() | port() | RegName | {RegName, Node}
RegName = atom()
Node = node()
Msg = term()
The same as erlang:send(Dest, Msg, [nosuspend]), but returns true if the message was sent and false if the message was not sent because the sender would have had to be suspended.
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 false instead.
The same happens, if Dest refers to a local port that is busy. For all other destinations (allowed for the ordinary send operator '!') this function sends the message and returns true.
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 net_kernel. The normal reaction to take when this happens is some kind of premature shutdown of the other node.
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 false.
Note also that in many systems, transient states of overloaded queues are normal. The fact that this function returns false does not in any way mean that the other node is guaranteed to be non-responsive, it could be a temporary overload. Also a return value of true does only mean that the message could be sent on the (TCP) channel without blocking, the message is not guaranteed to have arrived at the remote node. Also in the case of a disconnected non-responsive node, the return value is true (mimics the behaviour of the ! operator). The expected behaviour as well as the actions to take when the function returns false are application and hardware specific.
Use with extreme care!
erlang:send_nosuspend(Dest, Msg, Options) -> bool()
Types:
Dest = pid() | port() | RegName | {RegName, Node}
RegName = atom()
Node = node()
Msg = term()
Option = noconnect
The same as erlang:send(Dest, Msg, [nosuspend | Options]), but with boolean return value.
This function behaves like erlang:send_nosuspend/2), but takes a third parameter, a list of options. The only currently implemented option is noconnect. The option noconnect makes the function return false if the remote node is not currently reachable by the local node. The normal behaviour is to try to connect to the node, which may stall the process for a shorter period. The use of the noconnect option makes it possible to be absolutely sure not to get even the slightest delay when sending to a remote process. This is especially useful when communicating with nodes who expect to always be the connecting part (i.e. nodes written in C or Java).
Whenever the function returns false (either when a suspend would occur or when noconnect was specified and the node was not already connected), the message is guaranteed not to have been sent.
Use with extreme care!
erlang:set_cookie(Node, Cookie) -> true
Types:
Node = node()
Cookie = atom()
Sets the magic cookie of Node to the atom Cookie. If Node is the local node, the function also sets the cookie of all other unknown nodes to Cookie (see Distributed Erlang in the Erlang Reference Manual).
Failure: function_clause if the local node is not alive.
setelement(Index, Tuple1, Value) -> Tuple2
Types:
Index = 1..tuple_size(Tuple1)
Tuple1 = Tuple2 = tuple()
Value = term()
Returns a tuple which is a copy of the argument Tuple1 with the element given by the integer argument Index (the first element is the element with index 1) replaced by the argument Value.
> setelement(2, {10, green, bottles}, red). {10,red,bottles}
Types:
Item = tuple() | binary()
Returns an integer which is the size of the argument Item, which must be either a tuple or a binary.
> size({morni, mulle, bwange}). 3
Allowed in guard tests.
Types:
Fun = fun()
Returns the pid of a new process started by the application of Fun to the empty list []. Otherwise works like spawn/3.
Types:
Node = node()
Fun = fun()
Returns the pid of a new process started by the application of Fun to the empty list [] on Node. If Node does not exist, a useless pid is returned. Otherwise works like spawn/3.
spawn(Module, Function, Args) -> pid()
Types:
Module = Function = atom()
Args = [term()]
Returns the pid of a new process started by the application of Module:Function to Args. The new process created will be placed in the system scheduler queue and be run some time later.
error_handler:undefined_function(Module, Function, Args) is evaluated by the new process if Module:Function/Arity does not exist (where Arity is the length of Args). The error handler can be redefined (see process_flag/2). If error_handler is undefined, or the user has redefined the default error_handler its replacement is undefined, a failure with the reason undef will occur.
> spawn(speed, regulator, [high_speed, thin_cut]). <0.13.1>
spawn(Node, Module, Function, ArgumentList) -> pid()
Types:
Node = node()
Module = Function = atom()
Args = [term()]
Returns the pid of a new process started by the application of Module:Function to Args on Node. If Node does not exists, a useless pid is returned. Otherwise works like spawn/3.
Types:
Fun = fun()
Returns the pid of a new process started by the application of Fun to the empty list []. A link is created between the calling process and and the new process, atomically. Otherwise works like spawn/3.
Types:
Node = node()
Fun = fun()
Returns the pid of a new process started by the application of Fun to the empty list [] on Node. A link is created between the calling process and and the new process, atomically. If Node does not exist, a useless pid is returned (and due to the link, an exit signal with exit reason noconnection will be received). Otherwise works like spawn/3.
spawn_link(Module, Function, Args) -> pid()
Types:
Module = Function = atom()
Args = [term()]
Returns the pid of a new process started by the application of Module:Function to Args. A link is created between the calling process and the new process, atomically. Otherwise works like spawn/3.
spawn_link(Node, Module, Function, Args) -> pid()
Types:
Node = node()
Module = Function = atom()
Args = [term()]
Returns the pid of a new process started by the application of Module:Function to Args on Node. A link is created between the calling process and the new process, atomically. If Node does not exist, a useless pid is returned (and due to the link, an exit signal with exit reason noconnection will be received). Otherwise works like spawn/3.
spawn_monitor(Fun) -> {pid(),reference()}
Types:
Fun = fun()
Returns the pid of a new process started by the application of Fun to the empty list [] and reference for a monitor created to the new process. Otherwise works like spawn/3.
spawn_monitor(Module, Function, Args) -> {pid(),reference()}
Types:
Module = Function = atom()
Args = [term()]
A new process is started by the application of Module:Function to Args, and the process is monitored at the same time. Returns the pid and a reference for the monitor. Otherwise works like spawn/3.
spawn_opt(Fun, [Option]) -> pid() | {pid(),reference()}
Types:
Fun = fun()
Option = link | monitor | {priority, Level} | {fullsweep_after, Number} | {min_heap_size, Size}
Level = low | normal | high
Number = int()
Size = int()
Returns the pid of a new process started by the application of Fun to the empty list []. Otherwise works like spawn_opt/4.
If the option monitor is given, the newly created process will be monitored and both the pid and reference for the monitor will be returned.
spawn_opt(Node, Fun, [Option]) -> pid()
Types:
Node = node()
Fun = fun()
Option = link | {priority, Level} | {fullsweep_after, Number} | {min_heap_size, Size}
Level = low | normal | high
Number = int()
Size = int()
Returns the pid of a new process started by the application of Fun to the empty list [] on Node. If Node does not exist, a useless pid is returned. Otherwise works like spawn_opt/4.
spawn_opt(Module, Function, Args, [Option]) -> pid() | {pid(),reference()}
Types:
Module = Function = atom()
Args = [term()]
Option = link | monitor | {priority, Level} | {fullsweep_after, Number} | {min_heap_size, Size}
Level = low | normal | high
Number = int()
Size = int()
Works exactly like spawn/3, except that an extra option list is given when creating the process.
If the option monitor is given, the newly created process will be monitored and both the pid and reference for the monitor will be returned.
spawn_opt(Node, Module, Function, Args, [Option]) -> pid()
Types:
Node = node()
Module = Function = atom()
Args = [term()]
Option = link | {priority, Level} | {fullsweep_after, Number} | {min_heap_size, Size}
Level = low | normal | high
Number = int()
Size = int()
Returns the pid of a new process started by the application of Module:Function to Args on Node. If Node does not exist, a useless pid is returned. Otherwise works like spawn_opt/4.
split_binary(Bin, Pos) -> {Bin1, Bin2}
Types:
Bin = Bin1 = Bin2 = binary()
Pos = 1..byte_size(Bin)
Returns a tuple containing the binaries which are the result of splitting Bin into two parts at position Pos. This is not a destructive operation. After the operation, there will be three binaries altogether.
> 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
erlang:start_timer(Time, Dest, Msg) -> TimerRef
Types:
Time = int()
0 <= Time <= 4294967295
Dest = LocalPid | RegName
LocalPid = pid() (of a process, alive or dead, on the local node)
RegName = atom()
Msg = term()
TimerRef = ref()
Starts a timer which will send the message {timeout, TimerRef, Msg} to Dest after Time milliseconds.
If Dest is an atom, it is supposed to be the name of a registered process. The process referred to by the name is looked up at the time of delivery. No error is given if the name does not refer to a process.
If Dest is a pid, the timer will be automatically canceled if the process referred to by the pid is not alive, or when the process exits. This feature was introduced in erts version 5.4.11. Note that timers will not be automatically canceled when Dest is an atom.
See also erlang:send_after/3, erlang:cancel_timer/1, and erlang:read_timer/1.
Failure: badarg if the arguments does not satisfy the requirements specified above.
Types:
Type, Res -- see below
Returns information about the system as specified by Type:
All times are in milliseconds.
> statistics(runtime). {1690,1620} > statistics(reductions). {2046,11} > statistics(garbage_collection). {85,23961,0}
erlang:suspend_process(Suspendee, OptList) -> true | false
Types:
Suspendee = pid()
OptList = [Opt]
Opt = atom()
Increases the suspend count on the process identified by Suspendee and puts it in the suspended state if it isn't already in the suspended state. A suspended process will not be scheduled for execution until the process has been resumed.
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 Suspendee is decreased when erlang:resume_process(Suspendee) is called by the same process that called erlang:suspend_process(Suspendee). All increased suspend counts on other processes acquired by a process will automatically be decreased when the process terminates.
Currently the following options (Opts) are available:
If the suspend count on the process identified by Suspendee was increased, true is returned; otherwise, false is returned.
This BIF is intended for debugging only.
Failures:
erlang:suspend_process(Suspendee) -> true
Types:
Suspendee = pid()
Suspends the process identified by Suspendee. The same as calling erlang:suspend_process(Suspendee, []). For more information see the documentation of erlang:suspend_process/2.
This BIF is intended for debugging only.
erlang:system_flag(Flag, Value) -> OldValue
Types:
Flag, Value, OldValue -- see below
Sets various system properties of the Erlang node. Returns the old value of the flag.
The schedulers option has been removed as of erts version 5.5.3. The number of scheduler threads is determined at emulator boot time, and cannot be changed after that.
erlang:system_info(Type) -> Res
Types:
Type, Res -- see below
Returns various information about the current system (emulator) as specified by Type:
The scheduler argument has changed name to scheduler_id. This in order to avoid mixup with the schedulers argument. The scheduler argument was introduced in ERTS version 5.5 and renamed in ERTS version 5.5.1.
erlang:system_monitor() -> MonSettings
Types:
MonSettings -> {MonitorPid, Options} | undefined
MonitorPid = pid()
Options = [Option]
Option = {long_gc, Time} | {large_heap, Size} | busy_port | busy_dist_port
Time = Size = int()
Returns the current system monitoring settings set by erlang:system_monitor/2 as {MonitorPid, Options}, or undefined if there are no settings. The order of the options may be different from the one that was set.
erlang:system_monitor(undefined | {MonitorPid, Options}) -> MonSettings
Types:
MonitorPid, Options, MonSettings -- see below
When called with the argument undefined, all system performance monitoring settings are cleared.
Calling the function with {MonitorPid, Options} as argument, is the same as calling erlang:system_monitor(MonitorPid, Options).
Returns the previous system monitor settings just like erlang:system_monitor/0.
erlang:system_monitor(MonitorPid, [Option]) -> MonSettings
Types:
MonitorPid = pid()
Option = {long_gc, Time} | {large_heap, Size} | busy_port | busy_dist_port
Time = Size = int()
MonSettings = {OldMonitorPid, [Option]}
OldMonitorPid = pid()
Sets system performance monitoring options. MonitorPid is a local pid that will receive system monitor messages, and the second argument is a list of monitoring options:
Returns the previous system monitor settings just like erlang:system_monitor/0.
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: badarg if MonitorPid does not exist.
erlang:system_profile() -> ProfilerSettings
Types:
ProfilerSettings -> {ProfilerPid, Options} | undefined
ProfilerPid = pid() | port()
Options = [Option]
Option = runnable_procs | runnable_ports | scheduler | exclusive
Returns the current system profiling settings set by erlang:system_profile/2 as {ProfilerPid, Options}, or undefined if there are no settings. The order of the options may be different from the one that was set.
erlang:system_profile(ProfilerPid, Options) -> ProfilerSettings
Types:
ProfilerSettings -> {ProfilerPid, Options} | undefined
ProfilerPid = pid() | port()
Options = [Option]
Option = runnable_procs | runnable_ports | scheduler | exclusive
Sets system profiler options. ProfilerPid is a local pid or port that will receive profiling messages. The receiver is excluded from all profiling. The second argument is a list of profiling options:
erlang:system_profile is considered experimental and its behaviour may change in the future.
term_to_binary(Term) -> ext_binary()
Types:
Term = term()
Returns a binary data object which is the result of encoding Term according to the Erlang external term format.
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 binary_to_term/1.
term_to_binary(Term, [Option]) -> ext_binary()
Types:
Term = term()
Option = compressed | {compressed,Level} | {minor_version,Version}
Returns a binary data object which is the result of encoding Term according to the Erlang external term format.
If the option compressed is provided, the external term format will be compressed. The compressed format is automatically recognized by binary_to_term/1 in R7B and later.
It is also possible to specify a compression level by giving the option {compressed,Level}, where Level is an integer from 0 through 9. 0 means that no compression will be done (it is the same as not giving any compressed option); 1 will take the least time but may not compress as well as the higher levels; 9 will take the most time and may produce a smaller result. Note the "mays" in the preceding sentence; depending on the input term, level 9 compression may or may not produce a smaller result than level 1 compression.
Currently, compressed gives the same result as {compressed,6}.
The option {minor_version,Version} can be use to control some details of the encoding. This option was introduced in R11B-4. Currently, the allowed values for Version are 0 and 1.
{minor_version,1} forces any floats in the term to be encoded in a more space-efficient and exact way (namely in the 64-bit IEEE format, rather than converted to a textual representation). binary_to_term/1 in R11B-4 and later is able decode the new representation.
{minor_version,0} is currently the default, meaning that floats will be encoded using a textual representation; this option is useful if you want to ensure that releases prior to R11B-4 can decode resulting binary.
See also binary_to_term/1.
Types:
Any = term()
A non-local return from a function. If evaluated within a catch, catch will return the value Any.
> catch throw({hello, there}). {hello,there}
Failure: nocatch if not evaluated within a catch.
time() -> {Hour, Minute, Second}
Types:
Hour = Minute = Second = int()
Returns the current time as {Hour, Minute, Second}.
The time zone and daylight saving time correction depend on the underlying OS.
> time(). {9,42,44}
Types:
List1 = List2 = [term()]
Returns the tail of List1, that is, the list minus the first element.
> tl([geesties, guilies, beasties]). [guilies, beasties]
Allowed in guard tests.
Failure: badarg if List is the empty list [].
erlang:trace(PidSpec, How, FlagList) -> int()
Types:
PidSpec = pid() | existing | new | all
How = bool()
FlagList = [Flag]
Flag -- see below
Turns on (if How == true) or off (if How == false) the trace flags in FlagList for the process or processes represented by PidSpec.
PidSpec is either a pid for a local process, or one of the following atoms:
FlagList can contain any number of the following flags (the "message tags" refers to the list of messages following below):
The effect of combining set_on_first_link with set_on_link is the same as having set_on_first_link alone. Likewise for set_on_spawn and set_on_first_spawn.
If the timestamp flag is not given, the tracing process will receive the trace messages described below. Pid is the pid of the traced process in which the traced event has occurred. The third element of the tuple is the message tag.
If the timestamp flag is given, the first element of the tuple will be trace_ts instead and the timestamp is added last in the tuple.
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 PidSpec. If PidSpec is a pid, the return value will be 1. If PidSpec is all or existing the return value will be the number of processes running, excluding tracer processes. If PidSpec is new, the return value will be 0.
Failure: If specified arguments are not supported. For example cpu_timestamp is not supported on all platforms.
erlang:trace_delivered(Tracee) -> Ref
Types:
Tracee = pid() | all
Ref = reference()
The delivery of trace messages is dislocated on the time-line compared to other events in the system. If you know that the Tracee has passed some specific point in its execution, and you want to know when at least all trace messages corresponding to events up to this point have reached the tracer you can use erlang:trace_delivered(Tracee). A {trace_delivered, Tracee, Ref} message is sent to the caller of erlang:trace_delivered(Tracee) when it is guaranteed that all trace messages have been delivered to the tracer up to the point that the Tracee had reached at the time of the call to erlang:trace_delivered(Tracee).
Note that the trace_delivered message does not imply that trace messages have been delivered; instead, it implies that all trace messages that should be delivered have been delivered. It is not an error if Tracee isn't, and hasn't been traced by someone, but if this is the case, no trace messages will have been delivered when the trace_delivered message arrives.
Note that Tracee has to refer to a process currently, or previously existing on the same node as the caller of erlang:trace_delivered(Tracee) resides on. The special Tracee atom all denotes all processes that currently are traced in the node.
An example: Process A is tracee, port B is tracer, and process C is the port owner of B. C wants to close B when A exits. C can ensure that the trace isn't truncated by calling erlang:trace_delivered(A) when A exits and wait for the {trace_delivered, A, Ref} message before closing B.
Failure: badarg if Tracee does not refer to a process (dead or alive) on the same node as the caller of erlang:trace_delivered(Tracee) resides on.
erlang:trace_info(PidOrFunc, Item) -> Res
Types:
PidOrFunc = pid() | new | {Module, Function, Arity} | on_load
Module = Function = atom()
Arity = int()
Item, Res -- see below
Returns trace information about a process or function.
To get information about a process, PidOrFunc should be a pid or the atom new. The atom new means that the default trace state for processes to be created will be returned. Item must have one of the following values:
To get information about a function, PidOrFunc should be a three-element tuple: {Module, Function, Arity} or the atom on_load. No wildcards are allowed. Returns undefined if the function does not exist or false if the function is not traced at all. Item must have one of the following values:
The actual return value will be {Item, Value}, where Value is the requested information as described above. If a pid for a dead process was given, or the name of a non-existing function, Value will be undefined.
If PidOrFunc is the on_load, the information returned refers to the default value for code that will be loaded.
erlang:trace_pattern(MFA, MatchSpec) -> int()
The same as erlang:trace_pattern(MFA, MatchSpec, []), retained for backward compatibility.
erlang:trace_pattern(MFA, MatchSpec, FlagList) -> int()
Types:
MFA, MatchSpec, FlagList -- see below
This BIF is used to enable or disable call tracing for exported functions. It must be combined with erlang:trace/3 to set the call trace flag for one or more processes.
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 erlang:trace/3 to add or remove one or more processes to the set of traced processes. Use erlang:trace_pattern/2 to add or remove exported functions to the set of traced functions.
The erlang:trace_pattern/3 BIF can also add match specifications to an exported function. A match specification comprises a pattern that the arguments to the function must match, a guard expression which must evaluate to true and an action to be performed. The default action is to send a trace message. If the pattern does not match or the guard fails, the action will not be executed.
The MFA argument should be a tuple like {Module, Function, Arity} or the atom on_load (described below). It can be the module, function, and arity for an exported function (or a BIF in any module). The '_' atom can be used to mean any of that kind. Wildcards can be used in any of the following ways:
Other combinations, such as {Module,'_',Arity}, are not allowed. Local functions will match wildcards only if the local option is in the FlagList.
If the MFA argument is the atom on_load, the match specification and flag list will be used on all modules that are newly loaded.
The MatchSpec argument can take any of the following forms:
The FlagList parameter is a list of options. The following options are allowed:
The global and local options are mutually exclusive and global is the default (if no options are specified). The call_count and meta options perform a kind of local tracing, and can also not be combined with global. A function can be either globally or locally traced. If global tracing is specified for a specified set of functions; local, meta and call count tracing for the matching set of local functions will be disabled, and vice versa.
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 local option and global tracing with the global option (or no option at all), and so forth.
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 erlang:trace_info/2 BIF to retrieve the existing match specification.
Returns the number of exported functions that matched the MFA argument. This will be zero if none matched at all.
Types:
Number = number()
Returns an integer by the truncating Number.
> trunc(5.5). 5
Allowed in guard tests.
Types:
Tuple = tuple()
Returns an integer which is the number of elements in Tuple.
> tuple_size({morni, mulle, bwange}). 3
Allowed in guard tests.
tuple_to_list(Tuple) -> [term()]
Types:
Tuple = tuple()
Returns a list which corresponds to Tuple. Tuple may contain any Erlang terms.
> tuple_to_list({share, {'Ericsson_B', 163}}). [share,{'Ericsson_B',163}]
erlang:universaltime() -> {Date, Time}
Types:
Date = {Year, Month, Day}
Time = {Hour, Minute, Second}
Year = Month = Day = Hour = Minute = Second = int()
Returns the current date and time according to Universal Time Coordinated (UTC), also called GMT, in the form {{Year, Month, Day}, {Hour, Minute, Second}} if supported by the underlying operating system. If not, erlang:universaltime() is equivalent to erlang:localtime().
> erlang:universaltime(). {{1996,11,6},{14,18,43}}
erlang:universaltime_to_localtime({Date1, Time1}) -> {Date2, Time2}
Types:
Date1 = Date2 = {Year, Month, Day}
Time1 = Time2 = {Hour, Minute, Second}
Year = Month = Day = Hour = Minute = Second = int()
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 {Date1, Time1} is returned.
> erlang:universaltime_to_localtime({{1996,11,6},{14,18,43}}). {{1996,11,7},{15,18,43}}
Failure: badarg if Date1 or Time1 do not denote a valid date or time.
Types:
Id = pid() | port()
Removes the link, if there is one, between the calling process and the process or port referred to by Id.
Returns true and does not fail, even if there is no link to Id, or if Id does not exist.
Once unlink(Id) has returned it is guaranteed that the link between the caller and the entity referred to by Id has no effect on the caller in the future (unless the link is setup again). If caller is trapping exits, an {'EXIT', Id, _} message due to the link might have been placed in the callers message queue prior to the call, though. Note, the {'EXIT', Id, _} message can be the result of the link, but can also be the result of Id calling exit/2. Therefore, it may be appropriate to cleanup the message queue when trapping exits after the call to unlink(Id), as follow:
unlink(Id), receive {'EXIT', Id, _} -> true after 0 -> true end
Prior to OTP release R11B (erts version 5.5) unlink/1 behaved completely asynchronous, i.e., the link was active until the "unlink signal" reached the linked entity. This had one undesirable effect, though. You could never know when you were guaranteed not to be effected by the link.
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.
Types:
RegName = atom()
Removes the registered name RegName, associated with a pid or a port identifier.
> unregister(db). true
Users are advised not to unregister system processes.
Failure: badarg if RegName is not a registered name.
whereis(RegName) -> pid() | port() | undefined
Returns the pid or port identifier with the registered name RegName. Returns undefined if the name is not registered.
> whereis(db). <0.43.0>
Voluntarily let other processes (if any) get a chance to execute. Using erlang:yield() is similar to receive after 1 -> ok end, except that yield() is faster.