User's Guide
Reference Manual
Release Notes
PDF
Top

Erlang Run-Time System Application (ERTS)
Reference Manual
Version 5.9.2

Expand All
Contract All

Table of Contents

- erl_prim_loader
  - Top of manual page
  - start/3
  - get_file/1
  - get_path/0
  - list_dir/1
  - read_file_info/1
  - set_path/1
- erlang
  - Top of manual page
  - abs/1
  - adler32/1
  - adler32/2
  - adler32_combine/3
  - append_element/2
  - apply/2
  - apply/3
  - atom_to_binary/2
  - atom_to_list/1
  - binary_part/2
  - binary_part/3
  - binary_to_atom/2
  - binary_to_existing_atom/2
  - binary_to_list/1
  - binary_to_list/3
  - bitstring_to_list/1
  - binary_to_term/1
  - binary_to_term/2
  - bit_size/1
  - bump_reductions/1
  - byte_size/1
  - cancel_timer/1
  - check_old_code/1
  - check_process_code/2
  - crc32/1
  - crc32/2
  - crc32_combine/3
  - date/0
  - decode_packet/3
  - delete_module/1
  - demonitor/1
  - demonitor/2
  - disconnect_node/1
  - display/1
  - element/2
  - erase/0
  - erase/1
  - error/1
  - error/2
  - exit/1
  - exit/2
  - external_size/1
  - external_size/2
  - float/1
  - float_to_list/1
  - fun_info/1
  - fun_info/2
  - fun_to_list/1
  - function_exported/3
  - garbage_collect/0
  - garbage_collect/1
  - get/0
  - get/1
  - get_cookie/0
  - get_keys/1
  - get_stacktrace/0
  - group_leader/0
  - group_leader/2
  - halt/0
  - halt/1
  - halt/2
  - hash/2
  - hd/1
  - hibernate/3
  - integer_to_list/1
  - integer_to_list/2
  - iolist_to_binary/1
  - iolist_size/1
  - is_alive/0
  - is_atom/1
  - is_binary/1
  - is_bitstring/1
  - is_boolean/1
  - is_builtin/3
  - is_float/1
  - is_function/1
  - is_function/2
  - is_integer/1
  - is_list/1
  - is_number/1
  - is_pid/1
  - is_port/1
  - is_process_alive/1
  - is_record/2
  - is_record/3
  - is_reference/1
  - is_tuple/1
  - length/1
  - link/1
  - list_to_atom/1
  - list_to_binary/1
  - list_to_bitstring/1
  - list_to_existing_atom/1
  - list_to_float/1
  - list_to_integer/1
  - list_to_integer/2
  - list_to_pid/1
  - list_to_tuple/1
  - load_module/2
  - load_nif/2
  - loaded/0
  - localtime/0
  - localtime_to_universaltime/1
  - localtime_to_universaltime/2
  - make_ref/0
  - make_tuple/2
  - make_tuple/3
  - max/2
  - md5/1
  - md5_final/1
  - md5_init/0
  - md5_update/2
  - memory/0
  - memory/1
  - min/2
  - module_loaded/1
  - monitor/2
  - monitor_node/2
  - monitor_node/3
  - nif_error/1
  - nif_error/2
  - node/0
  - node/1
  - nodes/0
  - nodes/1
  - now/0
  - open_port/2
  - phash/2
  - phash2/1
  - pid_to_list/1
  - port_close/1
  - port_command/2
  - port_command/3
  - port_connect/2
  - port_control/3
  - port_call/3
  - port_info/1
  - port_info/2
  - port_to_list/1
  - ports/0
  - pre_loaded/0
  - process_display/2
  - process_flag/2
  - process_flag/3
  - process_info/1
  - process_info/2
  - processes/0
  - purge_module/1
  - put/2
  - raise/3
  - read_timer/1
  - ref_to_list/1
  - register/2
  - registered/0
  - resume_process/1
  - round/1
  - self/0
  - send/2
  - send/3
  - send_after/3
  - send_nosuspend/2
  - send_nosuspend/3
  - set_cookie/2
  - setelement/3
  - size/1
  - spawn/1
  - spawn/2
  - spawn/3
  - spawn/4
  - spawn_link/1
  - spawn_link/2
  - spawn_link/3
  - spawn_link/4
  - spawn_monitor/1
  - spawn_monitor/3
  - spawn_opt/2
  - spawn_opt/3
  - spawn_opt/4
  - spawn_opt/5
  - split_binary/2
  - start_timer/3
  - statistics/1
  - suspend_process/2
  - suspend_process/1
  - system_flag/2
  - system_info/1
  - system_monitor/0
  - system_monitor/1
  - system_monitor/2
  - system_profile/0
  - system_profile/2
  - term_to_binary/1
  - term_to_binary/2
  - throw/1
  - time/0
  - tl/1
  - trace/3
  - trace_delivered/1
  - trace_info/2
  - trace_pattern/2
  - trace_pattern/3
  - trunc/1
  - tuple_size/1
  - tuple_to_list/1
  - universaltime/0
  - universaltime_to_localtime/1
  - unlink/1
  - unregister/1
  - whereis/1
  - yield/0
