waitpid with a time limit
From: Frank J. Lhota (NOSPAM.lhota_at_adarose.com)
Date: 09/14/05
- Next message: Georg Acher: "Re: waitpid with a time limit"
- Previous message: Bill Marcum: "Re: Strange gcc warnings on AMD64"
- Next in thread: Georg Acher: "Re: waitpid with a time limit"
- Reply: Georg Acher: "Re: waitpid with a time limit"
- Reply: Kasper Dupont: "Re: waitpid with a time limit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 14 Sep 2005 14:58:47 GMT
My company may be getting a contract to port a Win32 application to
Linux (Yay!). In my off hours, I have been going through the source code
in order to figure out how to port the Win32 API calls to Posix.
For the most part, the Win32 stuff I'm seeing have straightforward Posix
equivalents. There is one Win32 trick, however, where I'm not quite what
the optimal Posix equivalent would be. At one point, the application
spawns another process, and waits up to X number of seconds to
terminate. If the spawned process does not terminate within X seconds,
the main application assumes that something has gone wrong and takes
corrective action.
The Linux / Posix waitpid function does wait for a given process to
terminate. But waitpid() basically waits forever, whereas we need
something with a time limit. Since this application uses lots of
threads, using an alarm signal seems ill-advised.
One approach would be to create a thread that would spawn the
child process and wait for the child to complete. This new thread could
indicate the completion of the child process by posting to a semaphore.
Then we simulate a timed waitpid() call by making a sem_timedwait() call
on this semaphore. This may work, but it seems sort of wasteful to
create a thread purely for the purpose of waiting for a child process to
complete.
Is there a better way to get the effect of a timed waitpid() call?
-- "All things extant in this world, Gods of Heaven, gods of Earth, Let everything be as it should be; Thus shall it be!" - Magical chant from "Magical Shopping Arcade Abenobashi" "Drizzle, Drazzle, Drozzle, Drome, Time for the this one to come home!" - Mr. Lizard from "Tutor Turtle"
- Next message: Georg Acher: "Re: waitpid with a time limit"
- Previous message: Bill Marcum: "Re: Strange gcc warnings on AMD64"
- Next in thread: Georg Acher: "Re: waitpid with a time limit"
- Reply: Georg Acher: "Re: waitpid with a time limit"
- Reply: Kasper Dupont: "Re: waitpid with a time limit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|