Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] cat /dev/zero > /dev/null



On Sat, Mar 15, 2003 at 03:40:59AM -0800, Pietro Zuco wrote:
> Hello.
> 
> I proved this and find with top that the proccess takes the 98% of my cpu.
> I googling a bit and find that a lot of people talk about this but I
> coundn't find a way to solve the problem.

there isnt really, /dev/zero will generate 0s as fast as it can, /dev/null
will swallow as fast as it can, whats taking most of the CPU is cat doing
it's read/write loop. 

> Any user can do it and the system got slow until I stop the proccess.
> 

This is where a computer mis-use policy comes in.

> If I change the permissions there are software that need to use /dev/zero
> and /dev/null
> 

You cant do these, here is why. malloc allocates memory by mmaping against
/dev/zero, so any user process that needs dynamic memory will need
permission here. Also a lot processes open /dev/null, for various things
(output redirects...), you can see it by "strace <progname>".

> Some idea to avoid this? Maybe some " cpu quota " for limit the cpu usage of
> users?

"ulimit -t" can place cpu limits, although a user can change them. There
is a way to set a hard limit, but I have forgotten it. The corresponding C
functions are: getrlimit and setrlimit, you could re-compile cat with
these in.

tbh though there are much worse things a local user can do, chewing up all
the cpu with one process is not that bad, you can kill it. Fork bombs on
the other had will often kill a Linux box completly as the scheduler
cannot handle all the processes (the Linux scheduler is not very good in
this respect, Solaris and others can withstand a fork bomb and return
happily). There is even a 10 char string which will cause bash for
fork bomb. Then of course there are the other things, malloc bombs and all
manner of nasties that you can do with a shell account. ulimit will
protect against accidents though.

Tim.

-- 
"ergo it is easier to drag sheep downhill" - Applied Ergonomics Magasine
Tim Hurman - Email: kano at kano.org.uk - Phone: Yeah right.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links