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 Pervasives.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.  The maximum length of a float array
240       is max_array_length/2 on 32-bit machines and max_array_length on 64-bit
241       machines.
242
243
244
245       val runtime_variant : unit -> string
246
247       Return the name of the runtime variant the program is running on.  This
248       is normally the argument given to -runtime-variant at compile time, but
249       for byte-code it can be changed after compilation.
250
251
252       Since 4.03.0
253
254
255
256       val runtime_parameters : unit -> string
257
258       Return  the  value of the runtime parameters, in the same format as the
259       contents of the OCAMLRUNPARAM environment variable.
260
261
262       Since 4.03.0
263
264
265
266
267       === Signal handling ===
268
269
270       type signal_behavior =
271        | Signal_default
272        | Signal_ignore
273        | Signal_handle of (int -> unit)
274
275
276       What to do when receiving a signal:
277
278       - Signal_default : take the default behavior (usually: abort  the  pro‐
279       gram)
280
281       - Signal_ignore : ignore the signal
282
283       -  Signal_handle  f  : call function f , giving it the signal number as
284       argument.
285
286
287
288
289       val signal : int -> signal_behavior -> signal_behavior
290
291       Set the behavior of the system on receipt of a given signal.  The first
292       argument  is the signal number.  Return the behavior previously associ‐
293       ated with the signal. If the signal number is invalid (or not available
294       on your system), an Invalid_argument exception is raised.
295
296
297
298       val set_signal : int -> signal_behavior -> unit
299
300       Same as Sys.signal but return value is ignored.
301
302
303
304
305       === Signal numbers for the standard POSIX signals.  ===
306
307
308       val sigabrt : int
309
310       Abnormal termination
311
312
313
314       val sigalrm : int
315
316       Timeout
317
318
319
320       val sigfpe : int
321
322       Arithmetic exception
323
324
325
326       val sighup : int
327
328       Hangup on controlling terminal
329
330
331
332       val sigill : int
333
334       Invalid hardware instruction
335
336
337
338       val sigint : int
339
340       Interactive interrupt (ctrl-C)
341
342
343
344       val sigkill : int
345
346       Termination (cannot be ignored)
347
348
349
350       val sigpipe : int
351
352       Broken pipe
353
354
355
356       val sigquit : int
357
358       Interactive termination
359
360
361
362       val sigsegv : int
363
364       Invalid memory reference
365
366
367
368       val sigterm : int
369
370       Termination
371
372
373
374       val sigusr1 : int
375
376       Application-defined signal 1
377
378
379
380       val sigusr2 : int
381
382       Application-defined signal 2
383
384
385
386       val sigchld : int
387
388       Child process terminated
389
390
391
392       val sigcont : int
393
394       Continue
395
396
397
398       val sigstop : int
399
400       Stop
401
402
403
404       val sigtstp : int
405
406       Interactive stop
407
408
409
410       val sigttin : int
411
412       Terminal read from background process
413
414
415
416       val sigttou : int
417
418       Terminal write from background process
419
420
421
422       val sigvtalrm : int
423
424       Timeout in virtual time
425
426
427
428       val sigprof : int
429
430       Profiling interrupt
431
432
433
434       val sigbus : int
435
436       Bus error
437
438
439       Since 4.03
440
441
442
443       val sigpoll : int
444
445       Pollable event
446
447
448       Since 4.03
449
450
451
452       val sigsys : int
453
454       Bad argument to routine
455
456
457       Since 4.03
458
459
460
461       val sigtrap : int
462
463       Trace/breakpoint trap
464
465
466       Since 4.03
467
468
469
470       val sigurg : int
471
472       Urgent condition on socket
473
474
475       Since 4.03
476
477
478
479       val sigxcpu : int
480
481       Timeout in cpu time
482
483
484       Since 4.03
485
486
487
488       val sigxfsz : int
489
490       File size limit exceeded
491
492
493       Since 4.03
494
495
496
497       exception Break
498
499
500       Exception raised on interactive interrupt if Sys.catch_break is on.
501
502
503
504       val catch_break : bool -> unit
505
506
507       catch_break  governs  whether interactive interrupt (ctrl-C) terminates
508       the program or raises the Break exception.  Call  catch_break  true  to
509       enable  raising  Break , and catch_break false to let the system termi‐
510       nate the program on user interrupt.
511
512
513
514       val ocaml_version : string
515
516
517       ocaml_version is the version of OCaml.  It is  a  string  of  the  form
518       major.minor[.patchlevel][+additional-info]  , where major , minor , and
519       patchlevel are integers, and additional-info is  an  arbitrary  string.
520       The [.patchlevel] and [+additional-info] parts may be absent.
521
522
523
524       val enable_runtime_warnings : bool -> unit
525
526       Control  whether  the OCaml runtime system can emit warnings on stderr.
527       Currently, the only supported warning is triggered when a channel  cre‐
528       ated  by  open_*  functions is finalized without being closed.  Runtime
529       warnings are enabled by default.
530
531
532       Since 4.03.0
533
534
535
536       val runtime_warnings_enabled : unit -> bool
537
538       Return whether runtime warnings are currently enabled.
539
540
541       Since 4.03.0
542
543
544
545
546       === Optimization ===
547
548
549       val opaque_identity : 'a -> 'a
550
551       For the purposes  of  optimization,  opaque_identity  behaves  like  an
552       unknown (and thus possibly side-effecting) function.
553
554       At runtime, opaque_identity disappears altogether.
555
556       A  typical  use  of  this function is to prevent pure computations from
557       being optimized away in benchmarking loops.  For example: for _round  =
558       1  to  100_000 do ignore (Sys.opaque_identity (my_pure_computation ()))
559       done
560
561
562
563       Since 4.03.0
564
565
566
567
568
569OCamldoc                          2019-02-02                            Sys(3)
Impressum