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