Created
October 1, 2019 20:00
-
-
Save kannangce/f6c0a9d43c1632be8e72b55e45044e7a to your computer and use it in GitHub Desktop.
Showcase on capturing and making use of SIG_PIPE
This file contains 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; | |
/** | |
* 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