Created
September 3, 2015 11:45
-
-
Save wookietreiber/4f974318227428072b86 to your computer and use it in GitHub Desktop.
handle SIGPIPE in Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.