# tail memory usage



## pelmen (Oct 26, 2011)

Hi

It is true that the tail(1) utilites stored all processed information in memory? For example, I do not really understand why `tail /dev/zero` eats my memory. I understand that the "tail /dev/zero" - silly and infinity, this is an example.


----------



## SirDice (Oct 26, 2011)

One of the great things about FreeBSD is that you can take a look at the source code.

http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/tail/


----------



## pelmen (Oct 26, 2011)

SirDice said:
			
		

> One of the great things about FreeBSD is that you can take a look at the source code.
> 
> http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/tail/



Yea!
As I see  http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/tail/read.c?rev=1.16.2.1;content-type=text%2Fplain


```
while ((ch = getc(fp)) != EOF) {
...
			if ((sp = realloc(sp, blen += 1024)) == NULL)
...
				if ((llines[recno].l = realloc(llines[recno].l,
.....
	if (ferror(fp)) {
		ierr(fn);
		rc = 1;
		goto done;
	}
....
	}
done:
	for (cnt = 0; cnt < off; cnt++)
[color="Red"]		free(llines[cnt].l);
	free(sp);[/color]
```

looks like that without EOF and error - free to not come never.

I was just searching for confirmation - I figured that the tail is working on fseek and kqueue occupying a minimum of memory. It turns out that for large ascii files, tail is not economical, and in some cases, better use logtail / retail (reading by offset from previous execution).


----------

