1Sys(3)                             OCamldoc                             Sys(3)
2
3
4

NAME

6       Sys - System interface.
7

Module

9       Module   Sys
10

Documentation

12       Module Sys
13        : sig end
14
15
16       System interface.
17
18       Every function in this module raises Sys_error with an informative mes‐
19       sage when the underlying system call signal an error.
20
21
22
23
24
25
26       val argv : string array
27
28       The command line arguments given to the process.  The first element  is
29       the  command  name  used to invoke the program.  The following elements
30       are the command-line arguments given to the program.
31
32
33
34       val executable_name : string
35
36       The name of the file containing the executable currently running.
37
38
39
40       val file_exists : string -> bool
41
42       Test if a file with the given name exists.
43
44
45
46       val is_directory : string -> bool
47
48       Returns true if the given name refers  to  a  directory,  false  if  it
49       refers to another kind of file.  Raise Sys_error if no file exists with
50       the given name.
51
52
53       Since 3.10.0
54
55
56
57       val remove : string -> unit
58
59       Remove the given file name from the file system.
60
61
62
63       val rename : string -> string -> unit
64
65       Rename a file. The first argument is the old name and the second is the
66       new  name.  If there is already another file under the new name, rename
67       may replace it, or raise an exception, depending on your operating sys‐
68       tem.
69
70
71
72       val getenv : string -> string
73
74       Return  the  value associated to a variable in the process environment.
75       Raise Not_found if the variable is unbound.
76
77
78
79       val getenv_opt : string -> string option
80
81       Return the value associated to a variable in the process environment or
82       None if the variable is unbound.
83
84
85       Since 4.05
86
87
88
89       val command : string -> int
90
91       Execute the given shell command and return its exit code.
92
93
94
95       val time : unit -> float
96
97       Return  the  processor  time, in seconds, used by the program since the
98       beginning of execution.
99
100
101
102       val chdir : string -> unit
103
104       Change the current working directory of the process.
105
106
107
108       val getcwd : unit -> string
109
110       Return the current working directory of the process.
111
112
113
114       val readdir : string -> string array
115
116       Return the names of all files present in the  given  directory.   Names
117       denoting the current directory and the parent directory ( .  and ..  in
118       Unix) are not returned.  Each string in  the  result  is  a  file  name
119       rather  than  a  complete  path.   There  is no guarantee that the name
120       strings in the resulting array will appear in any specific order;  they
121       are not, in particular, guaranteed to appear in alphabetical order.
122
123
124
125       val interactive : bool Pervasives.ref
126
127       This  reference is initially set to false in standalone programs and to
128       true if the code is being executed under the interactive toplevel  sys‐
129       tem ocaml .
130
131
132
133       val os_type : string
134
135       Operating system currently executing the OCaml program. One of
136
137       - Unix (for all Unix versions, including Linux and Mac OS X),
138
139       - Win32 (for MS-Windows, OCaml compiled with MSVC++ or Mingw),
140
141       - Cygwin (for MS-Windows, OCaml compiled with Cygwin).
142
143
144
145       type backend_type =
146        | Native
147        | Bytecode
148        | Other of string
149
150
151       Currently,  the official distribution only supports Native and Bytecode
152       , but it can be other backends with alternative compilers, for example,
153       javascript.
154
155
156       Since 4.04.0
157
158
159
160       val backend_type : backend_type
161
162       Backend type  currently executing the OCaml program.
163
164
165       Since 4.04.0
166
167
168
169       val unix : bool
170
171       True if Sys.os_type = Unix .
172
173
174       Since 4.01.0
175
176
177
178       val win32 : bool
179
180       True if Sys.os_type = Win32 .
181
182
183       Since 4.01.0
184
185
186
187       val cygwin : bool
188
189       True if Sys.os_type = Cygwin .
190
191
192       Since 4.01.0
193
194
195
196       val word_size : int
197
198       Size  of one word on the machine currently executing the OCaml program,
199       in bits: 32 or 64.
200
201
202
203       val int_size : int
204
205       Size of an int.  It is 31 bits (resp. 63 bits)  when  using  the  OCaml
206       compiler  on  a  32  bits  (resp. 64 bits) platform.  It may differ for
207       other compilers, e.g. it is 32 bits when compiling to JavaScript.
208
209
210       Since 4.03.0
211
212
213
214       val big_endian : bool
215
216       Whether the machine currently executing the Caml program is big-endian.
217
218
219       Since 4.00.0
220
221
222
223       val max_string_length : int
224
225       Maximum length of strings and byte sequences.
226
227
228
229       val max_array_length : int
230
231       Maximum length of a normal array.  The maximum length of a float  array
232       is max_array_length/2 on 32-bit machines and max_array_length on 64-bit
233       machines.
234
235
236
237       val runtime_variant : unit -> string
238
239       Return the name of the runtime variant the program is running on.  This
240       is normally the argument given to -runtime-variant at compile time, but
241       for byte-code it can be changed after compilation.
242
243
244       Since 4.03.0
245
246
247
248       val runtime_parameters : unit -> string
249
250       Return the value of the runtime parameters, in the same format  as  the
251       contents of the OCAMLRUNPARAM environment variable.
252
253
254       Since 4.03.0
255
256
257
258
259       === Signal handling ===
260
261
262       type signal_behavior =
263        | Signal_default
264        | Signal_ignore
265        | Signal_handle of (int -> unit)
266
267
268       What to do when receiving a signal:
269
270       -  Signal_default  : take the default behavior (usually: abort the pro‐
271       gram)
272
273       - Signal_ignore : ignore the signal
274
275       - Signal_handle f : call function f , giving it the  signal  number  as
276       argument.
277
278
279
280
281       val signal : int -> signal_behavior -> signal_behavior
282
283       Set the behavior of the system on receipt of a given signal.  The first
284       argument is the signal number.  Return the behavior previously  associ‐
285       ated with the signal. If the signal number is invalid (or not available
286       on your system), an Invalid_argument exception is raised.
287
288
289
290       val set_signal : int -> signal_behavior -> unit
291
292       Same as Sys.signal but return value is ignored.
293
294
295
296
297       === Signal numbers for the standard POSIX signals.  ===
298
299
300       val sigabrt : int
301
302       Abnormal termination
303
304
305
306       val sigalrm : int
307
308       Timeout
309
310
311
312       val sigfpe : int
313
314       Arithmetic exception
315
316
317
318       val sighup : int
319
320       Hangup on controlling terminal
321
322
323
324       val sigill : int
325
326       Invalid hardware instruction
327
328
329
330       val sigint : int
331
332       Interactive interrupt (ctrl-C)
333
334
335
336       val sigkill : int
337
338       Termination (cannot be ignored)
339
340
341
342       val sigpipe : int
343
344       Broken pipe
345
346
347
348       val sigquit : int
349
350       Interactive termination
351
352
353
354       val sigsegv : int
355
356       Invalid memory reference
357
358
359
360       val sigterm : int
361
362       Termination
363
364
365
366       val sigusr1 : int
367
368       Application-defined signal 1
369
370
371
372       val sigusr2 : int
373
374       Application-defined signal 2
375
376
377
378       val sigchld : int
379
380       Child process terminated
381
382
383
384       val sigcont : int
385
386       Continue
387
388
389
390       val sigstop : int
391
392       Stop
393
394
395
396       val sigtstp : int
397
398       Interactive stop
399
400
401
402       val sigttin : int
403
404       Terminal read from background process
405
406
407
408       val sigttou : int
409
410       Terminal write from background process
411
412
413
414       val sigvtalrm : int
415
416       Timeout in virtual time
417
418
419
420       val sigprof : int
421
422       Profiling interrupt
423
424
425
426       val sigbus : int
427
428       Bus error
429
430
431       Since 4.03
432
433
434
435       val sigpoll : int
436
437       Pollable event
438
439
440       Since 4.03
441
442
443
444       val sigsys : int
445
446       Bad argument to routine
447
448
449       Since 4.03
450
451
452
453       val sigtrap : int
454
455       Trace/breakpoint trap
456
457
458       Since 4.03
459
460
461
462       val sigurg : int
463
464       Urgent condition on socket
465
466
467       Since 4.03
468
469
470
471       val sigxcpu : int
472
473       Timeout in cpu time
474
475
476       Since 4.03
477
478
479
480       val sigxfsz : int
481
482       File size limit exceeded
483
484
485       Since 4.03
486
487
488
489       exception Break
490
491
492       Exception raised on interactive interrupt if Sys.catch_break is on.
493
494
495
496       val catch_break : bool -> unit
497
498
499       catch_break governs whether interactive interrupt  (ctrl-C)  terminates
500       the  program  or  raises the Break exception.  Call catch_break true to
501       enable raising Break , and catch_break false to let the  system  termi‐
502       nate the program on user interrupt.
503
504
505
506       val ocaml_version : string
507
508
509       ocaml_version  is  the  version  of  OCaml.  It is a string of the form
510       major.minor[.patchlevel][+additional-info] , where major , minor ,  and
511       patchlevel  are  integers,  and additional-info is an arbitrary string.
512       The [.patchlevel] and [+additional-info] parts may be absent.
513
514
515
516       val enable_runtime_warnings : bool -> unit
517
518       Control whether the OCaml runtime system can emit warnings  on  stderr.
519       Currently,  the only supported warning is triggered when a channel cre‐
520       ated by open_* functions is finalized without  being  closed.   Runtime
521       warnings are enabled by default.
522
523
524       Since 4.03.0
525
526
527
528       val runtime_warnings_enabled : unit -> bool
529
530       Return whether runtime warnings are currently enabled.
531
532
533       Since 4.03.0
534
535
536
537
538       === Optimization ===
539
540
541       val opaque_identity : 'a -> 'a
542
543       For  the  purposes  of  optimization,  opaque_identity  behaves like an
544       unknown (and thus possibly side-effecting) function.
545
546       At runtime, opaque_identity disappears altogether.
547
548       A typical use of this function is to  prevent  pure  computations  from
549       being  optimized away in benchmarking loops.  For example: for _round =
550       1 to 100_000 do ignore (Sys.opaque_identity  (my_pure_computation  ()))
551       done
552
553
554
555       Since 4.03.0
556
557
558
559
560
5612018-04-14                          source:                             Sys(3)
Impressum