RE: wait(2)
"Simon Marlow" <[EMAIL PROTECTED]> wrote, > I've been looking at FreeBSD's `kevent' stuff recently > - they have a really nice way to wait for several different types of > event, including file descriptors, processes and even when a file is > modified (eg. tail -f). Does Linux or Solaris have anything like this? > I had a quick look around but didn't find anything. Linus doesn't seem to be in favour of the approach as at the end of http://kt.linuxcare.com/kernel-traffic/kt20001113_93.epl#1 he writes I've actually read the BSD kevent stuff, and I think it's classic over-design. It's not easy to see what it's all about, and the whole tuple crap is just silly. Looks much too complicated. But not everybody seems to agree with that: http://www.uwsg.indiana.edu/hypermail/linux/kernel/0011.0/0083.html Cheers, Manuel ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: wait(2) [Slight correction]
[My previous message omitted a word ("records"). I should take one more look at these things before sending them.] Scsh (Scheme Shell) has a mechanism to turn the Unix process interface into something reasonable. Instead of PIDs, fork returns a process object. The SIGCHLD signal handler reaps processes and records their exit status. The program can retrieve the exit status using the process object. When the process object is GCed, the status can be as well. This seems be right for almost all code (and reaping policy can be changed for the remaining code.) The details of Scsh's mechanism can be found in the manual ftp://ftp-swiss.ai.mit.edu/pub/su/scsh/scsh-manual.ps on pages 55-58. mike ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: wait(2)
Scsh (Scheme Shell) has a mechanism to turn the Unix process interface into something reasonable. Instead of PIDs, fork returns process objects. The SIGCHLD signal handler reaps processes and their exit status. The program can retrieve the exit status using the process object. If the process object is GCed, the status can be as well. This seems be right for almost all code (and reaping policy can be changed for the remaining code.) The details of Scsh's mechanism can be found in the manual ftp://ftp-swiss.ai.mit.edu/pub/su/scsh/scsh-manual.ps on pages 55-58. mike ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
RE: wait(2)
> This is interesting, but not what I want. I want something to wait on > a real, Posix, child, _process_!! Not a GHC thread. Ah. Oops :) There's one other way that Marcin didn't mention: wait for SIGCHLD, which can be done without blocking the whole process. Unfortunately there's no easy way at the moment to tell *which* child generated the SIGCHLD. I guess we should really have a process wait as a threading primitive, like OCaml does. I've been looking at FreeBSD's `kevent' stuff recently - they have a really nice way to wait for several different types of event, including file descriptors, processes and even when a file is modified (eg. tail -f). Does Linux or Solaris have anything like this? I had a quick look around but didn't find anything. Cheers, Simon ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: wait(2)
George Russell <[EMAIL PROTECTED]> wrote, > Is there a way in Glasgow Haskell to get a thread to wait on a child process > in the same way as the Posix function wait(), and get the termination status > of the child? If so, how? This is what I use when I want to avoid that wait()ing for a process in one thread blocks the whole Haskell runtime: waitForExitCode pid = do status <- do status <- getProcessStatus False False pid -- Note: With WNOHANG, waitpid() can have a return value of -- 0 and still an `errno != 0'; the current -- implementation of `getProcessStatus' doesn't handle -- this case. errno <- getErrorCode if errno == noChildProcess then do return $ Just (Exited ExitSuccess) else return status case status of Nothing -> do threadDelay 1-- wait 10ms waitForExitCode pid vec Just (Exited ec ) -> return ec Just (Terminated sig) -> return $ ExitFailure (128 + sig) Just _-> -- can't happen, as second argument = `False' error "Processes.proc: Stopped?" Cheers, Manuel ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: wait(2)
Thu, 26 Jul 2001 16:44:57 +0200, George Russell <[EMAIL PROTECTED]> pisze: > Is there a way in Glasgow Haskell to get a thread to wait on a > child process in the same way as the Posix function wait(), and > get the termination status of the child? There is no easy way: all Haskell's thread run in the same process and wait() blocks the whole process. The only (or the only portable) way is to call wait() with WNOHANG repeatedly in a thread and threadDelay for a short period of time between calls. This is what OCaml runtime does. It provides waiting for a process as a threading primitive. It accounts for waiting in its select() loop in the scheduler. -- __("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
RE: wait(2)
> Is there a way in Glasgow Haskell to get a thread to wait on > a child process > in the same way as the Posix function wait(), and get the > termination status > of the child? If so, how? There's a couple of ways. The obvious way is to get the thread to place its result in an MVar when it exits: there's a guarantee that a thread always either exits or raises an exception, so you can wrap the top-level computation in something that places the result/exception in an MVar. Alternatively, you can foreign import rts_evalIO() and do it that way. It ought to work, but I haven't tried it. This way lets you get at the Interrupted or Deadlocked return states too, which you can't do solely within Haskell. Hmm, now I think about it, the compiler won't let you foreign import rts_evalIO() with the type you want, namely a -> Ptr b -> IO CInt, and quite rightly so. You'll need a version of rts_evalIO() that takes StablePtrs instead. Cheers, Simon ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
wait(2)
Is there a way in Glasgow Haskell to get a thread to wait on a child process in the same way as the Posix function wait(), and get the termination status of the child? If so, how? ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users