openloop.c 479 Bytes
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>

main(int argc, char **argv)
{
	int fd, loop;
	char *fname;
	char *pname;

	pname = *argv++;
	if (argc < 2) {
		printf("Usage: %s <file>\n", pname);
		exit(1);
	}
	fname = *argv;

	printf("Open and close %s\n", fname);

	for (loop = 0; ; loop++) {
		if ((fd = open(fname, O_RDWR)) >= 0) {
			close(fd);
		} else
			perror(fname);
		if ((loop & 3) == 0)
			printf("Loop: %d\r", loop);
	}
	
	exit(0);
}