- init
  - Top of manual page
  - boot/1
  - get_argument/1
  - get_arguments/0
  - get_plain_arguments/0
  - get_status/0
  - reboot/0
  - restart/0
  - script_id/0
  - stop/0
  - stop/1
- zlib
  - Top of manual page
  - open/0
  - close/1
  - deflateInit/1
  - deflateInit/2
  - deflateInit/6
  - deflate/2
  - deflate/3
  - deflateSetDictionary/2
  - deflateReset/1
  - deflateParams/3
  - deflateEnd/1
  - inflateInit/1
  - inflateInit/2
  - inflate/2
  - inflateSetDictionary/2
  - inflateReset/1
  - inflateEnd/1
  - setBufSize/2
  - getBufSize/1
  - crc32/1
  - crc32/2
  - crc32/3
  - crc32_combine/4
  - adler32/2
  - adler32/3
  - adler32_combine/4
  - compress/1
  - uncompress/1
  - zip/1
  - unzip/1
  - gzip/1
  - gunzip/1
- epmd
- erl
- erlc
- werl
- escript
- erlsrv
- start_erl
- erl_set_memory_block
  - Top of manual page
  - erl_set_memory_block()
  - erl_memory_show()
  - erl_mem_info_get()
- run_erl
- start
- erl_driver
  - Top of manual page
  - driver_system_info()
  - driver_output()
  - driver_output2()
  - driver_output_binary()
  - driver_outputv()
  - driver_vec_to_buf()
  - driver_set_timer()
  - driver_cancel_timer()
  - driver_read_timer()
  - driver_get_now()
  - driver_select()
  - driver_alloc()
  - driver_realloc()
  - driver_free()
  - driver_alloc_binary()
  - driver_realloc_binary()
  - driver_free_binary()
  - driver_binary_get_refc()
  - driver_binary_inc_refc()
  - driver_binary_dec_refc()
  - driver_enq()
  - driver_pushq()
  - driver_deq()
  - driver_sizeq()
  - driver_enq_bin()
  - driver_pushq_bin()
  - driver_peekqv()
  - driver_peekq()
  - driver_enqv()
  - driver_pushqv()
  - driver_pdl_create()
  - driver_pdl_lock()
  - driver_pdl_unlock()
  - driver_pdl_get_refc()
  - driver_pdl_inc_refc()
  - driver_pdl_dec_refc()
  - driver_monitor_process()
  - driver_demonitor_process()
  - driver_get_monitored_process()
  - driver_compare_monitors()
  - add_driver_entry()
  - remove_driver_entry()
  - erl_errno_id()
  - set_busy_port()
  - set_port_control_flags()
  - driver_failure_eof()
  - driver_failure_atom()
  - driver_failure_posix()
  - driver_failure()
  - driver_connected()
  - driver_caller()
  - driver_output_term()
  - driver_mk_atom()
  - driver_mk_port()
  - driver_send_term()
  - driver_async ()
  - driver_async_cancel()
  - driver_lock_driver()
  - driver_create_port()
  - erl_drv_thread_create()
  - erl_drv_thread_opts_create()
  - erl_drv_thread_opts_destroy()
  - erl_drv_thread_exit()
  - erl_drv_thread_join()
  - erl_drv_thread_self()
  - erl_drv_equal_tids()
  - erl_drv_mutex_create()
  - erl_drv_mutex_destroy()
  - erl_drv_mutex_lock()
  - erl_drv_mutex_trylock()
  - erl_drv_mutex_unlock()
  - erl_drv_cond_create()
  - erl_drv_cond_destroy()
  - erl_drv_cond_signal()
  - erl_drv_cond_broadcast()
  - erl_drv_cond_wait()
  - erl_drv_rwlock_create()
  - erl_drv_rwlock_destroy()
  - erl_drv_rwlock_rlock()
  - erl_drv_rwlock_tryrlock()
  - erl_drv_rwlock_runlock()
  - erl_drv_rwlock_rwlock()
  - erl_drv_rwlock_tryrwlock()
  - erl_drv_rwlock_rwunlock()
  - erl_drv_tsd_key_create()
  - erl_drv_tsd_key_destroy()
  - erl_drv_tsd_set()
  - erl_drv_tsd_get()
  - erl_drv_putenv()
  - erl_drv_getenv()
