为什么unix排序过程在消耗其输入时没有增长? [英] Why doesn't the unix sort process grow as it consumes its input?

查看:47
本文介绍了为什么unix排序过程在消耗其输入时没有增长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了这一点(观察unix排序的行为):

I tried this (to observe the behaviour of unix sort):

yes | sort & top

我看到的是,正如您所期望的,unix内存使用量正在增长,但是排序过程本身的内存似乎并没有增长:

What I see is the unix memory usage growing, as you would expect, but the sort process itself's memory does not appear to be growing:

Mem:   1689540k total,  1455384k used,   234156k free,   147248k buffers
Swap:  1718268k total,      804k used,  1717464k free,   956216k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
32248 mgregory  20   0 29844  25m  692 R 95.0  1.6   0:32.98 sort               
32247 mgregory  20   0  4036  504  444 S  4.0  0.0   0:01.52 yes             

数字1455348正在迅速增长

The number 1455348 is growing rapidly

29844号没有增长.

The number 29844 is not growing.

那里发生了什么事?

推荐答案

Unix Sort使用外部R-Way合并排序算法.它基本上将输入分成相似大小的较小部分(适合内存),然后将每个部分最后合并在一起.

Unix Sort uses an External R-Way merge sorting algorithm. It basically divides the input up into smaller portions of similar size (that fit into memory) and then merges each portion together at the end.

文件的那些小部分(在排序过程中除外)存储在临时磁盘文件中(通常存储在/tmp中),而不存储在内存中.因此,在排序过程中,Unix Sort命令的内存使用不会增加.

Those small portions of the file, except during its sorting precess, are stored in temporary disk files (usually in /tmp) and not in memory. Therefore the Unix Sort command's memory usage does not increase during the sorting process.

但是为什么unix内存使用量不断增长?仅仅是因为未使用的内存就是浪费的内存". Linux内核保留着大量的文件元数据和所请求的文件,直到看起来更重要的事物将这些数据推出为止.

But why is the unix memory usage growing ? Simply because "unused memory is wasted memory". The Linux kernel keeps around huge amounts of file metadata and files that were requested, until something that looks more important pushes that data out.

这篇关于为什么unix排序过程在消耗其输入时没有增长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