Skip to content

Instantly share code, notes, and snippets.

@kannangce
Created October 1, 2019 20:00
Show Gist options
  • Save kannangce/f6c0a9d43c1632be8e72b55e45044e7a to your computer and use it in GitHub Desktop.
Save kannangce/f6c0a9d43c1632be8e72b55e45044e7a to your computer and use it in GitHub Desktop.
Showcase on capturing and making use of SIG_PIPE
import sun.misc.Signal;
import sun.misc.SignalHandler;
/**
* Demo on making use of SIG_PIPE
*
*/
public class RespectSigPipe
{
static boolean isPipeRecieved = false;
public RespectSigPipe() {
Signal.handle(new Signal("PIPE"), new SignalHandler() {
@Override
public void handle(Signal arg0) {
isPipeRecieved = true;
}
});
}
private void printToInfinite()
{
while(!isPipeRecieved)
{
System.out.println( "Hello World!!!");
}
}
public static void main( String[] args )
{
RespectSigPipe demo = new RespectSigPipe();
demo.printToInfinite();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment