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