- driver_entry
- erts_alloc
- erl_nif
  - Top of manual page
  - enif_alloc()
  - enif_alloc_binary()
  - enif_alloc_env()
  - enif_alloc_resource()
  - enif_clear_env()
  - enif_compare()
  - enif_cond_broadcast()
  - enif_cond_create()
  - enif_cond_destroy()
  - enif_cond_signal()
  - enif_cond_wait()
  - enif_equal_tids()
  - enif_free()
  - enif_free_env()
  - enif_get_atom()
  - enif_get_atom_length()
  - enif_get_double()
  - enif_get_int()
  - enif_get_int64()
  - enif_get_local_pid()
  - enif_get_list_cell()
  - enif_get_list_length()
  - enif_get_long()
  - enif_get_resource()
  - enif_get_string()
  - enif_get_tuple()
  - enif_get_uint()
  - enif_get_uint64()
  - enif_get_ulong()
  - enif_inspect_binary()
  - enif_inspect_iolist_as_binary()
  - enif_is_atom()
  - enif_is_binary()
  - enif_is_empty_list()
  - enif_is_exception()
  - enif_is_number()
  - enif_is_fun()
  - enif_is_identical()
  - enif_is_pid()
  - enif_is_port()
  - enif_is_ref()
  - enif_is_tuple()
  - enif_is_list()
  - enif_keep_resource()
  - enif_make_atom()
  - enif_make_atom_len()
  - enif_make_badarg()
  - enif_make_binary()
  - enif_make_copy()
  - enif_make_double()
  - enif_make_existing_atom()
  - enif_make_existing_atom_len()
  - enif_make_int()
  - enif_make_int64()
  - enif_make_list()
  - enif_make_list1()
  - enif_make_list2()
  - enif_make_list3()
  - enif_make_list4()
  - enif_make_list5()
  - enif_make_list6()
  - enif_make_list7()
  - enif_make_list8()
  - enif_make_list9()
  - enif_make_list_cell()
  - enif_make_list_from_array()
  - enif_make_reverse_list()
  - enif_make_long()
  - enif_make_new_binary()
  - enif_make_pid()
  - enif_make_ref()
  - enif_make_resource()
  - enif_make_resource_binary()
  - enif_make_string()
  - enif_make_string_len()
  - enif_make_sub_binary()
  - enif_make_tuple()
  - enif_make_tuple1()
  - enif_make_tuple2()
  - enif_make_tuple3()
  - enif_make_tuple4()
  - enif_make_tuple5()
  - enif_make_tuple6()
  - enif_make_tuple7()
  - enif_make_tuple8()
  - enif_make_tuple9()
  - enif_make_tuple_from_array()
  - enif_make_uint()
  - enif_make_uint64()
  - enif_make_ulong()
  - enif_mutex_create()
  - enif_mutex_destroy()
  - enif_mutex_lock()
  - enif_mutex_trylock()
  - enif_mutex_unlock()
  - enif_open_resource_type()
  - enif_priv_data()
  - enif_realloc_binary()
  - enif_release_binary()
  - enif_release_resource()
  - enif_rwlock_create()
  - enif_rwlock_destroy()
  - enif_rwlock_rlock()
  - enif_rwlock_runlock()
  - enif_rwlock_rwlock()
  - enif_rwlock_rwunlock()
  - enif_rwlock_tryrlock()
  - enif_rwlock_tryrwlock()
  - enif_self()
  - enif_send()
  - enif_sizeof_resource()
  - enif_system_info()
  - enif_thread_create()
  - enif_thread_exit()
  - enif_thread_join()
  - enif_thread_opts_create()
  - enif_thread_opts_destroy()
  - enif_thread_self()
  - enif_tsd_key_create()
  - enif_tsd_key_destroy()
  - enif_tsd_get()
  - enif_tsd_set()

