Skip to content

Instantly share code, notes, and snippets.

@wookietreiber
Created September 3, 2015 11:45
Show Gist options
  • Save wookietreiber/4f974318227428072b86 to your computer and use it in GitHub Desktop.
Save wookietreiber/4f974318227428072b86 to your computer and use it in GitHub Desktop.
handle SIGPIPE in Scala
import sun.misc.Signal
import sun.misc.SignalHandler
object Foo extends App {
val signal = new Signal("PIPE")
val handler = new SignalHandler {
def handle(signal: Signal): Unit = {
Console.err.println(s"""caught signal: $signal""")
sys.exit(128 + signal.getNumber)
}
}
Signal.handle(signal, handler)
while (true) {
println("foo")
Thread.sleep(50)
}
}
@wookietreiber
Copy link
Author

I don't know if it is a convention or there is some deeper logic behind when receiving SIGPIPE to exit with status code 141.

But: 141 = 128 + 13 and SIGPIPE number is 13. There must be a connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment