Operating System - HP-UX
1830899 Members
3096 Online
110017 Solutions
New Discussion

Re: programme/script to openfiles

 
SOLVED
Go to solution
steven Burgess_2
Honored Contributor

programme/script to openfiles

Hello

I'm trying to open a specific number of files to try and hit my limit with the below piece of code

#include
#include
#include
#include

int main(int argc, char *argv[])
{
if ( argc != 2 ) {
printf("Usage : %s \n", argv[0]);
exit(1);
}

printf("\nOur pid is %d\n\n", getpid());

int i, fd;
int j = atoi(argv[1]);

for (i = 0; i <= j; i++) {
if ( fd = ( open("/var/tmp/james/open_file", O_RDONLY | O_CREAT, 0600)) < 0 ) {
perror("open");
exit(2);
}
}

printf("Finished %d opens for process %d......\n", i - 1, getpid());

sleep(100);
exit(0);

}


My c knowledge is 0, when I try to compile with

cc openf.c

I get the below

(Bundled) cc: "openf.c", line 18: error 1000: Unexpected symbol: "int".
(Bundled) cc: "openf.c", line 6: error 1705: Function prototypes are an ANSI feature.


Can anyone help or have a perl/c/shell programme to do a similar thing

I'm going home for the day but would be grateful if supplied for the morning

thanks in advance

Steve
take your time and think things through
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: programme/script to openfiles

Your problem is that the Bundled C compiler only speaks K&R and knows nothing about ANSI C syntax.

Your functions, including main() must use K & R C, e.g:

int main(int argc, char *argv[])
must be instead:
int main(argc,argv)
int argc;
char *argv[];
{

}
If it ain't broke, I can fix that.