Michael Norrish wrote:
Incidentally, on the machine where Posix.Process.exec("/bin/ls", []) seg. faults, Unix.execute("/bin/ls", []) works correctly. The Basis library documentation I have for the Unix structure doesn't discuss how the argv component should be setup, but attempting

  Unix.execute("/bin/ls", ["ls"])

prompts a message from ls saying that there is no file called ls.

This doesn't seem consistent.

Curiously, on the Macbook where Posix.Process.exec gives ENOTSUP, Unix.execute does work.

It turns out that on Mac OS X execv returns ENOTSUP if the process is multi-threaded. You need to use Posix.Process.fork first to start a new process:
case Posix.Process.fork() of
   SOME _ => OS.Process.exit OS.Process.success
 | NONE => Posix.Process.exec("/bin/ls", ["ls"]);

This isn't documented in Apple's man page for execv and I found the explanation at
http://factor-language.blogspot.com/2007/07/execve-returning-enotsup-on-mac-os-x.html

Unix.execute is implemented in terms of fork and exec and the exec is called in the child process, roughly the code above.

The arguments for Posix.Process.exec and Unix.execute are different. The basis library book (Ganser and Reppy 2004) says for Unix.execute "execute(cmd, args) asks the operating system to execute the program named by the string cmd with the argument list args." For Posix.Process.exec it says "The args argument is a list of string arguments to be passed to the new program. By convention, the first item in args is some form of the filename of the new program, usually the last arc in the path or filename." Like any informal specification this is subject to interpretation but I think the current behaviour conforms to this definition.

David
_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

Reply via email to