Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gracefully terminate a process created from scala

Tags:

scala

I am currently using the scala process API scala.sys.processbut, I can't seem to figure out how to gracefully terminate a process that react to the SIGTERM signal. I've done it in python before where there are pretty terminate and send_signal function on the process, but on the scala scala.sys.process.Process object, all I see is destroy. To me it look like scala will nuke my process from orbit, just to be sure, and thats not what I want.

How can I tell this process that it should clean itself and exit from my scala code?

val launcher = Process("myprocess", Seq("args"))
val process = launcher.run()
process.destroy() //Err... no? terminate or equivalent like in python please?

EDIT

For more detail : My scala process is launching a C++ subprocess, that listen to signal handler (SIGTERM, SIGKILL and the like) to know when to exit. It has been well tested and it clean itself correctly. My problem is that I don't know how to send that signal from my scala application! Thus, my C++ process always get dragged outside and shot instead of just being asked to stop.

like image 694
Laurent Bourgault-Roy Avatar asked May 28 '12 01:05

Laurent Bourgault-Roy


1 Answers

Scala Process stuff is based on Java's, and, therefore, subject to the same limitations. Java provides a very poor interface. Perhaps it makes it possible to use the same interface on more systems, but it is incredibly limiting to those working on Posix systems.

like image 137
Daniel C. Sobral Avatar answered Oct 16 '22 17:10

Daniel C. Sobral