/* What can a file descriptor describe? * A file * A pipe * A piece of information from the kernel that looks like a file but isn't * A network socket (we'll leave that for 435) * A hardware device * A thing that looks like a hardware device but is actually done in software */ #include #include #include #include int main(){ int fd = open("/proc/version", O_RDONLY); if(fd == -1){ perror(""); return 1; } char buffer[1024]; memset(buffer, 0, sizeof(buffer)); printf("The version is: "); while(read(fd, buffer, sizeof(buffer)-1)){ printf("%s", buffer); memset(buffer, 0, sizeof(buffer)); } close(fd); return 0; }