Open longshorej opened 7 years ago
Here's a complete example for Scala (uses the jna
library for native callouts):
package example
import com.sun.jna.{ Native, NativeLibrary }
import java.nio.file.{ Files, NoSuchFileException, Paths }
object Hello extends App {
Native.register(NativeLibrary.getProcess());
@native def close(fd: Int): Int
@native def getpid(): Int
def closeInheritedFds(): Unit = {
val pid = getpid()
try {
val dirStream = Files.newDirectoryStream(Paths.get(s"/proc/$pid/fd", "\\d*"))
try {
dirStream.forEach { path =>
val fd = path.getFileName.toString.toInt
if (fd > 2) close(fd) // Don't close stdin/stderr/stdout (> 2)
}
} finally {
dirStream.close()
}
} catch {
case _: NoSuchFileException =>
}
}
closeInheritedFds()
}
According to the referenced NuProcess issue, this was fixed in NuProcess 1.2 and this project is now using 1.24.
It was fixed in https://github.com/typesafehub/akka-contrib-extra/commit/7ca1ec0c6ce496fa902a57199b50b95e580f8636 but it has not yet been released.
@2m Thanks for the update. BTW - I think that this project is a good candidate for inclusion in alpakka.
Is there any chance to move this project to akka organizations ?
@dpennell @hepin1989 I think we want to eventually phase out this library and move individual pieces either into Akka, Alpakka, or 'personal' repositories of maintainers outside of the Akka organization. Probably best to create issues about individual pieces in the respective repositories. I'll add a note to the README.
@raboof - My comment was only about the process package. I'll open a ticket in the Alpakka project.
On Linux, processes spawned by
NonBlockingProcess
inherit the JVM's open file descriptors. The underlying cause it due to this NuProcess issue.The following can be used as a work-around -- spawn
bash
to run these commands, and thenexec
the command you wished to spawn: