/usr/lib/swipl/library/ext/clib/unix.pl
All Application Manual Name SummaryHelp

  • ext
    • clib
      • socket.pl -- Network socket (TCP and UDP) library
      • uid.pl
      • unix.pl -- Unix specific operations
        • fork/1
        • fork_exec/1
        • exec/1
        • wait/2
        • kill/2
        • pipe/2
        • dup/2
        • detach_IO/1
        • detach_IO/0
        • prctl/1
        • sysconf/1
      • syslog.pl -- Unix syslog interface
      • memfile.pl
      • time.pl -- Time and alarm library
      • uri.pl -- Process URIs
      • filesex.pl -- Extended operations on files
      • uuid.pl -- Universally Unique Identifier (UUID) Library
      • sha.pl -- SHA secure hashes
      • process.pl -- Create processes and redirect I/O
      • hash_stream.pl -- Maintain a hash on a stream
      • md5.pl -- MD5 hashes
      • rlimit.pl
      • mallocinfo.pl -- Memory allocation details
      • prolog_stream.pl -- A stream with Prolog callbacks
      • crypt.pl
      • streaminfo.pl
      • udp_broadcast.pl -- A UDP broadcast proxy
      • cgi.pl -- Read CGI parameters
      • streampool.pl -- Input multiplexing
 exec(+Command)
Replace the running program by starting Command. Command is a callable term. The functor is the command and the arguments provide the command-line arguments for the command. Each command-line argument must be atomic and is converted to a string before passed to the Unix call execvp(). Here are some examples:
  • exec(ls('-l'))
  • exec('/bin/ls'('-l', '/home/jan'))

Unix exec() is the only way to start an executable file executing. It is commonly used together with fork/1. For example to start netscape on an URL in the background, do:

run_netscape(URL) :-
        (    fork(child),
             exec(netscape(URL))
        ;    true
        ).

Using this code, netscape remains part of the process-group of the invoking Prolog process and Prolog does not wait for netscape to terminate. The predicate wait/2 allows waiting for a child, while detach_IO/0 disconnects the child as a deamon process.