sure! this is the "lots of files" program.
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define BSZ 2000
unsigned char buf[BSZ+256];
main ()
{
int fd,i,j;
unsigned int ctr=0;
unsigned char r=0;
char f1[32],f2[32],f3[32],f4[32];
while (1)
{
sprintf (f1,"fxa_%06d",ctr++); sprintf (f2,"fxa_%06d",ctr++);
sprintf (f3,"fxa_%06d",ctr++); sprintf (f4,"fxa_%06d",ctr++);
fd = open (f1,O_CREAT | O_RDWR);
memset (buf,r++,BSZ+256); write (fd,buf,BSZ+r); close (fd);
fd = open (f2,O_CREAT | O_RDWR);
memset (buf,r++,BSZ+256); write (fd,buf,BSZ+r); close (fd);
fd = open (f3,O_CREAT | O_RDWR);
memset (buf,r++,BSZ+256); write (fd,buf,BSZ+r); close (fd);
fd = open (f4,O_CREAT | O_RDWR);
memset (buf,r++,BSZ+256); write (fd,buf,BSZ+r); close (fd);
unlink (f1); unlink (f2); unlink (f3); unlink (f4);
if (!r)
fprintf (stdout,".");fflush (stdout);
}
}
and this is the "gimme 300MB even though free sez I hardly have
anything" program:
#define BS (30*1024*1024)
main()
{
char *x;
x = malloc (BS);
if (!x)
printf ("heh - x is NULL\n");
else
{
printf ("allocd\n");
memset (x,0x31,BS);
printf ("set\n");
free (x);
printf ("freed\n");
}
}
> On your machine it'll be "all of swap plus all of physical memory
> minus whatever malloc'ed memory you're using now minus 8-12 megabytes".
> There isn't much memory which cannot be reclaimed unless you have a
> huge machine or you're doing odd things.
this is useful advice, thanks. Basically what the new procps does?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/