Process

Conveniences for working with processes and the process dictionary.

Some of the functions in this module are inlined by the compiler, similar to functions in the Kernel module and they are explicitly marked in their docs as "inlined by the compiler". For more information about inlined functions, check out the Kernel module.

Source

Summary

alive?(pid)

Returns true if the process exists and is alive, that is, is not exiting and has not exited. Otherwise, returns false

delete()

Deletes all items in the dictionary

delete(key)

Deletes the given key from the dictionary

demonitor(monitor_ref, options \\ [])

If monitor_ref is a reference which the calling process obtained by calling monitor/1, this monitoring is turned off. If the monitoring is already turned off, nothing happens

exit(pid, reason)

Sends an exit signal with the given reason to the pid

flag(flag, value)

Sets certain flags for the process which calls this function. Returns the old value of the flag

flag(pid, flag, value)

Sets certain flags for the process Pid, in the same manner as flag/2. Returns the old value of the flag. The allowed values for Flag are only a subset of those allowed in flag/2, namely: save_calls

get()

Returns all key-values in the dictionary

get(key, default \\ nil)

Returns the value for the given key

get_keys(value)

Returns all keys that have the given value

group_leader()

Returns the pid of the group leader for the process which evaluates the function

group_leader(pid, leader)

Sets the group leader of pid to leader. Typically, this is used when a processes started from a certain shell should have another group leader than :init

info(pid)

Returns information about the process identified by pid or nil if the process is not alive. Use this only for debugging information

info(pid, spec)

Returns information about the process identified by pid or nil if the process is not alive

link(pid)

Creates a link between the calling process and another process (or port) pid, if there is not such a link already

list()

Returns a list of process identifiers corresponding to all the processes currently existing on the local node

monitor(item)

The calling process starts monitoring the item given. It returns the monitor reference

put(key, value)

Stores the given key-value in the process dictionary

register(pid, name)

Associates the name with a pid or a port identifier. name, which must be an atom, can be used instead of the pid / port identifier with the Kernel.send/2 function

registered()

Returns a list of names which have been registered using register/2

self()

Returns the pid (process identifier) of the calling process

send(dest, msg)

Sends a message to the given process

send_after(dest, msg, time)

Sends msg to dest after time millisecons

spawn(fun)

Returns the pid of a new process started by the application of fun. It behaves exactly the same as Kernel.spawn/1

spawn(fun, opts)

Returns the pid of a new process started by the application of fun

spawn(mod, fun, args)

Returns the pid of a new process started by the application of module.function(args). The new process created will be placed in the system scheduler queue and be run some time later

spawn(mod, fun, args, opts)

Returns the pid of a new process started by the application of module.function(args). The new process created will be placed in the system scheduler queue and be run some time later

spawn_link(fun)

Returns the pid of a new process started by the application of fun. A link is created between the calling process and the new process, atomically

spawn_link(mod, fun, args)

Returns the pid of a new process started by the application of module.function(args). A link is created between the calling process and the new process, atomically. Otherwise works like spawn/3

spawn_monitor(fun)

Returns the pid of a new process started by the application of fun and reference for a monitor created to the new process

spawn_monitor(mod, fun, args)

A new process is started by the application of module.function(args) and the process is monitored at the same time. Returns the pid and a reference for the monitor. Otherwise works like spawn/3

unlink(pid)

Removes the link, if there is one, between the calling process and the process or port referred to by pid. Returns true and does not fail, even if there is no link or id does not exist

unregister(name)

Removes the registered name, associated with a pid or a port identifier

whereis(name)

Returns the pid or port identifier with the registered name. Returns nil if the name is not registered

Types

spawn_opt :: :link | :monitor | {:priority, :low | :normal | :high} | {:fullsweep_after, non_neg_integer} | {:min_heap_size, non_neg_integer} | {:min_bin_vheap_size, non_neg_integer}

Functions

alive?(pid)

Specs:

  • alive?(pid) :: boolean

Returns true if the process exists and is alive, that is, is not exiting and has not exited. Otherwise, returns false.

pid must refer to a process at the local node.

