How can I create a process using Unix.create_process in OCaml?

I tried

let _ = Unix.create_process "ls" [||] Unix.stdin Unix.stdout Unix.stderr

in utop, this will destroy it all.

If I write this to .mland compile and run, this will cause the terminal to crash and my ubuntu will cause a system error.

But why?

+4
source share
2 answers

The correct way to call it:

let pid = Unix.create_process "ls" [|"ls"|] Unix.stdin Unix.stdout Unix.stderr

The first element of the array must be the name of the command.

On some systems, /bin/lsthere is a link to some larger executable that will look at argv.(0)to know how to behave (cf Busybox ); so you really need to provide this information.

( , /usr/bin/vi, , vim).

+7

Unix.create_process fork execvpe, execv ( OCaml C Unix). cstringvect ( C ), arg C, ​​ NULL. , execve .. (. execve(2) linux man), :

argv - , .        , ,         .

(, , ) , , ls, top ..

+4

Source: https://habr.com/ru/post/1542490/


All Articles