@@ -10,6 +10,7 @@ module Node.UnsafeChildProcess.Safe
1010 , messageH
1111 , spawnH
1212 , pid
13+ , pidExists
1314 , connected
1415 , disconnect
1516 , exitCode
@@ -36,7 +37,7 @@ import Data.Posix.Signal as Signal
3637import Effect (Effect )
3738import Effect.Uncurried (EffectFn1 , EffectFn2 , mkEffectFn1 , mkEffectFn2 , runEffectFn1 , runEffectFn2 )
3839import Foreign (Foreign )
39- import Node.ChildProcess.Types (Exit (..), Handle , KillSignal , StdIO , UnsafeChildProcess , ipc , pipe , stringSignal )
40+ import Node.ChildProcess.Types (Exit (..), Handle , KillSignal , StdIO , UnsafeChildProcess , intSignal , ipc , pipe , stringSignal )
4041import Node.Errors.SystemError (SystemError )
4142import Node.EventEmitter (EventEmitter , EventHandle (..))
4243import Node.EventEmitter.UtilTypes (EventHandle0 , EventHandle1 )
@@ -79,6 +80,11 @@ pid cp = map toMaybe $ runEffectFn1 pidImpl cp
7980
8081foreign import pidImpl :: EffectFn1 (UnsafeChildProcess ) (Nullable Pid )
8182
83+ -- | Note: this will not work if the user does not have permission to kill
84+ -- | a `PID`. Uses `cp.kill(0)` underneath.
85+ pidExists :: UnsafeChildProcess -> Effect Boolean
86+ pidExists cp = kill' (intSignal 0 ) cp
87+
8288-- | Indicates whether it is still possible to send and receive
8389-- | messages from the child process.
8490connected :: UnsafeChildProcess -> Effect Boolean
0 commit comments