Source
delete()

Specs:

  • delete :: [{term, term}]

Deletes all items in the dictionary.

Source
delete(key)

Specs:

  • delete(term) :: term | nil

Deletes the given key from the dictionary.

Source
demonitor(monitor_ref, options \\ [])

Specs:

  • demonitor(reference, options :: [:flush | :info]) :: boolean

If monitor_ref is a reference which the calling process obtained by calling monitor/1, this monitoring is turned off. If the monitoring is already turned off, nothing happens.

See http://www.erlang.org/doc/man/erlang.html#demonitor-2 for more info.

Inlined by the compiler.

Source
exit(pid, reason)

Specs:

  • exit(pid, term) :: true

Sends an exit signal with the given reason to the pid.

The following behaviour applies if reason is any term except :normal or :kill:

1) If pid is not trapping exits, pid will exit with the given reason;

2) If pid is trapping exits, the exit signal is transformed into a message {:EXIT, from, reason} and delivered to the message queue of pid;

3) 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;

4) 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.

Inlined by the compiler.

Examples

Process.exit(pid, :kill)
Source
flag(flag, value)

Specs:

  • flag(process_flag, term) :: term

Sets certain flags for the process which calls this function. Returns the old value of the flag.

See http://www.erlang.org/doc/man/erlang.html#process_flag-2 for more info.

Source
flag(pid, flag, value)

Specs:

  • flag(pid, process_flag, term) :: term

Sets certain flags for the process Pid, in the same manner as flag/2. Returns the old value of the flag. The allowed values for Flag are only a subset of those allowed in flag/2, namely: save_calls.

See http://www.erlang.org/doc/man/erlang.html#process_flag-3 for more info.

Source
get()

Specs:

  • get :: [{term, term}]

Returns all key-values in the dictionary.

Source
get(key, default \\ nil)

Specs:

  • get(term, default :: term) :: term

Returns the value for the given key.

Source
get_keys(value)

Specs:

  • get_keys(term) :: [term]

Returns all keys that have the given value.

Source
group_leader()

Specs:

  • group_leader :: pid

Returns the pid of the group leader for the process which evaluates the function.

Source
group_leader(pid, leader)

Specs:

  • group_leader(pid, leader :: pid) :: true

Sets the group leader of pid to leader. Typically, this is used when a processes started from a certain shell should have another group leader than :init.

Source
info(pid)

Specs:

Returns information about the process identified by pid or nil if the process is not alive. Use this only for debugging information.

See http://www.erlang.org/doc/man/erlang.html#process_info-1 for more info.

Source
info(pid, spec)

Specs:

  • info(pid, atom) :: {atom, term}

Returns information about the process identified by pid or nil if the process is not alive.

See http://www.erlang.org/doc/man/erlang.html#process_info-2 for more info.

Source
link(pid)

Specs:

  • link(pid | port) :: true

Creates a link between the calling process and another process (or port) pid, if there is not such a link already.

See http://www.erlang.org/doc/man/erlang.html#link-1 for more info.

Inlined by the compiler.

Source
list()

Specs:

  • list :: [pid]

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., alive?/1 will return false for a process that is exiting, but its process identifier will be part of the result returned.

See http://www.erlang.org/doc/man/erlang.html#processes-0 for more info.

Source
monitor(item)

Specs:

  • monitor(pid | {reg_name :: atom, node :: atom} | reg_name :: atom) :: reference

The calling process starts monitoring the item given. It returns the monitor reference.

See http://www.erlang.org/doc/man/erlang.html#monitor-2 for more info.

Inlined by the compiler.

Source
put(key, value)

Specs:

  • put(term, term) :: term | nil

Stores the given key-value in the process dictionary.

Source
register(pid, name)

Specs:

  • register(pid | port, atom) :: true

Associates the name with a pid or a port identifier. name, which must be an atom, can be used instead of the pid / port identifier with the Kernel.send/2 function.

See http://www.erlang.org/doc/man/erlang.html#register-2 for more info.

Source
registered()

Specs:

  • registered :: [atom]

Returns a list of names which have been registered using register/2.

