feather icon indicating copy to clipboard operation
feather copied to clipboard

Invalid argument from Unix.kill

Open charlesetc opened this issue 3 years ago • 3 comments

Trying to run this code:

let () =
  let process =
    process "bash" [ "-c"; "for i in `seq 1 5` ; do echo $i ; sleep 1 ; done" ]
    |> run_in_background
  in
  ignore process

results in this exception

Uncaught exception:
  
  (Unix.Unix_error "Invalid argument" kill "")

Raised by primitive operation at Feather.terminate_child_processes.(fun) in file "feather.ml", line 626, characters 13-38
Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Called from Stdlib.at_exit.new_exit in file "stdlib.ml", line 554, characters 59-63
Called from Stdlib.do_at_exit in file "stdlib.ml" (inlined), line 560, characters 20-61
Called from Std_exit in file "std_exit.ml", line 18, characters 8-20

I'm not sure what "invalid argument" means from Unix.kill but I bet it'd be easy to fix if we knew...

charlesetc avatar Aug 14 '21 21:08 charlesetc

This seems to happen when you don't wait on processes you started in the background, which isn't a great thing to do in general. Maybe we should make the default to wait before exiting?

charlesetc avatar Aug 14 '21 21:08 charlesetc

I have at least one use case where I want to completely detach a background process, i.e. use a feather script as a "lancher" for a long-term background application. Currently this works because of this exception (and so the child process is not killed and continues to run).

Waiting by default should be good, but I wonder if it is doable to provide a means to completely detach a child process (in this case of course nothing can be collected).

Firobe avatar Aug 18 '21 15:08 Firobe

Yeah agreed, it'd be necessary to add an option to detach a child process.

charlesetc avatar Oct 09 '21 03:10 charlesetc