1Stdlib.Sys(3)                    OCaml library                   Stdlib.Sys(3)
2
3
4

NAME

6       Stdlib.Sys - no description
7

Module

9       Module   Stdlib.Sys
10

Documentation

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