Source
self()

Specs:

  • self :: pid

Returns the pid (process identifier) of the calling process.

Source
send(dest, msg)

Specs:

  • send(dest, msg) :: msg when dest: pid | port | atom | {atom, node}, msg: any

Sends a message to the given process.

It does the same as Kernel.send/2.

Source
send_after(dest, msg, time)

Specs:

  • send_after(pid | atom, term, non_neg_integer) :: reference

Sends msg to dest after time millisecons.

If dest is a pid, it has to be a pid of a local process, dead or alive. If dest is an atom, it is supposed to be the name of a registered process which is looked up at the time of delivery. No error is given if the name does not refer to a process.

This function returns a timer reference, which can be read or canceled with :erlang.read_timer/1, :erlang.start_timer/3 and :erlang.cancel_timer/1. Note time cannot be greater than 4294967295.

Finally, the timer will be automatically canceled if the given dest is a pid which is not alive or when the given pid exits. Note that timers will not be automatically canceled when dest is an atom (as the atom resolution is done on delivery).

Source
spawn(fun)

Specs:

  • spawn((() -> any)) :: pid

Returns the pid of a new process started by the application of fun. It behaves exactly the same as Kernel.spawn/1.

Inlined by the compiler.

Source
spawn(fun, opts)

Specs:

  • spawn((() -> any), spawn_opts) :: pid | {pid, reference}

Returns the pid of a new process started by the application of fun.

It also accepts extra options, for the list of available options check http://www.erlang.org/doc/man/erlang.html#spawn_opt-2

Inlined by the compiler.

Source
spawn(mod, fun, args)

Specs:

  • spawn(module, atom, [any]) :: pid

Returns the pid of a new process started by the application of module.function(args). The new process created will be placed in the system scheduler queue and be run some time later.

It behaves exactly the same as the Kernel.spawn/3 function.

Inlined by the compiler.

Source
spawn(mod, fun, args, opts)

Specs:

  • spawn(module, atom, [any], spawn_opts) :: pid | {pid, reference}

Returns the pid of a new process started by the application of module.function(args). The new process created will be placed in the system scheduler queue and be run some time later.

It also accepts extra options, for the list of available options check http://www.erlang.org/doc/man/erlang.html#spawn_opt-4

Inlined by the compiler.

Source
spawn_link(fun)

Specs:

  • spawn_link((() -> any)) :: pid

Returns the pid of a new process started by the application of fun. A link is created between the calling process and the new process, atomically.

Inlined by the compiler.

Source
spawn_link(mod, fun, args)

Specs:

  • spawn_link(module, atom, [any]) :: pid

Returns the pid of a new process started by the application of module.function(args). A link is created between the calling process and the new process, atomically. Otherwise works like spawn/3.

Inlined by the compiler.

Source
spawn_monitor(fun)

Specs:

  • spawn_monitor((() -> any)) :: {pid, reference}

Returns the pid of a new process started by the application of fun and reference for a monitor created to the new process.

Inlined by the compiler.

Source
spawn_monitor(mod, fun, args)

Specs:

  • spawn_monitor(module, atom, [any]) :: {pid, reference}

A new process is started by the application of module.function(args) and the process is monitored at the same time. Returns the pid and a reference for the monitor. Otherwise works like spawn/3.

Inlined by the compiler.

Source
unlink(pid)

Specs:

  • unlink(pid | port) :: true

Removes the link, if there is one, between the calling process and the process or port referred to by pid. Returns true and does not fail, even if there is no link or id does not exist

See http://www.erlang.org/doc/man/erlang.html#unlink-1 for more info.

Inlined by the compiler.

Source
unregister(name)

Specs:

  • unregister(atom) :: true

Removes the registered name, associated with a pid or a port identifier.

See http://www.erlang.org/doc/man/erlang.html#unregister-1 for more info.

Source
whereis(name)

Specs:

  • whereis(atom) :: pid | port | nil

Returns the pid or port identifier with the registered name. Returns nil if the name is not registered.

See http://www.erlang.org/doc/man/erlang.html#whereis-1 for more info.

Source