# erlsrv

### COMMAND

erlsrv

### COMMAND SUMMARY

Run the Erlang emulator as a service on Windows NT®

### DESCRIPTION

This utility is specific to Windows NT/2000/XP® (and subsequent versions of Windows) It allows Erlang emulators to run as services on the Windows system, allowing embedded systems to start without any user needing to log in. The emulator started in this way can be manipulated through the Windows® services applet in a manner similar to other services.

Note that erlsrv is not a general service utility for Windows, but designed for embedded Erlang systems.

As well as being the actual service, erlsrv also provides a command line interface for registering, changing, starting and stopping services.

To manipulate services, the logged in user should have Administrator privileges on the machine. The Erlang machine itself is (default) run as the local administrator. This can be changed with the Services applet in Windows ®.

The processes created by the service can, as opposed to normal services, be "killed" with the task manager. Killing a emulator that is started by a service will trigger the "OnFail" action specified for that service, which may be a reboot.

The following parameters may be specified for each Erlang service:

- StopAction: This tells erlsrv how to stop the Erlang emulator. Default is to kill it (Win32 TerminateProcess), but this action can specify any Erlang shell command that will be executed in the emulator to make it stop. The emulator is expected to stop within 30 seconds after the command is issued in the shell. If the emulator is not stopped, it will report a running state to the service manager.

- OnFail: This can be either of reboot, restart, restart_always or ignore (the default). In case of reboot, the NT system is rebooted whenever the emulator stops (a more simple form of watchdog), this could be useful for less critical systems, otherwise use the heart functionality to accomplish this. The restart value makes the Erlang emulator be restarted (with whatever parameters are registered for the service at the occasion) when it stops. If the emulator stops again within 10 seconds, it is not restarted to avoid an infinite loop which could completely hang the NT system. restart_always is similar to restart, but does not try to detect cyclic restarts, it is expected that some other mechanism is present to avoid the problem. The default (ignore) just reports the service as stopped to the service manager whenever it fails, it has to be manually restarted.

  On a system where release handling is used, this should always be set to ignore. Use heart to restart the service on failure instead.

- Machine: The location of the Erlang emulator. The default is the erl.exe located in the same directory as erlsrv.exe. Do not specify werl.exe as this emulator, it will not work.

  If the system uses release handling, this should be set to a program similar to start_erl.exe.

- Env: Specifies an additional environment for the emulator. The environment variables specified here are added to the system wide environment block that is normally present when a service starts up. Variables present in both the system wide environment and in the service environment specification will be set to the value specified in the service.

- WorkDir: The working directory for the Erlang emulator, has to be on a local drive (there are no network drives mounted when a service starts). Default working directory for services is %SystemDrive%%SystemPath%. Debug log files will be placed in this directory.

- Priority: The process priority of the emulator, this can be one of realtime, high, low or default (the default). Real-time priority is not recommended, the machine will possibly be inaccessible to interactive users. High priority could be used if two Erlang nodes should reside on one dedicated system and one should have precedence over the other. Low process priority may be used if interactive performance should not be affected by the emulator process.

- SName or Name: Specifies the short or long node-name of the Erlang emulator. The Erlang services are always distributed, default is to use the service name as (short) node-name.

