File tree Expand file tree Collapse file tree 1 file changed +25
-6
lines changed
io/native/src/main/scala/fs2/io/process Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ import java.io.IOException
3737import cats .effect .LiftIO
3838import cats .effect .IO
3939import org .typelevel .scalaccompat .annotation ._
40+ import scala .concurrent .duration .*
41+ import cats .effect .implicits .*
4042
4143@ extern
4244@ nowarn212(" cat=unused" )
@@ -247,13 +249,30 @@ private[process] trait ProcessesCompanionPlatform extends Processesjvmnative {
247249 }
248250 }
249251
250- private def fallbackExitValue (pid : pid_t): F [Int ] =
251- F .blocking {
252- val status = stackalloc[CInt ]()
253- val result = waitpid(pid, status, 0 )
254- if (result == pid) WEXITSTATUS (! status)
255- else throw new IOException (s " waitpid failed with errno: ${errno.errno}" )
252+ private def fallbackExitValue (pid : pid_t): F [Int ] = {
253+ def loop : F [Int ] =
254+ F .blocking {
255+ Zone { _ =>
256+ val status = stackalloc[CInt ]()
257+ val result = waitpid(pid, status, WNOHANG )
258+
259+ if (result == pid) {
260+ Some (WEXITSTATUS (! status))
261+ } else if (result == 0 ) None
262+ else throw new IOException (s " waitpid failed with errno: ${errno.errno}" )
263+ }
264+ }.flatMap {
265+ case Some (code) => F .pure(code)
266+ case None => F .sleep(10 .millis) >> loop
267+ }
268+
269+ loop.onCancel {
270+ F .blocking {
271+ kill(pid, SIGKILL )
272+ ()
273+ }
256274 }
275+ }
257276 }
258277 } else super .forAsync[F ]
259278}
You can’t perform that action at this time.
0 commit comments