1Stdlib.Sys(3) OCaml library Stdlib.Sys(3)
2
3
4
6 Stdlib.Sys - no description
7
9 Module Stdlib.Sys
10
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
35 native 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. Raise Sys_error if no file exists with
49 the given name.
50
51
52 Since 3.10.0
53
54
55
56 val remove : string -> unit
57
58 Remove the given file name from the file system.
59
60
61
62 val rename : string -> string -> unit
63
64 Rename a file. rename oldpath newpath renames the file called oldpath
65 , giving it newpath as its new name, moving it between directories if
66 needed. If newpath already exists, its contents will be replaced with
67 those of oldpath . Depending on the operating system, the metadata
68 (permissions, owner, etc) of newpath can either be preserved or be
69 replaced by those of oldpath .
70
71
72 Since 4.06 concerning the "replace existing file" behavior
73
74
75
76 val getenv : string -> string
77
78 Return the value associated to a variable in the process environment.
79 Raise Not_found if the variable is unbound.
80
81
82
83 val getenv_opt : string -> string option
84
85 Return the value associated to a variable in the process environment or
86 None if the variable is unbound.
87
88
89 Since 4.05
90
91
92
93 val command : string -> int
94
95 Execute the given shell command and return its exit code.
96
97
98
99 val time : unit -> float
100
101 Return the processor time, in seconds, used by the program since the
102 beginning of execution.
103
104
105
106 val chdir : string -> unit
107
108 Change the current working directory of the process.
109
110
111
112 val getcwd : unit -> string
113
114 Return the current working directory of the process.
115
116
117
118 val readdir : string -> string array
119
120 Return the names of all files present in the given directory. Names
121 denoting the current directory and the parent directory ( . and .. in
122 Unix) are not returned. Each string in the result is a file name
123 rather than a complete path. There is no guarantee that the name
124 strings in the resulting array will appear in any specific order; they
125 are not, in particular, guaranteed to appear in alphabetical order.
126
127
128
129 val interactive : bool ref
130
131 This reference is initially set to false in standalone programs and to
132 true if the code is being executed under the interactive toplevel sys‐
133 tem ocaml .
134
135
136
137 val os_type : string
138
139 Operating system currently executing the OCaml program. One of
140
141 - Unix (for all Unix versions, including Linux and Mac OS X),
142
143 - Win32 (for MS-Windows, OCaml compiled with MSVC++ or Mingw),
144
145 - Cygwin (for MS-Windows, OCaml compiled with Cygwin).
146
147
148
149 type backend_type =
150 | Native
151 | Bytecode
152 | Other of string
153
154
155 Currently, the official distribution only supports Native and Bytecode
156 , but it can be other backends with alternative compilers, for example,
157 javascript.
158
159
160 Since 4.04.0
161
162
163
164 val backend_type : backend_type
165
166 Backend type currently executing the OCaml program.
167
168
169 Since 4.04.0
170
171
172
173 val unix : bool
174
175 True if Sys.os_type = Unix .
176
177
178 Since 4.01.0
179
180
181
182 val win32 : bool
183
184 True if Sys.os_type = Win32 .
185
186
187 Since 4.01.0
188
189
190
191 val cygwin : bool
192
193 True if Sys.os_type = Cygwin .
194
195
196 Since 4.01.0
197
198
199
200 val word_size : int
201
202 Size of one word on the machine currently executing the OCaml program,
203 in bits: 32 or 64.
204
205
206
207 val int_size : int
208
209 Size of int , in bits. It is 31 (resp. 63) when using OCaml on a 32-bit
210 (resp. 64-bit) platform. It may differ for other implementations, e.g.
211 it can be 32 bits when compiling to JavaScript.
212
213
214 Since 4.03.0
215
216
217
218 val big_endian : bool
219
220 Whether the machine currently executing the Caml program is big-endian.
221
222
223 Since 4.00.0
224
225
226
227 val max_string_length : int
228
229 Maximum length of strings and byte sequences.
230
231
232
233 val max_array_length : int
234
235 Maximum length of a normal array (i.e. any array whose elements are not
236 of type float ). The maximum length of a float array is max_floatar‐
237 ray_length if OCaml was configured with --enable-flat-float-array and
238 max_array_length if configured with --disable-flat-float-array .
239
240
241
242 val max_floatarray_length : int
243
244 Maximum length of a floatarray. This is also the maximum length of a
245 float array when OCaml is configured with --enable-flat-float-array .
246
247
248
249 val runtime_variant : unit -> string
250
251 Return the name of the runtime variant the program is running on. This
252 is normally the argument given to -runtime-variant at compile time, but
253 for byte-code it can be changed after compilation.
254
255
256 Since 4.03.0
257
258
259
260 val runtime_parameters : unit -> string
261
262 Return the value of the runtime parameters, in the same format as the
263 contents of the OCAMLRUNPARAM environment variable.
264
265
266 Since 4.03.0
267
268
269
270
271 Signal handling
272 type signal_behavior =
273 | Signal_default
274 | Signal_ignore
275 | Signal_handle of (int -> unit)
276
277
278 What to do when receiving a signal:
279
280 - Signal_default : take the default behavior (usually: abort the pro‐
281 gram)
282
283 - Signal_ignore : ignore the signal
284
285 - Signal_handle f : call function f , giving it the signal number as
286 argument.
287
288
289
290
291 val signal : int -> signal_behavior -> signal_behavior
292
293 Set the behavior of the system on receipt of a given signal. The first
294 argument is the signal number. Return the behavior previously associ‐
295 ated with the signal. If the signal number is invalid (or not available
296 on your system), an Invalid_argument exception is raised.
297
298
299
300 val set_signal : int -> signal_behavior -> unit
301
302 Same as Sys.signal but return value is ignored.
303
304
305
306
307 Signal numbers for the standard POSIX signals.
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 val opaque_identity : 'a -> 'a
548
549 For the purposes of optimization, opaque_identity behaves like an
550 unknown (and thus possibly side-effecting) function.
551
552 At runtime, opaque_identity disappears altogether.
553
554 A typical use of this function is to prevent pure computations from
555 being optimized away in benchmarking loops. For example: for _round =
556 1 to 100_000 do ignore (Sys.opaque_identity (my_pure_computation ()))
557 done
558
559
560
561 Since 4.03.0
562
563
564
565
566
567OCamldoc 2019-07-30 Stdlib.Sys(3)