erl
The Erlang Emulator
- Provided by: erlang-base (Version: 1:16.b.3-dfsg-1ubuntu2.2)
- Source: erlang
- Report a bug
The Erlang Emulator
The erl program starts an Erlang runtime system. The exact details (for example, whether erl is a script or a program and which other programs it calls) are system-dependent.
Windows users probably wants to use the werl program instead, which runs in its own window with scrollbars and supports command-line editing. The erl program on Windows provides no line editing in its shell, and on Windows 95 there is no way to scroll back to text which has scrolled off the screen. The erl program must be used, however, in pipelines or if you want to redirect standard input or output.
erl <arguments>
Starts an Erlang runtime system.
The arguments can be divided into emulator flags, flags and plain arguments:
As indicated by the name, emulator flags controls the behavior of the emulator.
The init process itself interprets some of these flags, the init flags. It also stores any remaining flags, the user flags. The latter can be retrieved by calling init:get_argument/1.
It can be noted that there are a small number of "-" flags which now actually are emulator flags, see the description below.
Example:
% erl +W w -sname arnie +R 9 -s my_init -extra +bertie
(arnie@host)1> init:get_argument(sname).
{ok,[["arnie"]]}
(arnie@host)2> init:get_plain_arguments().
["+bertie"]
Here +W w and +R 9 are emulator flags. -s my_init is an init flag, interpreted by init. -sname arnie is a user flag, stored by init. It is read by Kernel and will cause the Erlang runtime system to become distributed. Finally, everything after -extra (that is, +bertie) is considered as plain arguments.
% erl -myflag 1
1> init:get_argument(myflag).
{ok,[["1"]]}
2> init:get_plain_arguments().
[]
Here the user flag -myflag 1 is passed to and stored by the init process. It is a user defined flag, presumably used by some user defined application.
In the following list, init flags are marked (init flag). Unless otherwise specified, all other flags are user flags, for which the values can be retrieved by calling init:get_argument/1. Note that the list of user flags is not exhaustive, there may be additional, application specific flags which instead are documented in the corresponding application documentation.
The file FileName should be a plain text file and may contain comments and command line arguments. A comment begins with a # character and continues until next end of line character. Backslash (\\) is used as quoting character. All command line arguments accepted by erl are allowed, also the -args_file FileName flag. Be careful not to cause circular dependencies between files containing the -args_file flag, though.
The -extra flag is treated specially. Its scope ends at the end of the file. Arguments following an -extra flag are moved on the command line into the -extra section, i.e. the end of the command line following after an -extra flag.
Defaults to $ROOT/bin/start.boot.
% erl -env DISPLAY gin:0
In this example, an Erlang runtime system is started with the DISPLAY environment variable set to gin:0.
The IP addresses must be given in the standard form (four decimal numbers separated by periods, for example "150.236.20.74". Hosts names are not acceptable, but a broadcast address (preferably limited to the local network) is.
The name of the node will be Name@Host, where Host is the fully qualified host name of the current host. For short names, use the -sname flag instead.
This is sometimes the only way to run distributed Erlang if the DNS (Domain Name System) is not running. There can be no communication between nodes running with the -sname flag and those running with the -name flag, as node names must be unique in distributed Erlang systems.
NOTE: The runtime system with SMP support will not be available on all supported platforms. See also the +S flag.
erl invokes the code for the Erlang emulator (virtual machine), which supports the following flags:
If the c option is used with oldshell on Unix, Ctrl-C will restart the shell process rather than interrupt it.
Note that on Windows, this flag is only applicable for werl, not erl (oldshell). Note also that Ctrl-Break is used instead of Ctrl-C on Windows.
Normally, erlang:now/0 will not immediately reflect sudden changes in the system time, in order to keep timers (including receive-after) working. Instead, the time maintained by erlang:now/0 is slowly adjusted towards the new system time. (Slowly means in one percent adjustments; if the time is off by one minute, the time will be adjusted in 100 minutes.)
When the +c option is given, this slow adjustment will not take place. Instead erlang:now/0 will always reflect the current system time. Note that timers are based on erlang:now/0. If the system time jumps, timers then time out at the wrong time.
The +d option instructs the emulator to only produce a core dump and no crash dump if an internal error is detected.
Calling erlang:halt/1 with a string argument will still produce a crash dump.
See STDLIB User's Guide for more infomation about unicode file names.
The +fnu switch can be followed by w, i, or e to control the way wrongly encoded file names are to be reported. w means that a warning is sent to the error_logger whenever a wrongly encoded file name is "skipped" in directory listings, i means that those wrongly encoded file names are silently ignored and e means that the API function will return an error whenever a wrongly encoded file (or directory) name is encountered. w is the default. Note that file:read_link/1 will always return an error if the link points to an invalid file name.
See STDLIB User's Guide for more infomation about unicode file names.
The +fna switch can be followed by w, i, or e. This will have effect if the locale settings cause the behavior of +fnu to be selected. See the description of +fnu above. If the locale settings cause the behavior of +fnl to be selected, then w, i, or e will not have any effect.
See STDLIB User's Guide for more infomation about unicode file names.
As of OTP-R16 signals to ports are truly asynchronously delivered. Note that signals always have been documented as asynchronous. The underlying implementation has, however, previously delivered these signals synchronously. Correctly written Erlang programs should be able to handle this without any issues. Bugs in existing Erlang programs that make false assumptions about signals to ports may, however, be tricky to find. This switch has been introduced in order to at least make it easier to compare behaviors during a transition period. Note that this flag is deprecated as of its introduction, and is scheduled for removal in OTP-R17. Behavior should be one of the following characters:
Currently two values for the Range are supported:
Se also io:printable_range/0.
NOTE: The actual maximum chosen may be much larger than the Number passed. Currently the runtime system often, but not always, chooses a value that is a power of 2. This might, however, be changed in the future. The actual value chosen can be checked by calling erlang:system_info(process_limit).
The default value is 262144
If legacy is passed as value, the legacy algorithm for allocation of process identifiers will be used. Using the legacy algorithm, identifiers will be allocated in a strictly increasing fashion until largest possible identifier has been reached. Note that this algorithm suffers from performance issues and can under certain circumstances be extremely expensive. The legacy algoritm is deprecated, and the legacy option is scheduled for removal in OTP-R18.
NOTE: The actual maximum chosen may be much larger than the actual Number passed. Currently the runtime system often, but not always, chooses a value that is a power of 2. This might, however, be changed in the future. The actual value chosen can be checked by calling erlang:system_info(port_limit).
The default value used is normally 65536. However, if the runtime system is able to determine maximum amount of file descriptors that it is allowed to open and this value is larger than 65536, the chosen value will increased to a value larger or equal to the maximum amount of file descriptors that can be opened.
On Windows the default value is set to 8196 because the normal OS limitations are set higher than most machines can handle.
Previously the environment variable ERL_MAX_PORTS was used for setting the maximum number of simultaneously existing ports. This environment variable is deprecated, and scheduled for removal in OTP-R17, but can still be used.
If legacy is passed as value, the legacy algorithm for allocation of port identifiers will be used. Using the legacy algorithm, identifiers will be allocated in a strictly increasing fashion until largest possible identifier has been reached. Note that this algorithm suffers from performance issues and can under certain circumstances be extremely expensive. The legacy algoritm is deprecated, and the legacy option is scheduled for removal in OTP-R18.
The distribution mechanism is not backwards compatible by default. This flags sets the emulator in compatibility mode with an earlier Erlang/OTP release ReleaseNumber. The release number must be in the range <current release>-2..<current release>. This limits the emulator, making it possible for it to communicate with Erlang nodes (as well as C- and Java nodes) running that earlier release.
Note: Make sure all nodes (Erlang-, C-, and Java nodes) of a distributed Erlang system is of the same Erlang/OTP release, or from two different Erlang/OTP releases X and Y, where all Y nodes have compatibility mode X.
When the amount of schedulers is less than or equal to the reader groups limit, each scheduler has its own reader group. When the amount of schedulers is larger than the reader groups limit, schedulers share reader groups. Shared reader groups degrades read lock and read unlock performance while a large amount of reader groups degrades write lock performance, so the limit is a tradeoff between performance for read operations and performance for write operations. Each reader group currently consumes 64 byte in each read/write lock. Also note that a runtime system using shared reader groups benefits from binding schedulers to logical processors, since the reader groups are distributed better between schedulers.
If Schedulers or SchedulersOnline is specified as a negative number, the value is subtracted from the default number of logical processors configured or logical processors available, respectively.
Specifying the value 0 for Schedulers or SchedulersOnline resets the number of scheduler threads or scheduler threads online respectively to its default value.
This option is ignored if the emulator doesn't have SMP support enabled (see the -smp flag).
This option interacts with +S settings. For example, on a system with 8 logical cores configured and 8 logical cores available, the combination of the options +S 4:4 +SP 50:25 (in either order) results in 2 scheduler threads (50% of 4) and 1 scheduler thread online (25% of 4).
This option is ignored if the emulator doesn't have SMP support enabled (see the -smp flag).
Schedulers can also be bound using the +stbt flag. The only difference between these two flags is how the following errors are handled:
If any of these errors occur when +sbt has been passed, the runtime system will print an error message, and refuse to start. If any of these errors occur when +stbt has been passed, the runtime system will silently ignore the error, and start up using unbound schedulers.
Currently valid BindTypes:
Binding of schedulers is currently only supported on newer Linux, Solaris, FreeBSD, and Windows systems.
If no CPU topology is available when the +sbt flag is processed and BindType is any other type than u, the runtime system will fail to start. CPU topology can be defined using the +sct flag. Note that the +sct flag may have to be passed before the +sbt flag on the command line (in case no CPU topology has been automatically detected).
The runtime system will by default not bind schedulers to logical processors.
NOTE: If the Erlang runtime system is the only operating system process that binds threads to logical processors, this improves the performance of the runtime system. However, if other operating system processes (as for example another Erlang runtime system) also bind threads to logical processors, there might be a performance penalty instead. In some cases this performance penalty might be severe. If this is the case, you are advised to not bind the schedulers.
How schedulers are bound matters. For example, in situations when there are fewer running processes than schedulers online, the runtime system tries to migrate processes to schedulers with low scheduler identifiers. The more the schedulers are spread over the hardware, the more resources will be available to the runtime system in such situations.
NOTE: If a scheduler fails to bind, this will often be silently ignored. This since it isn't always possible to verify valid logical processor identifiers. If an error is reported, it will be reported to the error_logger. If you want to verify that the schedulers actually have bound as requested, call erlang:system_info(scheduler_bindings).
NOTE: This flag may be removed or changed at any time without prior notice.
Set a user defined CPU topology. The user defined CPU topology will override any automatically detected CPU topology. The CPU topology is used when binding schedulers to logical processors.
Upper-case letters signify real identifiers and lower-case letters signify fake identifiers only used for description of the topology. Identifiers passed as real identifiers may be used by the runtime system when trying to access specific hardware and if they are not correct the behavior is undefined. Faked logical CPU identifiers are not accepted since there is no point in defining the CPU topology without real logical CPU identifiers. Thread, core, processor, and node identifiers may be left out. If left out, thread id defaults to t0, core id defaults to c0, processor id defaults to p0, and node id will be left undefined. Either each logical processor must belong to one and only one NUMA node, or no logical processors must belong to any NUMA nodes.
Both increasing and decreasing <IdRange>s are allowed.
NUMA node identifiers are system wide. That is, each NUMA node on the system have to have a unique identifier. Processor identifiers are also system wide. Core identifiers are processor wide. Thread identifiers are core wide.
The order of the identifier types imply the hierarchy of the CPU topology. Valid orders are either <LogicalIds><ThreadIds><CoreIds><ProcessorIds><NodeIds>, or <LogicalIds><ThreadIds><CoreIds><NodeIds><ProcessorIds>. That is, thread is part of a core which is part of a processor which is part of a NUMA node, or thread is part of a core which is part of a NUMA node which is part of a processor. A cpu topology can consist of both processor external, and processor internal NUMA nodes as long as each logical processor belongs to one and only one NUMA node. If <ProcessorIds> is left out, its default position will be before <NodeIds>. That is, the default is processor external NUMA nodes.
If a list of identifiers is used in an <IdDefs>:
A simple example. A single quad core processor may be described this way:
% erl +sct L0-3c0-3
1> erlang:system_info(cpu_topology).
[{processor,[{core,{logical,0}},
{core,{logical,1}},
{core,{logical,2}},
{core,{logical,3}}]}]
A little more complicated example. Two quad core processors. Each processor in its own NUMA node. The ordering of logical processors is a little weird. This in order to give a better example of identifier lists:
% erl +sct L0-1,3-2c0-3p0N0:L7,4,6-5c0-3p1N1
1> erlang:system_info(cpu_topology).
[{node,[{processor,[{core,{logical,0}},
{core,{logical,1}},
{core,{logical,3}},
{core,{logical,2}}]}]},
{node,[{processor,[{core,{logical,7}},
{core,{logical,4}},
{core,{logical,6}},
{core,{logical,5}}]}]}]
As long as real identifiers are correct it is okay to pass a CPU topology that is not a correct description of the CPU topology. When used with care this can actually be very useful. This in order to trick the emulator to bind its schedulers as you want. For example, if you want to run multiple Erlang runtime systems on the same machine, you want to reduce the amount of schedulers used and manipulate the CPU topology so that they bind to different logical CPUs. An example, with two Erlang runtime systems on a quad core machine:
% erl +sct L0-3c0-3 +sbt db +S3:2 -detached -noinput -noshell -sname one % erl +sct L3-0c0-3 +sbt db +S3:2 -detached -noinput -noshell -sname two
In this example each runtime system have two schedulers each online, and all schedulers online will run on different cores. If we change to one scheduler online on one runtime system, and three schedulers online on the other, all schedulers online will still run on different cores.
Note that a faked CPU topology that does not reflect how the real CPU topology looks like is likely to decrease the performance of the runtime system.
For more information, see erlang:system_info(cpu_topology).
This feature has been introduced as a temporary workaround for lengthy executing native code, and native code that do not bump reductions properly in OTP. When these bugs have be fixed the +sfwi flag will be removed.
NOTE: This flag may be removed or changed at any time without prior notice.
NOTE: This flag may be removed or changed at any time without prior notice.
NOTE: This flag may be removed or changed at any time without prior notice.
Currently, modified timing affects the following:
NOTE: Performance will suffer when modified timing is enabled. This flag is only intended for testing and debugging. Also note that return_to and return_from trace messages will be lost when tracing on the spawn BIFs. This flag may be removed or changed at any time without prior notice.
A larger buffer limit will allow processes to buffer more outgoing messages over the distribution. When the buffer limit has been reached, sending processes will be suspended until the buffer size has shrunk. The buffer limit is per distribution channel. A higher limit will give lower latency and higher throughput at the expense of higher memory usage.
If the environment variable is not set or it is set to zero seconds, ERL_CRASH_DUMP_SECONDS=0, the runtime system will not even attempt to write the crash dump file. It will just terminate.
If the environment variable is set to negative valie, e.g. ERL_CRASH_DUMP_SECONDS=-1, the runtime system will wait indefinitely for the crash dump file to be written.
This environment variable is used in conjuction with heart if heart is running:
The -extra flag is treated specially. Its scope ends at the end of the environment variable content. Arguments following an -extra flag are moved on the command line into the -extra section, i.e. the end of the command line following after an -extra flag.
The -extra flag is treated specially. Its scope ends at the end of the environment variable content. Arguments following an -extra flag are moved on the command line into the -extra section, i.e. the end of the command line following after an -extra flag.
The standard Erlang/OTP system can be re-configured to change the default behavior on start-up.
If an .erlang file is found, it is assumed to contain valid Erlang expressions. These expressions are evaluated as if they were input to the shell.
A typical .erlang file contains a set of search paths, for example:
io:format("executing user profile in HOME/.erlang\n",[]).
code:add_path("/home/calvin/test/ebin").
code:add_path("/home/hobbes/bigappl-1.2/ebin").
io:format(".erlang rc finished\n",[]).
To include private shell commands, define them in a module user_default and add the following argument as the first line in the .erlang file.
code:load_abs("..../user_default").
init(3erl), erl_prim_loader(3erl), erl_boot_server(3erl), code(3erl), application(3erl), heart(3erl), net_kernel(3erl), auth(3erl), make(3erl), epmd(1), erts_alloc(3erl)