24. Runtime


Methodexit

voidexit(intreturncode, void|stringfmt, mixed ... extra)

Description

Exit the whole Pike program with the given returncode.

Using exit() with any other value than 0 (zero) indicates that something went wrong during execution. See your system manuals for more information about return codes.

The arguments after the returncode will be used for a call to werror to output a message on stderr.

See also

_exit()


Method_exit

void_exit(intreturncode)

Description

This function does the same as exit, but doesn't bother to clean up the Pike interpreter before exiting. This means that no destructors will be called, caches will not be flushed, file locks might not be released, and databases might not be closed properly.

Use with extreme caution.

See also

exit()


Methodatexit

voidatexit(function(:void) callback)

Description

This function puts the callback in a queue of callbacks to call when pike exits. The call order is reversed, i.e. callbacks that have been added earlier are called after callback.

Note

Please note that atexit callbacks are not called if Pike exits abnormally.

See also

exit(), _exit()


Methodtrace

inttrace(intlevel, void|stringfacility, void|intall_threads)

Description

This function changes the trace level for the subsystem identified by facility to level. If facility is zero or left out, it changes the global trace level which affects all subsystems.

Enabling tracing causes messages to be printed to stderr. A higher trace level includes the output from all lower levels. The lowest level is zero which disables all trace messages.

See the -t command-line option for more information.

Parameter level

If facility is specified then there is typically only one trace level for it, i.e. it's an on-or-off toggle. The global trace levels, when facility isn't specified, are:

1

Trace calls to Pike functions and garbage collector runs.

2

Trace calls to builtin functions.

3

Trace every interpreted opcode.

4

Also trace the opcode arguments.

Parameter facility

Valid facilities are:

"gc"

Trace the doings of the garbage collector. The setting is never thread local. level has two different meanings:

1..2

Trace the start and end of each gc run.

3..

Additionally show info about the collected garbage, to aid hunting down garbage problems. This currently shows gc'd trampolines. Note that the output can be very bulky and is somewhat low-level technical. Also note that pike currently has to be configured with --with-rtldebug to enable this.

Parameter all_threads

Trace levels are normally thread local, so changes affect only the current thread. To change the level in all threads, pass a nonzero value in this argument.

Returns

The old trace level in the current thread is returned.


Methodbacktrace

array(Pike.BacktraceFrame) backtrace(int|voidflags)

Description

Get a description of the current call stack.

Parameter flags

A bit mask of flags affecting generation of the backtrace.

Currently a single flag is defined:

1

Return LiveBacktraceFrames. This flag causes the frame objects to track changes (as long as they are in use), and makes eg local variables for functions available for inspection or change.

Note that since these values are "live", they may change or dissapear at any time unless the corresponding thread has been halted or similar.

Returns

The description is returned as an array with one entry for each call frame on the stack.

The entries are represented by Pike.BacktraceFrame objects.

The current call frame will be last in the array.

Note

Please note that the frame order may be reversed in a later version of Pike to accommodate for deferred backtraces.

Note

Note that the arguments reported in the backtrace are the current values of the variables, and not the ones that were at call-time. This can be used to hide sensitive information from backtraces (eg passwords).

Note

In old versions of Pike the entries used to be represented by arrays of the following format:

Array
stringfile

A string with the filename if known, else zero.

intline

An integer containing the linenumber if known, else zero.

function(:void) fun

The function that was called at this level.

mixed|void ... args

The arguments that the function was called with.

The above format is still supported by eg describe_backtrace().

See also

catch(), throw()


Methodgc

intgc(mapping|array|voidquick)

Description

Force garbage collection.

Parameter quick

Perform a quick garbage collection on just this value, which must have been made weak by set_weak_flag(). All values that only have a single reference from quick will then be freed.

When quick hasn't been specified or is UNDEFINED, this function checks all the memory for cyclic structures such as arrays containing themselves and frees them if appropriate. It also frees up destructed objects and things with only weak references.

Normally there is no need to call this function since Pike will call it by itself every now and then. (Pike will try to predict when 20% of all arrays/object/programs in memory is 'garbage' and call this routine then.)

Returns

The amount of garbage is returned. This is the number of arrays, mappings, multisets, objects and programs that had no nonweak external references during the garbage collection. It's normally the same as the number of freed things, but there might be some difference since _destruct() functions are called during freeing, which can cause more things to be freed or allocated.

See also

Pike.gc_parameters, Debug.gc_status


Methodquery_num_arg

intquery_num_arg()

Description

Returns the number of arguments given when the previous function was called.

This is useful for functions that take a variable number of arguments.

See also

call_function()


Methodversion

stringversion()

Description

Report the version of Pike. Does the same as

sprintf("Pike v%d.%d release %d",__REAL_VERSION__,__REAL_MINOR__,__REAL_BUILD__);
See also

__VERSION__, __MINOR__, __BUILD__, __REAL_VERSION__, __REAL_MINOR__, __REAL_BUILD__,