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