- DebugType: Can be one of none (default), new, reuse or console. Specifies that output from the Erlang shell should be sent to a "debug log". The log file is named <servicename>.debug or <servicename>.debug.<N>, where <N> is an integer between 1 and 99. The log-file is placed in the working directory of the service (as specified in WorkDir). The reuse option always reuses the same log file (<servicename>.debug) and the new option uses a separate log file for every invocation of the service (<servicename>.debug.<N>). The console option opens an interactive Windows® console window for the Erlang shell of the service. The console option automatically disables the StopAction and a service started with an interactive console window will not survive logouts, OnFail actions do not work with debug-consoles either. If no DebugType is specified (none), the output of the Erlang shell is discarded.

  The console DebugType is not in any way intended for production. It is only a convenient way to debug Erlang services during development. The new and reuse options might seem convenient to have in a production system, but one has to take into account that the logs will grow indefinitely during the systems lifetime and there is no way, short of restarting the service, to truncate those logs. In short, the DebugType is intended for debugging only. Logs during production are better produced with the standard Erlang logging facilities.

- Args: Additional arguments passed to the emulator startup program erl.exe (or start_erl.exe). Arguments that cannot be specified here are -noinput (StopActions would not work), -name and -sname (they are specified in any way. The most common use is for specifying cookies and flags to be passed to init:boot() (-s).

- InternalServiceName: Specifies the Windows® internal service name (not the display name, which is the one erlsrv uses to identify the service).

  This internal name can not be changed, it is fixed even if the service is renamed. Erlsrv generates a unique internal name when a service is created, it is recommended to keep to the defaut if release-handling is to be used for the application.

  The internal service name can be seen in the Windows® service manager if viewing Properties for an erlang service.

- Comment: A textual comment describing the service. Not mandatory, but shows up as the service description in the Windows® service manager.

The naming of the service in a system that uses release handling has to follow the convention NodeName_Release, where NodeName is the first part of the Erlang nodename (up to, but not including the "@") and Release is the current release of the application.

### EXPORTS

erlsrv {set | add} <service-name> [<service options>]

The set and add commands adds or modifies a Erlang service respectively. The simplest form of an add command would be completely without options in which case all default values (described above) apply. The service name is mandatory.

Every option can be given without parameters, in which case the default value is applied. Values to the options are supplied only when the default should not be used (i.e. erlsrv set myservice -prio -arg sets the default priority and removes all arguments).

The following service options are currently available:

-st[opaction] [<erlang shell command>]
  Defines the StopAction, the command given to the Erlang shell when the service is stopped. Default is none.
-on[fail] [{reboot | restart | restart_always}]
  Specifies the action to take when the Erlang emulator stops unexpectedly. Default is to ignore.
-m[achine] [<erl-command>]
  The complete path to the Erlang emulator, never use the werl program for this. Default is the erl.exe in the same directory as erlsrv.exe. When release handling is used, this should be set to a program similar to start_erl.exe.
-e[nv] [<variable>[=<value>]] ...
  Edits the environment block for the service. Every environment variable specified will add to the system environment block. If a variable specified here has the same name as a system wide environment variable, the specified value overrides the system wide. Environment variables are added to this list by specifying <variable>=<value> and deleted from the list by specifying <variable> alone. The environment block is automatically sorted. Any number of -env options can be specified in one command. Default is to use the system environment block unmodified (except for two additions, see below).
-w[orkdir] [<directory>]
  The initial working directory of the Erlang emulator. Default is the system directory.
-p[riority] [{low|high|realtime}]
  The priority of the Erlang emulator. The default is the Windows® default priority.
{-sn[ame] | -n[ame]} [<node-name>]
  The node-name of the Erlang machine, distribution is mandatory. Default is -sname <service name>.
-d[ebugtype] [{new|reuse|console}]
  Specifies where shell output should be sent, default is that shell output is discarded. To be used only for debugging.
-ar[gs] [<limited erl arguments>]
  Additional arguments to the Erlang emulator, avoid -noinput, -noshell and -sname/-name. Default is no additional arguments. Remember that the services cookie file is not necessarily the same as the interactive users. The service runs as the local administrator. All arguments should be given together in one string, use double quotes (") to give an argument string containing spaces and use quoted quotes (\") to give an quote within the argument string if necessary.
-i[nternalservicename] [<internal name>]
  Only allowed for add. Specifies a Windows® internal service name for the service, which by default is set to something unique (prefixed with the original service name) by erlsrv when adding a new service. Specifying this is a purely cosmethic action and is not recommended if release handling is to be performed. The internal service name cannot be changed once the service is created. The internal name is not to be confused with the ordinary service name, which is the name used to identify a service to erlsrv.
-c[omment] [<short description>]
  Specifies a textual comment describing the service. This comment will show upp as the service description in the Windows® service manager.

erlsrv {start | start_disabled | stop | disable | enable} <service-name>

These commands are only added for convenience, the normal way to manipulate the state of a service is through the control panels services applet. The start and stop commands communicates with the service manager for stopping and starting a service. The commands wait until the service is actually stopped or started. When disabling a service, it is not stopped, the disabled state will not take effect until the service actually is stopped. Enabling a service sets it in automatic mode, that is started at boot. This command cannot set the service to manual.

The start_disabled command operates on a service regardless of if it's enabled/disabled or started/stopped. It does this by first enabling it (regardless of if it's enabled or not), then starting it (if it's not already started) and then disabling it. The result will be a disabled but started service, regardless of its earlier state. This is useful for starting services temporarily during a release upgrade. The difference between using start_disabled and the sequence enable, start and disable is that all other erlsrv commands are locked out during the sequence of operations in start_disable, making the operation atomic from an erlsrv user's point of view.

erlsrv remove <service-name>

This command removes the service completely with all its registered options. It will be stopped before it is removed.

erlsrv list [<service-name>]

If no service name is supplied, a brief listing of all Erlang services is presented. If a service-name is supplied, all options for that service are presented.

erlsrv help

### ENVIRONMENT

The environment of an Erlang machine started as a service will contain two special variables, ERLSRV_SERVICE_NAME, which is the name of the service that started the machine and ERLSRV_EXECUTABLE which is the full path to the erlsrv.exe that can be used to manipulate the service. This will come in handy when defining a heart command for your service. A command file for restarting a service will simply look like this:

    @echo off
    %ERLSRV_EXECUTABLE% stop %ERLSRV_SERVICE_NAME%
    %ERLSRV_EXECUTABLE% start %ERLSRV_SERVICE_NAME%

This command file is then set as heart command.

The environment variables can also be used to detect that we are running as a service and make port programs react correctly to the control events generated on logout (see below).

### PORT PROGRAMS

When a program runs in the service context, it has to handle the control events that is sent to every program in the system when the interactive user logs off. This is done in different ways for programs running in the console subsystem and programs running as window applications. An application which runs in the console subsystem (normal for port programs) uses the win32 function SetConsoleCtrlHandler to register a control handler that returns TRUE in answer to the CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT events. Other applications just forward WM_ENDSESSION and WM_QUERYENDSESSION to the default window procedure. Here is a brief example in C of how to set the console control handler:

    #include <windows.h>
    /*
    ** A Console control handler that ignores the log off events,
    ** and lets the default handler take care of other events.
    */
    BOOL WINAPI service_aware_handler(DWORD ctrl){
        if(ctrl == CTRL_LOGOFF_EVENT)
            return TRUE;
        if(ctrl == CTRL_SHUTDOWN_EVENT)
            return TRUE;
        return FALSE;
    }

    void initialize_handler(void){
        char buffer[2];
        /*
         * We assume we are running as a service if this
         * environment variable is defined
         */
        if(GetEnvironmentVariable("ERLSRV_SERVICE_NAME",buffer,
                                  (DWORD) 2)){
            /*
            ** Actually set the control handler
            */
            SetConsoleCtrlHandler(&service_aware_handler, TRUE);
        }
    }

### NOTES

Even though the options are described in a Unix-like format, the case of the options or commands is not relevant, and the "/" character for options can be used as well as the "-" character.

Note that the program resides in the emulators bin-directory, not in the bin-directory directly under the Erlang root. The reasons for this are the subtle problem of upgrading the emulator on a running system, where a new version of the runtime system should not need to overwrite existing (and probably used) executables.

To easily manipulate the Erlang services, put the <erlang_root>\erts-<version>\bin directory in the path instead of <erlang_root>\bin. The erlsrv program can be found from inside Erlang by using the os:find_executable/1 Erlang function.

For release handling to work, use start_erl as the Erlang machine. It is also worth mentioning again that the name of the service is significant (see above).

### SEE ALSO

start_erl(1), release_handler(3)