1 #include <sys/types.h> 2 #include <sys/wait.h> 3 #include <fcntl.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <unistd.h> 7 8 int 9 main(int argc, char *argv[]) 10 { 11 int fd, fd_parent; 12 char buf[1]; 13 14 if (argc != 2) { 15 return 1; 16 } 17 18 fd_parent = atoi(argv[1]); 19 20 /* If we open a new file, the fd we obtain should be fd_parent + 1 */ 21 fd = open("open_plusplus_fd", O_CREAT|O_RDWR, 0660); 22 if (fd != fd_parent + 1) { 23 return 2; 24 } 25 26 /* Also, writing to fd_parent should succeed */ 27 if (write(fd_parent, buf, sizeof(buf)) <= 0) { 28 return 3; 29 } 30 31 return 0; 32 } 33 34