fork download
  1. /** Demonstrate that fcntl(fd, F_GETFL) may fail.
  2.  
  3.   $ gcc *.c && ./a.out
  4. */
  5.  
  6. #include <stdlib.h>
  7.  
  8. #include <unistd.h>
  9. #include <fcntl.h>
  10.  
  11. int main(void) {
  12. int invalid_fd = -1;
  13. if (fcntl(invalid_fd, F_GETFL) == -1) {
  14. perror("fcntl");
  15. exit(EXIT_FAILURE);
  16. }
  17. return 0;
  18. }
  19.  
Runtime error #stdin #stdout #stderr 0s 2288KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
fcntl: Bad file descriptor