~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/stdlib/doc/src/sys.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (1.1.13 upstream)
  • mto: (3.3.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: james.westby@ubuntu.com-20090215164252-dxpjjuq108nz4noa
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="latin1" ?>
 
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
 
3
 
 
4
<erlref>
 
5
  <header>
 
6
    <copyright>
 
7
      <year>1996</year>
 
8
      <year>2007</year>
 
9
      <holder>Ericsson AB, All Rights Reserved</holder>
 
10
    </copyright>
 
11
    <legalnotice>
 
12
  The contents of this file are subject to the Erlang Public License,
 
13
  Version 1.1, (the "License"); you may not use this file except in
 
14
  compliance with the License. You should have received a copy of the
 
15
  Erlang Public License along with this software. If not, it can be
 
16
  retrieved online at http://www.erlang.org/.
 
17
 
 
18
  Software distributed under the License is distributed on an "AS IS"
 
19
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
20
  the License for the specific language governing rights and limitations
 
21
  under the License.
 
22
 
 
23
  The Initial Developer of the Original Code is Ericsson AB.
 
24
    </legalnotice>
 
25
 
 
26
    <title>sys</title>
 
27
    <prepared>Martin Bj&ouml;rklund</prepared>
 
28
    <responsible>Bjarne D&auml;cker</responsible>
 
29
    <docno></docno>
 
30
    <approved>Bjarne D&auml;cker</approved>
 
31
    <checked></checked>
 
32
    <date>1996-06-06</date>
 
33
    <rev></rev>
 
34
    <file>sys.sgml</file>
 
35
  </header>
 
36
  <module>sys</module>
 
37
  <modulesummary>A Functional Interface to System Messages</modulesummary>
 
38
  <description>
 
39
    <p>This module contains functions for sending system messages used by programs, and messaged used for debugging purposes.
 
40
      </p>
 
41
    <p>Functions used for implementation of processes 
 
42
      should also understand system messages such as debugging
 
43
      messages and code change. These functions must be used to implement the use of system messages for a process; either directly, or through standard behaviours, such as <c>gen_server</c>.</p>
 
44
    <p>The following types are used in the functions defined below:</p>
 
45
    <list type="bulleted">
 
46
      <item>
 
47
        <p><c>Name = pid() | atom() | {global, atom()}</c></p>
 
48
      </item>
 
49
      <item>
 
50
        <p><c>Timeout = int() >= 0 | infinity</c></p>
 
51
      </item>
 
52
      <item>
 
53
        <p><c>system_event() = {in, Msg} | {in, Msg, From} | {out, Msg, To} | term()</c></p>
 
54
      </item>
 
55
    </list>
 
56
    <p>The default timeout is 5000 ms, unless otherwise specified. The
 
57
      <c>timeout</c> defines the time period to wait for the process to
 
58
      respond to a request. If the process does not respond, the
 
59
      function evaluates <c>exit({timeout, {M, F, A}})</c>.
 
60
      </p>
 
61
    <p>The functions make reference to a debug structure.
 
62
      The debug structure is a list of <c>dbg_opt()</c>.
 
63
      <c>dbg_opt()</c> is an internal data type used by the
 
64
      <c>handle_system_msg/6</c> function. No debugging is performed if it is an empty list.
 
65
      </p>
 
66
  </description>
 
67
 
 
68
  <section>
 
69
    <title>System Messages</title>
 
70
    <p>Processes which are not implemented as one of the standard
 
71
      behaviours must still understand system
 
72
      messages. There are three different messages which must be
 
73
      understood:
 
74
      </p>
 
75
    <list type="bulleted">
 
76
      <item>
 
77
        <p>Plain system messages. These are received as
 
78
          <c>{system, From, Msg}</c>. The content and meaning of
 
79
          this message are not interpreted by the
 
80
          receiving process module. When a system message has been
 
81
          received, the function <c>sys:handle_system_msg/6</c>
 
82
          is called in order to handle the request.
 
83
          </p>
 
84
      </item>
 
85
      <item>
 
86
        <p>Shutdown messages. If the process traps exits, it must
 
87
          be able to handle an shut-down request from its parent, the
 
88
          supervisor. The message <c>{'EXIT', Parent, Reason}</c>
 
89
          from the parent is an order to terminate.  The process must terminate when this message is received, normally with the
 
90
          same <c>Reason</c> as <c>Parent</c>.
 
91
          </p>
 
92
      </item>
 
93
      <item>
 
94
        <p>There is one more message which the process must understand if the modules used to implement the process change dynamically during runtime. An example of such a process is the <c>gen_event</c> processes. This message is <c>{get_modules, From}</c>. The reply to this message is <c>From ! {modules, Modules}</c>,
 
95
          where <c>Modules</c> is a list of the currently active modules in the process.
 
96
          </p>
 
97
        <p>This message is used by the release handler to find which
 
98
          processes execute a certain module. The process may at a
 
99
          later time be suspended and ordered to perform a code change
 
100
          for one of its modules.
 
101
          </p>
 
102
      </item>
 
103
    </list>
 
104
  </section>
 
105
 
 
106
  <section>
 
107
    <title>System Events</title>
 
108
    <p>When debugging a process with the functions of this
 
109
      module, the process generates <em>system_events</em> which are
 
110
      then treated in the debug function. For example, <c>trace</c>
 
111
      formats the system events to the tty.
 
112
      </p>
 
113
    <p>There are three predefined system events which are used when a
 
114
      process receives or sends a message. The process can also define its
 
115
      own system events. It is always up to the process itself
 
116
      to format these events.</p>
 
117
  </section>
 
118
  <funcs>
 
119
    <func>
 
120
      <name>log(Name,Flag)</name>
 
121
      <name>log(Name,Flag,Timeout) -> ok | {ok, [system_event()]}</name>
 
122
      <fsummary>Log system events in memory</fsummary>
 
123
      <type>
 
124
        <v>Flag = true | {true, N} | false | get | print</v>
 
125
        <v>N = integer() > 0</v>
 
126
      </type>
 
127
      <desc>
 
128
        <p>Turns the logging of system events On or Off. If On, a
 
129
          maximum of <c>N</c>  events are kept in the
 
130
          debug structure (the default is 10). If <c>Flag</c> is <c>get</c>, a list of all
 
131
          logged events is returned. If <c>Flag</c> is <c>print</c>, the
 
132
          logged events are printed to <c>standard_io</c>. The events are
 
133
          formatted with a function that is defined by the process that
 
134
          generated the event (with a call to
 
135
          <c>sys:handle_debug/4</c>).</p>
 
136
      </desc>
 
137
    </func>
 
138
    <func>
 
139
      <name>log_to_file(Name,Flag)</name>
 
140
      <name>log_to_file(Name,Flag,Timeout) -> ok | {error, open_file}</name>
 
141
      <fsummary>Log system events to the specified file</fsummary>
 
142
      <type>
 
143
        <v>Flag = FileName | false</v>
 
144
        <v>FileName = string()</v>
 
145
      </type>
 
146
      <desc>
 
147
        <p>Enables or disables the logging of all system events in textual
 
148
          format to the file. The events are formatted with a function that is 
 
149
          defined by the process that generated the event (with a call
 
150
          to <c>sys:handle_debug/4</c>).</p>
 
151
      </desc>
 
152
    </func>
 
153
    <func>
 
154
      <name>statistics(Name,Flag)</name>
 
155
      <name>statistics(Name,Flag,Timeout) -> ok | {ok, Statistics} </name>
 
156
      <fsummary>Enable or disable the collections of statistics</fsummary>
 
157
      <type>
 
158
        <v>Flag = true | false | get</v>
 
159
        <v>Statistics = [{start_time, {Date1, Time1}}, {current_time, {Date, Time2}}, {reductions, integer()}, {messages_in, integer()}, {messages_out, integer()}]</v>
 
160
        <v>Date1 = Date2 = {Year, Month, Day}</v>
 
161
        <v>Time1 = Time2 = {Hour, Min, Sec}</v>
 
162
      </type>
 
163
      <desc>
 
164
        <p>Enables or disables the collection of statistics. If <c>Flag</c> is
 
165
          <c>get</c>, the statistical collection is returned.</p>
 
166
      </desc>
 
167
    </func>
 
168
    <func>
 
169
      <name>trace(Name,Flag)</name>
 
170
      <name>trace(Name,Flag,Timeout) -> void()</name>
 
171
      <fsummary>Print all system events on <c>standard_io</c></fsummary>
 
172
      <type>
 
173
        <v>Flag = boolean()</v>
 
174
      </type>
 
175
      <desc>
 
176
        <p>Prints all system events on <c>standard_io</c>. The events are
 
177
          formatted with a function that is defined by the process that
 
178
          generated the event (with a call to
 
179
          <c>sys:handle_debug/4</c>).</p>
 
180
      </desc>
 
181
    </func>
 
182
    <func>
 
183
      <name>no_debug(Name)</name>
 
184
      <name>no_debug(Name,Timeout) -> void()</name>
 
185
      <fsummary>Turn off debugging</fsummary>
 
186
      <desc>
 
187
        <p>Turns off all debugging for the process. This includes
 
188
          functions that have been installed explicitly with the
 
189
          <c>install</c> function, for example triggers.</p>
 
190
      </desc>
 
191
    </func>
 
192
    <func>
 
193
      <name>suspend(Name)</name>
 
194
      <name>suspend(Name,Timeout) -> void()</name>
 
195
      <fsummary>Suspend the process</fsummary>
 
196
      <desc>
 
197
        <p>Suspends the process. When the process is suspended, it
 
198
          will only respond to other system messages, but not other
 
199
          messages.</p>
 
200
      </desc>
 
201
    </func>
 
202
    <func>
 
203
      <name>resume(Name)</name>
 
204
      <name>resume(Name,Timeout) -> void()</name>
 
205
      <fsummary>Resume a suspended process</fsummary>
 
206
      <desc>
 
207
        <p>Resumes a suspended process.</p>
 
208
      </desc>
 
209
    </func>
 
210
    <func>
 
211
      <name>change_code(Name, Module, OldVsn, Extra)</name>
 
212
      <name>change_code(Name, Module, OldVsn, Extra, Timeout) -> ok | {error, Reason}</name>
 
213
      <fsummary>Send the code change system message to the process</fsummary>
 
214
      <type>
 
215
        <v>OldVsn = undefined | term()</v>
 
216
        <v>Module = atom()</v>
 
217
        <v>Extra = term()</v>
 
218
      </type>
 
219
      <desc>
 
220
        <p>Tells the process to change code. The process must be
 
221
          suspended to handle this message. The <c>Extra</c> argument is
 
222
          reserved for each process to use as its own. The function
 
223
          <c>Mod:system_code_change/4</c> is called. <c>OldVsn</c> is
 
224
          the old version of the <c>Module</c>.</p>
 
225
      </desc>
 
226
    </func>
 
227
    <func>
 
228
      <name>get_status(Name)</name>
 
229
      <name>get_status(Name,Timeout) -> {status, Pid, {module, Mod}, [PDict, SysState, Parent, Dbg, Misc]}</name>
 
230
      <fsummary>Get the status of the process</fsummary>
 
231
      <type>
 
232
        <v>PDict = [{Key, Value}]</v>
 
233
        <v>SysState = running | suspended</v>
 
234
        <v>Parent = pid()</v>
 
235
        <v>Dbg = [dbg_opt()]</v>
 
236
        <v>Misc = term()</v>
 
237
      </type>
 
238
      <desc>
 
239
        <p>Gets the status of the process.</p>
 
240
      </desc>
 
241
    </func>
 
242
    <func>
 
243
      <name>install(Name,{Func,FuncState})</name>
 
244
      <name>install(Name,{Func,FuncState},Timeout)</name>
 
245
      <fsummary>Install a debug function in the process</fsummary>
 
246
      <type>
 
247
        <v>Func = dbg_fun()</v>
 
248
        <v>dbg_fun() = fun(FuncState, Event, ProcState) -> done | NewFuncState</v>
 
249
        <v>FuncState = term()</v>
 
250
        <v>Event = system_event()</v>
 
251
        <v>ProcState = term()</v>
 
252
        <v>NewFuncState = term()</v>
 
253
      </type>
 
254
      <desc>
 
255
        <p>This function makes it possible to install other debug
 
256
          functions than the ones defined above. An example of such a
 
257
          function is a trigger, a function that waits for some
 
258
          special event and performs some action when the event is
 
259
          generated. This could, for example, be turning on low level tracing.
 
260
          </p>
 
261
        <p><c>Func</c> is called whenever a system event is
 
262
          generated. This function should return <c>done</c>, or a new
 
263
          func state. In the first case, the function is removed. It is removed 
 
264
          if the function fails.</p>
 
265
      </desc>
 
266
    </func>
 
267
    <func>
 
268
      <name>remove(Name,Func)</name>
 
269
      <name>remove(Name,Func,Timeout) -> void()</name>
 
270
      <fsummary>Remove a debug function from the process</fsummary>
 
271
      <type>
 
272
        <v>Func = dbg_fun()</v>
 
273
      </type>
 
274
      <desc>
 
275
        <p>Removes a previously installed debug function from the
 
276
          process. <c>Func</c> must be the same as previously
 
277
          installed.</p>
 
278
      </desc>
 
279
    </func>
 
280
  </funcs>
 
281
 
 
282
  <section>
 
283
    <title>Process Implementation Functions</title>
 
284
    <p>The following functions are used when implementing a
 
285
      special process. This is an ordinary process which does not use a
 
286
      standard behaviour, but a process which understands the standard system messages.</p>
 
287
  </section>
 
288
  <funcs>
 
289
    <func>
 
290
      <name>debug_options(Options) -> [dbg_opt()]</name>
 
291
      <fsummary>Convert a list of options to a debug structure</fsummary>
 
292
      <type>
 
293
        <v>Options = [Opt]</v>
 
294
        <v>Opt = trace | log | statistics | {log_to_file, FileName} | {install, {Func, FuncState}}</v>
 
295
        <v>Func = dbg_fun()</v>
 
296
        <v>FuncState = term()</v>
 
297
      </type>
 
298
      <desc>
 
299
        <p>This function can be used by a process that initiates a debug
 
300
          structure from a list of options. The values of the
 
301
          <c>Opt</c> argument are the same as the corresponding
 
302
          functions.</p>
 
303
      </desc>
 
304
    </func>
 
305
    <func>
 
306
      <name>get_debug(Item,Debug,Default) -> term()</name>
 
307
      <fsummary>Get the data associated with a debug option</fsummary>
 
308
      <type>
 
309
        <v>Item = log | statistics</v>
 
310
        <v>Debug = [dbg_opt()]</v>
 
311
        <v>Default = term()</v>
 
312
      </type>
 
313
      <desc>
 
314
        <p>This function gets the data associated with a debug option. <c>Default</c> is returned if the
 
315
          <c>Item</c> is not found.  Can be
 
316
          used by the process to retrieve debug data for printing
 
317
          before it terminates.</p>
 
318
      </desc>
 
319
    </func>
 
320
    <func>
 
321
      <name>handle_debug([dbg_opt()],FormFunc,Extra,Event) -> [dbg_opt()]</name>
 
322
      <fsummary>Generate a system event</fsummary>
 
323
      <type>
 
324
        <v>FormFunc = dbg_fun()</v>
 
325
        <v>Extra = term()</v>
 
326
        <v>Event = system_event()</v>
 
327
      </type>
 
328
      <desc>
 
329
        <p>This function is called by a process when it generates a system event. <c>FormFunc</c> is a formatting function which is called as <c>FormFunc(Device, Event, Extra)</c> in order to print the events, which is necessary if tracing is activated. <c>Extra</c> is any
 
330
          extra information which the process needs in the format function, for example the name of the process.</p>
 
331
      </desc>
 
332
    </func>
 
333
    <func>
 
334
      <name>handle_system_msg(Msg,From,Parent,Module,Debug,Misc)</name>
 
335
      <fsummary>Take care of system messages</fsummary>
 
336
      <type>
 
337
        <v>Msg = term()</v>
 
338
        <v>From = pid()</v>
 
339
        <v>Parent = pid()</v>
 
340
        <v>Module = atom()</v>
 
341
        <v>Debug = [dbg_opt()]</v>
 
342
        <v>Misc = term()</v>
 
343
      </type>
 
344
      <desc>
 
345
        <p>This function is used by a process module that wishes to take care of system
 
346
          messages. The process receives a <c>{system, From, Msg}</c>
 
347
          message and passes the <c>Msg</c> and <c>From</c> to this
 
348
          function.
 
349
          </p>
 
350
        <p>This function <em>never</em> returns. It calls the function
 
351
          <c>Module:system_continue(Parent, NDebug, Misc)</c> where the
 
352
          process continues the execution, or
 
353
          <c>Module:system_terminate(Reason, Parent, Debug, Misc)</c> if
 
354
          the process should terminate. The <c>Module</c> must export
 
355
          <c>system_continue/3</c>, <c>system_terminate/4</c>, and
 
356
          <c>system_code_change/4</c> (see below).
 
357
          </p>
 
358
        <p>The <c>Misc</c> argument can be used to save internal data
 
359
          in a process, for example its state. It is sent to
 
360
          <c>Module:system_continue/3</c> or
 
361
          <c>Module:system_terminate/4</c></p>
 
362
      </desc>
 
363
    </func>
 
364
    <func>
 
365
      <name>print_log(Debug) -> void()</name>
 
366
      <fsummary>Print the logged events in the debug structure</fsummary>
 
367
      <type>
 
368
        <v>Debug = [dbg_opt()]</v>
 
369
      </type>
 
370
      <desc>
 
371
        <p>Prints the logged system events in the debug structure
 
372
          using <c>FormFunc</c> as defined when the event was
 
373
          generated by a call to <c>handle_debug/4</c>.</p>
 
374
      </desc>
 
375
    </func>
 
376
    <func>
 
377
      <name>Mod:system_continue(Parent, Debug, Misc)</name>
 
378
      <fsummary>Called when the process should continue its execution</fsummary>
 
379
      <type>
 
380
        <v>Parent = pid()</v>
 
381
        <v>Debug = [dbg_opt()]</v>
 
382
        <v>Misc = term()</v>
 
383
      </type>
 
384
      <desc>
 
385
        <p>This function is called from <c>sys:handle_system_msg/6</c> when the process
 
386
          should continue its execution (for example after it has been
 
387
          suspended). This function never returns.</p>
 
388
      </desc>
 
389
    </func>
 
390
    <func>
 
391
      <name>Mod:system_terminate(Reason, Parent, Debug, Misc)</name>
 
392
      <fsummary>Called when the process should terminate</fsummary>
 
393
      <type>
 
394
        <v>Reason = term()</v>
 
395
        <v>Parent = pid()</v>
 
396
        <v>Debug = [dbg_opt()]</v>
 
397
        <v>Misc = term()</v>
 
398
      </type>
 
399
      <desc>
 
400
        <p>This function is called from <c>sys:handle_system_msg/6</c> when the process
 
401
          should terminate. For example, this function is called when
 
402
          the process is suspended and its parent orders shut-down.
 
403
          It  gives the process a chance to do a clean-up. This function never
 
404
          returns.</p>
 
405
      </desc>
 
406
    </func>
 
407
    <func>
 
408
      <name>Mod:system_code_change(Misc, Module, OldVsn, Extra) -> {ok, NMisc}</name>
 
409
      <fsummary>Called when the process should perform a code change</fsummary>
 
410
      <type>
 
411
        <v>Misc = term()</v>
 
412
        <v>OldVsn = undefined | term()</v>
 
413
        <v>Module = atom()</v>
 
414
        <v>Extra = term()</v>
 
415
        <v>NMisc = term()</v>
 
416
      </type>
 
417
      <desc>
 
418
        <p>Called from <c>sys:handle_system_msg/6</c> when the process
 
419
          should perform a code change. The code change is used when the
 
420
          internal data structure has changed. This function
 
421
          converts the <c>Misc</c> argument to the new data
 
422
          structure. <c>OldVsn</c> is the <em>vsn</em> attribute of the
 
423
          old version of the <c>Module</c>. If no such attribute was
 
424
          defined, the atom <c>undefined</c> is sent.</p>
 
425
      </desc>
 
426
    </func>
 
427
  </funcs>
 
428
</erlref>
 
429