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