logoISU  

CS 456 - Systems Programming

Spring 2024

Displaying ./code/jan25/fd.c

#include <stdio.h>
//#include <sys/types.h>
//#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

int main (int argc, char **argv){

	if (argc < 2){
	   fprintf(stderr, "Usage %s file\n",argv[0]);
	   exit(1);
	}

	//open a file, print it's file descriptor, then exit)

	for (int i = 1; i < argc; i++){
	    
		int fd = open(argv[i], O_RDONLY);

		printf("fd of %s: %d\n", argv[i], fd);

		close(fd);
	}





	return 0;

}