2008-02-13
如何将视频文件刻录到DVD光盘中并在电视上播放呢?
我一开始想在我的笔记本(DELL, WinXP,DVD-RW)上实现这个想法,但是失败了:
- 用Nero自带的光盘来刻录DVD,结果这个软件是体验版本的,马上过期了,更恶心的是刻录过程中需要用到的一个杜比插件还需要另行购买,否则就算刻录上去了在电视上一放也是没有声音的;
- 用Microsoft的什么Photo Story 3,更惨,需要购买一个19美刀的刻录插件!!
后来我决定看看Ubuntu如何,结果让我更加觉得以前生活在Windows的黑暗中 - 在Ubuntu下有多种方式可以满足我的需求:
S1.这个方案复杂一些
ffmpeg -i myfile.avi -target pal-dvd /tmp/dvd.mpg
Then make an iso of your movie.
mkiso movie.mpg
Or if you havce multiple mpgs to burn and would like a menu systsem
todisc -files 1.mpg 2mpg -titles "One" "Two" -out movie_dvd
This will create raw files which you can burn with k3b as a dvd project.
S2.安装并使用TOVID
http://tovid.wikia.com
Install Dependancies
sudo apt-get update && sudo apt-get install mplayer mencoder mjpegtools ffmpeg python python-dev python-wxgtk2.6 python-imaging imagemagick dvdauthor dvd+rw-tools vcdimager transcode sox normalize-audio txt2tags lsdvd python-cairo
install tovid.
tovid also have a gui was helps with a lot of the above. (tovidgui)
S3.这个方案最简单 - 使用DeVeDe这个软件轻松搞定!
sudo apt-get install devede
后记:最后我用DeVeDe把视频文件(投名状)转换成一个.ISO文件,再用Nerolinux刻录到可擦写DVD上然后放给家里人看的.
2008-01-16
I installed CVS on my Ubuntu 7.10
I installed CVS on my Ubuntu 7.10 in order to have the version control for some projects. Especially record the history of the source files I modified. What I did while setting up CVS server as following.
1. Install CVS client:
root@xtrf74:# sudo apt-get install cvs
2. Install CVS server:
root@xtrf74:# sudo apt-get –purge remove cvsd // remove old cvsd from Ubuntu 7.10
root@xtrf74:# sudo apt-get install cvsd
A blue screen will be shown to prompt you enter the location of the repository. Just remove the default value ( /demo:/mycvs or something like that ), and type a new one. E.g. /cvsroot
3. Configure CVS:
build the cvsroot:
root@xtrf74:# cd /var/lib/cvsd
root@xtrf74:# sudo cvsd-buildroot /var/lib/cvsd
create the folder cvsroot under /var/lib/cvsd:
root@xtrf74:# sudo mkdir cvsroot
and then create the repository:
root@xtrf74:# sudo cvs -d /var/lib/cvsd/cvsroot init
it will set up an empty repository in the CVS root specified in the usual way.
root@xtrf74:# sudo chown -R cvsd:cvsd cvsroot
create a user and password:
root@xtrf74:# sudo cvsd-passwd /var/lib/cvsd/cvsroot +
You will be asked to enter new password for the account.
and then change the AUTH type:
root@xtrf74:# sudo chmod 777 /var/lib/cvsd/cvsroot/CVSROOT/config
root@xtrf74:# sudo vim /var/lib/cvsd/cvsroot/CVSROOT/config
uncomment the "SystemAuth=no" line.
4. Check the configuration:
Run the debug info for CVS:
root@xtrf74:# cvsd-buginfo
You will see the following in the middle of the output, make sure that the last one "Repos /cvsroot" is correct, in some cases it might be something like "/decvs" and you cvs server will break, because they don't match with your setup.
...........................
/etc/cvsd/cvsd.conf:
RootJail /var/lib/cvsd
Uid cvsd
Gid cvsd
Nice 1
Umask 027
PidFile /var/run/cvsd.pid
MaxConnections 10
Log syslog info
Listen * 2401
Repos /cvsroot
...............................
5. Test it(Optional):
root@xtrf74:# cvs -d :pserver:
If you login successful, you will see something similar as below:
cvs login: CVS password file /home/
6. Add new files from,for example, /home/xxx/kscope_src
cd /home/xxx/kscope_src/
cvs –import –m “kscope source” /cvsroot kscope initver
2008-01-15
MO-patches for kscope 1.6.1
2008-01-12 07:44:18
kscope 1.6.1 MO-patches(MO means My Own,注:这只是我个人对kscope的改动,仅限本人使用)
2008.01.12:
1. 默认主界面右边的File type Column我实在看不出来有什么存在的必要,将其删除;
* 程序界面是用QT写的,代码清晰简洁,也使得改动比较容易;
* 代码里面对List View的Column Index一律用数字而不是macro,我添加了一个头文件common_ui.h用来消除这些问题;
2. Total Tag List里面的Type column也是多余的,因为Name前面的小图标已经标识出Type了,应该保持和Source Insight那样简洁就可以了;
3. Create Project->File Types,默认的File Types只有.c和.h,我每次都要把右边所有的其他Types都手动添加过来,也没什么Add All的选项,很麻烦;我准备先改成 - 默认就包含全部Types,以后可以靠考虑加一个"Add All" button,省得一下一下的点;
2008.01.13:
关闭Kscope之前打开了n个文件,那么重新打开kscope的时候就会把那n个文件重新打开,我觉得没必要,因为我往往关注的就是我最后打开的那一个文件;
双击file list会添加一个Tab来显示那个文件,我也觉得没必要,因为我如果想切换到前面的文件的话我也会倾向于使用Ctrl-Tab的快捷键来实现而不是在界面上显示一排的Tab;
总而言之,kscope的multi-tab的界面风格并不适合我
所以我准备分阶段做如下改动:
* Step 1. Keep only one tab; Implement a pool for opened files, and only the active one is visable;
* Step 2. Switch to other file view by using Ctrl+Tab to improve performance;
* Step 3. Remove EditTabs class
* Step 4. Add Shift+F8 functionality as SI;
2008.01.14 Kscope的线程
* Kscope里面只有一个线程:DirScanner,从QThread继承下来的 - Scans a directory for files matching a given pattern, using a separate thread.是不是可以考虑增加几个线程以增强界面的使用感受
* 用Valgrind或其他工具对Kscope进行分析,看看是不是有memory leak,看看是不是有影响性能的关键调用以便优化
Bcharge(1)
2008-01-09 20:18:12
忽然对前天提到的Bcharge的实现感兴趣: 它是怎么实现通过USB给Blackberry充电的呢?通过查看libusb和Bcharge的代码和资料检索,我把我的资料、观点和疑问写在下面:
首先把问题域搞清楚:
Bcharge通过USB给Blackberry充电
-> Bcharge在Linux下通过USB给Blackberry充电
-> Bcharge在Linux下通过USB给Blackberry的电池充电
再根据现有的资料和时间、精力把问题细化:
* Blackberry 7230手机电池
* 电池充电的原理
* USB充电的原理
* Bcharge通过USB给Blackberry 7230手机电池充电
Blackberry 7230手机电池
我买的7230手机电池上没有规格说明,根据Blackberry官方网站的资料,7230带的是一块锂离电池(Lithium-ion, or Li-ion), 960 mAh, 3.7V。
Lithium-ion是锂电池发展而来的。以前照相机的扣式电池就属于锂电池。锂电池的正极材料是锂金属。负极材料是碳材。Lithium-ion的正极材料是钴酸锂,负极材料是碳材。电池通过正极的锂离子在负极碳材 的键入与迁出来实现电池的充放电过程。
Lithium-ion电池的优点是:
* They're generally much lighter than other types of rechargeable batteries of the same size. The electrodes of a lithium-ion battery are made of lightweight lithium and carbon. Lithium is also a highly reactive element, meaning that a lot of energy can be stored in its atomic bonds. This translates into a very high energy density for lithium-ion batteries.Here is a way to get a perspective on the energy density. A typical lithium-ion battery can store 150 watt-hours of electricity in 1 kilogram of battery. A NiMH (nickel-metal hydride) battery pack can store perhaps 100 watt-hours per kilogram, although 60 to 70 watt-hours might be more typical. A lead-acid battery can store only 25 watt-hours per kilogram. Using lead-acid technology, it takes 6 kilograms to store the same amount of energy that a 1 kilogram lithium-ion battery can handle. That's a huge difference [Source: Everything2.com].
* They hold their charge. A lithium-ion battery pack loses only about 5 percent of its charge per month, compared to a 20 percent loss per month for NiMH batteries.
* They have no memory effect, which means that you do not have to completely discharge them before recharging, as with some other battery chemistries.
* Lithium-ion batteries can handle hundreds of charge/discharge cycles.
Lithium-ion电池的缺点是:
* They start degrading as soon as they leave the factory. They will only last two or three years from the date of manufacture whether you use them or not.
* They are extremely sensitive to high temperatures. Heat causes lithium-ion battery packs to degrade much faster than they normally would.
* If you completely discharge a lithium-ion battery, it is ruined.
* A lithium-ion battery pack must have an on-board computer to manage the battery. This makes them even more expensive than they already are.
* There is a small chance that, if a lithium-ion battery pack fails, it will burst into flame.
电池充电的原理
充电时电池和外接电源不是同时供电的。即有外接直流电时,用外接直流供电;无外接直流时,用电池供电。 其设计原理是:有一个可以称之为电池保护电路在起作用,当然这 不会损害电池的了。电池保护电路由两部份组成:充电电路与电池切换电路组成。 在有外接直流电时,用外接直流供电,并可以对电池进行充电操作
充电电池其实里面是用的化学溶液产生的一种反映,将这种溶液装入容器里,通过 里面产生的电子的饱和状态可以检测出电池的电量剩余多少,所以说这种电池是一种智能电池,现在很多的数码产品都能显示电池的使用状况,来确定大概还能用多长时间。其原理就是:溶液产生的电子一直处于活动状态,当有用电器需要供电时,大量电子通过导线传输给用电器,这是电池的失电状态,就是通常所说的放电,而充电就是向电池里输送电子,因为电池能长时间提供供电说明它有储存电子电荷的能力,所以是可以充电的。电池里使用的化学溶液不同,所以产生电子电荷 数量不同,使用时间也不同。如果电池800ma, 充电器是150ma的,那么大约是 800/150=5个小时左右可以充满. MP3的充电器应该是有两个指示灯的,绿色的为正 在充电(此灯灭了表示电已充满),红色为电源有无状态.
其他回答:比如你的电池容量是600mAh的,那么1C就是600mA,1/10C就是60mA。以 1C充电,1小时左右应该充饱了.当然以1/10C充充满电需要10多个小时。结合 充电器的电流,和电池的容量就可一算出来。
USB充电的原理
USB接口的正常输出电压为5V,输出电流最大可以达到500mA(According to USB 2.0 Spec:1个单位负载为100mA (最大)。任何设备允许吸取的最大电流为5个单位 负载),这符合标准锂电池的充电要求。
注:低功率USB端口提供电压4.4V 至5.25V,电流100mA;高功率USB端口提供电压4.75V至5.25V,电流500mA.由于USB电缆和连接器上的电压降,USB设备必须能工作至4.35V;USB设备必须保证其最大工作电流低于l00mA,直到通过软件被配置为高功率为止. 当设备首次连接到USB端口时,有一个列举程序识别设备以确定它所需要的负载,此时设备只允许驱动一个单元负载,运行列举程序後,如果主机电源管理软件允许,高功耗设备才被允许用大电流驱动。这也就是BCharge要做的事情!
大多数手机都是使用3.6V的电池,一般这种电池要求充电电压上限在4.5V左右,如果直接用5V电压进行充电的话,很可能会损坏手机电池,一般的手机原配充电器常 用4.3V对手机电池进行充电。因此要用USB接口给手机充电,必须要降压。我想这个应该是手机的内部电路来处理的而不是通过用特殊的USB线。
标准的USB接口有四条线组成:
VBus 红色 电源线
Ground 黑色 电源线
D+ 绿色 数据线
D- 白色 数据线
两边较长的为数据线而中间触点较短的为电源线 (这样设计是为了每次在插入时先接通数据线再通电,而拨出时先切断电源才断掉 数据线,因此热插拨时就不容易出错和损坏),电压为+5V和0。当与电脑相连时有四条线工作,而充电时只有两条电源线工作。
手机上那个USB口叫Mini USB接口(see http://wiki.ccw.com.cn/index.php/USB)
这我有个问题:像我以前用的Moto V3,可以通过在手机上设置USB配置,使得手机插上USB后可以处于充电状态或者被当作存储设备,这里的细节我没有想得太明白,但是应该是设置不同的配置导致的。
Bcharge通过USB给Blackberry 7230手机电池充电
Bcharge通过libusb来访问USB那段的Blackberry设备。libusb用它官方网站上的话说: It's aim is to create a library for use by user level applications to access USB devices regardless of OS.
(关于Bcharge的代码我们以后细说...)
Speed up firefox
2008-01-09 05:57:47
网上主流的、加速firefox的方法基本是通过about:config修改其配置来实现的,如下:
- Speed up page rendering
By default, Firefox doesn't try to render a web page for 250 milliseconds while it's waiting for data. If you use about:config to add the Integer preference nglayout.initialpaint.delay, and set the value to 0, Firefox immediately starts to display the page, even without complete data. The drawback, especially on slower machines, is that the total time to display the page will be longer.
- Enable Pipelining
Pipelining is an experimental feature, designed to improve page-load performance, that is unfortunately not well supported by some web servers and proxies. To try it out, by using about:config to set the following preferences:
network.http.pipelining
Set this to true, to enable pipelining.
network.http.proxy.pipelining
Set this to true, to enable pipelining to the proxy server.
network.http.pipelining.maxrequests
Set this to 8, to have a maximum of 8 pipelining requests at once. Possible values are from 1 to 8.
For more information about pipelining, read the HTTP/1.1 Pipelining FAQ
- disable IPV6
- set network.dns.disableIPv6 as false
- set plugin.expose_full_path as true
- set content.notify.backoffcount as 5
- se ui.submenuDelay as 0
Is swap space obsolete?
2008-01-07 12:18:56
昨天在鼎好花了305元买了一根杂牌的、Hyundai芯片的、DDR400 1G内存条。我的机器得到了升华:主板只有两根DDR插槽,撤掉一根256M的DELL原装内存,换上这根1G的,内存达到了空前的1.2G。作为顺理成 章的好处,我应该可以关掉swap来充分利用我的RAM。但是在此之前,我习惯性的作了一个检索,以证明我的做法也是其他电脑人士的做法,结果是我看到这 样一篇文章:Is swap space obsolete?
它让我还是为Ubuntu 7.10保留了128M swap space....
There was a thread on the CLUG list recently about whether it was still useful to have swap space, now that it's quite affordable to have a gigabyte or more of memory on a desktop machine. I think it is.
Some people have the idea that touching swap space at all is a sign that the machine is very overloaded, and so you ought to avoid it at all costs, by adding enough memory that the machine never needs to swap. This may have been true on Unix ten years ago, and may still be true on some systems for all I know but it's not true for Linux.
The meaning of the term swap has changed over time. It used to mean that entire tasks were moved out to disk, and they'd stay there until it was necessary to run them again. You can do this on machines without paged MMUs, and perhaps it was simpler to implement. However, these days almost all machines have MMUs, and so we use paging instead, where particular chunks of the program (typically 4kB) can move in or out independently. This gets more use out of the memory you have, because many programs run quite happily with only part of their virtual memory in RAM. Linux doesn't implement old-style whole-program swapping at all, and there does not seem to be any reason to add it.
Swap这个术语在过去用来这样一种场景/技术:为节省内存,一个task被整个移到磁盘上,直到它需要被再次执行的时候再被调度回内存。对于没有MMU的机器来说,这是可行的而且实现也比较简单,但是实际情况是绝大部分机器都有MMU,所以我们的调度单位往往是page(一般是4k)而不是整个task。况且,Linux也没有实现前面提到的老式的、基于调度整个task的Swap,因为觉得没有必要。
I'll recapitulate the way VM works, and in particular the ways it is different on Linux from in your average computer science textbook. The basic idea is that we have a relatively small fast RAM, and a slower larger disk, and we want to get the best performance out of the combination. I will skip some details and special cases for simplicity.
下面简单说说VM(Virtual Memory)的工作机制
All memory pages on Linux can be grouped into four classes. Firstly, there are kernel pages which are fixed in memory and never swapped. (Some other systems have pageable kernels, but at the moment the Linux developers consider it too risky.) Then there is program text: the contents of /bin/sh or /lib/libdl-2.3.2.so. These are read-only in memory, and so are always exactly the same as the file on disk. There are file-backed pages, which might have changes in memory that haven't been written out yet. Finally there are memory pages that don't correspond to any file on disk: this includes the stack and heap variables of running tasks. When a program does a malloc(), it allocates memory of this type. Pages in this last category are called anonymous mappings, because they don't correspond to any file name.
在Linux上所有的memory page被划分成四类:
- kernel pages,他们不会被swap
- read-only pages
- file-backed pages,主要是与磁盘文件相关的
- anonymous pages,与磁盘file不相关的pages,主要用来保存正在运行的task的stack变量,heap变量
There is no separate disk cache in Linux, like there is on old-Unix or on DOS. Instead, we try to keep the most useful parts of the disk in memory as cached pages. Linux usually doesn't directly modify the disk: rather, changes are made to the files in memory and then they're flushed out.
与老式的Unix和Dos一样,Linux没有单独的disk cache,作为替代,Linux把那些有用的disk部分放在内存中作为cached pages.
You'll notice that the free-memory measure on Linux machines is normally pretty low, even when the machine has plenty of memory for the tasks it's running. This is normal and intentional: the kernel tries to keep memory filled up with cached pages so that if those files are accessed again it won't have to go to disk. The free pool indicates just a few spare pages that are ready for immediate allocation. One time when the free memory will be large is shortly after bootup when the kernel just hasn't read in very much of the disk yet. Another time you'll have a lot of free memory is shortly after a large program exited: it had a lot of data pages in RAM, but those pages were deleted and so there's no useful information in them anymore.
We talk of pages as being clean when the in-memory version is the same as the one on disk, and dirty when they've been changed since being read in. Data(Williamski: Data or dirty here? should be ‘dirty’ I guess) pages need to get written back to disk eventually, and the kernel generally does this in the background. You can force all dirty pages to be written out using the sync system call.
clean page指的是其在内存中的内容与磁盘内容一致;dirty page指的是不一致的情况。
The kernel can discard a clean page whenever it needs the memory for something else, because it knows it can always get the data back from disk. However, dirty pages need to be saved to disk before they can be reused. We call this eviction. So flushing pages in the background has two purposes: it helps protect data from sudden power cuts, and more importantly it means there are plenty of clean pages that can be reused when a process needs memory. So efficient is this flushing that at the moment my machine has only four dirty pages out of 256,000 (by grep nr_dirty /proc/vmstat).
As the kernel allocates memory, it firstly takes pages from the free pool. If that drops too low, it needs to free up more memory. Where does that come from? It needs to discard a clean page to make room. If there aren't any suitable clean pages then it needs to flush a dirty page to disk, then use it. This is very slow because the allocation can't continue until the disk write has finished, so the kernel tries very hard to avoid this by always having some clean pages around. (Remember the whole point of the VM algorithm is to avoid ever having to wait for a disk access to complete, by keeping pages in memory that are likely to be used again.)
File-backed pages can be flushed by writing them back to their file on disk. But anonymous mappings by definition don't have any backing file. Where can they be flushed to? Swap space, of course. Swap partitions or files on Linux hold pages that aren't backed by a file.
对于File-backed pages来说,它们的回写比较容易,因为它们在磁盘上有对应的文件,那anonymous pages呢?它们在磁盘上没有对应的文件,怎么办?导出主题:它们需要被回写到swap space上。
If you don't have swap space, then anonymous mappings can't be flushed. They have to stay in memory until they're deleted. The kernel can only obtain clean memory and free memory by flushing out file-backed pages: programs, libraries, and data files. Not having swap space constrains and unbalances the kernel's page allocation. However unlikely it is that the data pages will be used again — even if they're never used again — they still need to stay in memory sucking up precious RAM. That means the kernel has to do more work to write out file-backed pages, and to read them back in after they're discarded. The kernel needs to throw out relatively valuable file-backed pages, because it has nowhere to write relatively worthless anonymous pages.
所以作者认为如果没有swap space的话,anonymous pages没法回写到磁盘,这样也就没法让出它们占据的空间,这会给kernel在调度内存 (即VM的管理)上带来不小的开销(见上面的粗体部分)
Not only this, but flushing pages to swap is actually a bit easier and quicker than flushing them to disk: the code is much simpler, and there are no directory trees to update. The swap file/partition is just an array of pages. This is another reason to give the kernel the option of flushing to swap as well as to the filesystem.
况且回写anonymous pages到swap space的效率(从实现和速度方面)比回写到disk要高。
As I write this, my 1024MB machine has 184MB of swap used out of 1506MB, and only 17MB of memory free. On old-Unix this would indicate a perilous situation: with numbers like this it would be grinding. But Linux is perfectly happy with these numbers: the disk is idle and it responds well.
The 184MB constitutes tasks that are running in the background, like the getty on the text console, or the gdm login manager. Neither of them has done anything much since I logged in days ago. From a certain overoptimizing point of view I ought to get rid of those tasks — although for the login manager it might be hard. But even then, there's probably lots of memory used for features of programs I am running that don't get invoked very often.
With swap, that memory is written to disk and costs very little. Without swap, it would be cluttering up RAM, as if I was down to only 840MB. Everything else would need to page a bit harder, but it wouldn't be obvious why.
Disk is cheap, so allocate a gigabyte or two for swap.
On BSD people used to advise allocating as much swap as memory, or maybe two or three times as much. Although the VM design is completely different, it's still a good rule of thumb. If anything, disk has gotten relatively cheaper over time: a typical developer machine now has 1GB of memory, but 200GB of disk. Spending one half or one percent of your disk on swap can probably improve performance.
If you are short on disk, as I am on my laptop, then use a swap file instead of a swap partition so that you can shrink or grow it more easily. (I think there is still a limit of 2GB per swap target, but you can create as many as you like.) Swap files might be slightly slower, but it's much better than not having it at all. If you ever see it get close to full, add some more.
Understanding the Linux Virtual Memory Manager has an enormous amount of detail on how this works in 2.4 (and I hope it doesn't contradict me!)
Q: 那2.6会有什么变化呢?是不是这个观点还使用呢?
O'Reilly's System Performance Tuning approaches this from a sysadmin's point of view, but it mostly describes the way swap works under Solaris.
独立显卡,你在哪里?
2008-01-04 13:22:17
那个谁答应给我换一块独立显卡的,好兴奋。
先查看了一下Ubuntu都支持哪些显卡(https://wiki.ubuntu.com/HardwareSupportComponentsVideoCards)
再打开DELL的说明书一看,我的主板居然没有AGP插槽,只有三条PCI插槽,而且是Bus Speed为33 MHZ的老式PCI插槽,看了看网上大部分都是AGP,PCI-E接口的显卡,都没有这种插槽的显卡卖了,晕~~
PCI Express slots are much shorter than PCI slots and run at a higher speed: PCI is 32-bit and runs at 33MHz, whereas PCIe can run from 66MHz to 133MHz and is 64-bit. It is also a point-to-point connection, versus a shared bus.
PCIe can have multiple "lanes" which can be put to together to increase speed; these are known as x1, x2, x4, x8, x12, x16, and x32 links. Each lane can handle 2.5Gbps in each direction, while PCI is limited to 33MHz x 32bits = 1.066Gbps.
在淘宝上看到有GF2 Force MX 400一类的二手PCI显卡卖,很兴奋,但是又一看DELL的说明书,居然没法Disable集成显卡(BIOS里面的Primary Video Controller只有AUTO和ON两个选项,居然连DISABLE都没有),有点失望了....
只能期待今晚能通过实践找到办法了~
Ubuntu rocks but has its drawbacks
"Ubuntu rocks but has its drawbacks" -这段话源自lxpages.com blog 于April 24, 2007写的一篇文章,文中提到了如何根据自己的需要优化Ubuntu的性能(作者用的Ubuntu是Fiesty Fawn (7.04)),它整理了一些关于这个话题的资料,我迫不及待的要看看都有些什么高招:
注意:有提示意义的原文用50% Gray,提高性能的步骤用100% Red
Hacking Ubuntu to Improve Performance
前言:Ubuntu is designed for the average computer user. As a result, there are some running processes that may not be needed and some resources that are not used optimally. Using a variety of commands, you can see what is running, what resources are available, and what resources are being used. The system can be tuned by adjusting kernel parameters, shell parameters, and settings for specific applications.
1.1 Introduction
- Different versions of Ubuntu (and Linux) use different startup scripts and run different support processes. Knowing how one version of Linux works does not mean that you know how all versions work.
1.2 Viewing Running Processes
- ps –ef shows every (-e) running process in a full (-f) detailed list
- Unix的两大分支:BSD(FreeBSD, OpenBSD, SunOS, and Mac OS X) and System V(it follows the POSIX standards, HP-UX, AIX, Solaris, and IRIX). 不同分支在进程管理、设备驱动的命名和系统目录的位置等方面会有一些不同。Linux呢?Linux supports both BSD and POSIX.
- Note: Technically, PIDs are handles to processes and not actual processes. A multi-threaded process may have one handle for all threads, or one handle per thread. It all depends on how the process creates the threads.
- there are some processes that cannot be killed.
- Zombies:—When a process dies, it returns an error code to its parent (PPID). A dead PD whose return code has not yet been received by its parent becomes a zombie. Zombies take up no CPU, but do take up a PID. For programmers, calling the wait() function retrieves return codes and kills zombies. In contrast, sending a kill signal to a zombie does nothing since the process is already dead.
- I/O Bound—A process that is blocked on a kernel driver call may not process the kill signal until the kernel call returns. This is usually seen with network file system calls (NFS) when the network is down or on disk I/O when the drive is bad. For example, if you are using an NFS mounted directory and run ls, the command may hang if the network mount is bad. Sending a kill signal to the ls process will not immediately kill it. I've also experienced these hangs when using dd to copy a disk that was in the middle of a head-crash.
- Interception—Some kill signals can be intercepted by applications. For example, programs can intercept the default signal (kill, kill -15, or kill –TERM). This is usually done so the program can clean up before exiting. Unfortunately, some programs don't die immediately. Other kill signals, such as kill –KILL or kill -9, cannot be intercepted.
- Tip: (稳妥而且优雅的kill方式) If you really want to kill a process, first use kill PID (e.g., kill 1234). This sends a TERM signal and allows well-behaved processes to clean up resources. If that does not get the result you want, try kill -1 PID. This sends a hang-up signal, telling the process that the terminal died. This signal is usually only intercepted by well-behaved processes; other processes just die. If that does not kill it, then using kill -9 PID. This is a true kill signal and cannot be intercepted by the process.
- Signals are flags; they are not queued up. If you send a dozen TERM signals to a process before the process can handle them, then the process will only receive one TERM signal. Similarly, if a program spawns six children and all die at once, then the parent may only receive one CHLD signal. If the parent fails to check for other dead children, then the remaining children could become zombies.
- Stop processes—(如何kill掉那些能自动spawn的进程)Infinite spawning loops usually happen because one process detects the death of another process. Instead of killing the processes, use the stop signal: kill -STOP PID or killall -STOP Name. This will prevent further spawning and enable you to kill all the sleeping processes without them re-spawning
- Linux provides a virtual file system that is mounted in the /proc directory. This directory lists system resources and running processes.
- Measuring Disk I/O If the system seems to be running slowly, you can use iostat (sudo apt-get install sysstat) to check the performance.
1.5 Measuring Memory Usage Network Throughput
- The command swapon –s will list the available swap space and show the usage. There is usually a little swap space used, but if it is very full then you either need to allocate more swap space, install more RAM, or find out what is consuming the available RAM.
- In addition, the pmap command can show you memory allocations for specific process IDs.(这难道不是我前段时间到处找的、用来察看每个module的内存分布的命令么?)
- There is no simple way to determine video memory. If you have a PCI memory card, then the command lspci –v will show you all PCI cards (including your video card) and all memory associated with the card.
- If the computer seems sluggish when accessing the network, then you can check the network performance using netstat -i inet.
- Inspecting Boot Scripts: The directory /etc/init.d/ contains scripts for starting and stopping system services. These scripts are activated by links in the different rc directories (/etc/rc0.d, /etc/rc1.d, and so on). As init enters each run level, the appropriate S links are executed. For example, at run level 1, all S links in /etc/rc1.d/ are started. This includes S20single for single-user mode configuration. When the system changes levels, all K (for kill) scripts are executed before changing run levels. To find the current run level, you can either use who -r or the runlevel command.
- Inspecting Device Startups: Dynamic device configuration is managed by udev. The udev process watches and manages plug-and-play devices. Based on the configuration in /etc/udev/rules.d/, different applications may be launched.
- Inspecting Network Services: There are four directories of scripts for managing network interfaces:
- /etc/network/if-pre-up.d/—This contains steps that must be completed before (pre) the interface is brought up. For example, the scripts may need to load wireless drivers.
- /etc/network/if-up.d/—These scripts are used after bringing up the configured network interface. For example, this is where the system clock is set—every time any network is brought up, the computer's clock is set.
- /etc/network/if-down.d/—These scripts are used to remove any running configuration. For example, if you have the Postfix mail server running, then there is a script that tells Postfix to reload its configuration when an interface is taken down.
- /etc/network/if-post-down.d/—This directory contains any cleanup stages that are needed after (post) the interface is taken down. For example, unnecessary wireless drivers can be unloaded.
- Inspecting Shell Startup Scripts
Table 7-1: Shell Startup Scripts
Initialization Script Purpose
/etc/profile Used by every login shell, system-wide.
$HOME/.bash_profile Used on a per-user basis. Each user can have a personalized login script.
/etc/bash.bashrc Every interactive shell runs this system-wide configuration script.
$HOME/.bashrc Every interactive shell runs this user-specific configuration script.
/etc/bash.logout If you create it, this system-wide script is executed every time a user logs out.
$HOME/.bash_logout User-specific script that is used during logout.
- 根据不同需求来设置X-Windows的启动配置
Everyone running X-Windows?
* Use /etc/X11/Xsession or place the startup script under /etc/X11/Xsession.d/.
Just you running X-Windows? * Use $HOME/.xsession.
Everyone running Gnome? * Use /etc/X11/gdm/PostSession/Default. This will work for Gnome users, but not KDE or other desktops. KDE, XDM, and other desktops have their own configuration directories and files.
? Just you running Gnome? * Use $HOME/.gnomerc or the graphical session editor
- 关掉CD-ROM的Auto run一类的设置:System>Preferences>Removable Drives and Media.
- Inspecting Schedulers: at, cron, and anacron Programs that should run periodically are usually placed in a scheduler. The three common schedulers are at, cron, and anacron.
Scheduling with at The at command specifies that an application should run at a specific time. This is used for run-once commands.
Scheduling with cron While at is used for one-time applications, cron is used for repeated tasks
Scheduling with anacron While cron runs tasks repeatedly, it makes no distinction as to the system state. The anacron service is similar to cron, but allows tasks to be run based on a relative period rather than an absolute date.
- Many of the tunable performance items can be configured directly by the kernel. The command sysctl is used to view current kernel settings and adjust them. For example, to display all available parameters (in a sorted list), use: sudo sysctl -a | sort | more
- There are two ways to adjust the kernel parameters. First, you can do it on the command line. For example, sudo sysctl -w kernel.threads-max=16000. This change takes effect immediately but is not permanent; if you reboot, this change will be lost. The other way to make a kernel change is to add the parameter to the /etc/sysctl.conf file. Adding the line kernel.threads-max=16000 will make the change take effect on the next reboot. Usually when tuning, you first use sysctl –w. If you like the change, then you can add it to /etc/sysctl.conf. Using sysctl –w first allows you to test modifications. In the event that everything breaks, you can always reboot to recover before committing the changes to /etc/sysctl.conf.
- The biggest improvement you can make to any computer running Ubuntu is to add RAM.
- Use sysv-rc-conf (sudo apt-get install sysv-rc-conf) to change the enable/disable settings.
- 可以考虑disable下列服务:
- anacron—As mentioned earlier, this subsystem periodically runs processes. You may want to disable it and move any critical services to cron.
- atd and cron—By default, there are not at or cron jobs scheduled. If you do not need these services, then they can be disabled. Personally, I would always leave them enabled since they take relatively few resources.
- apmd—This service handles power management and is intended for older systems that do not support the ACPI interface. It only monitors the battery. If you have a newer laptop (or are not using a laptop), then you probably do not need this service enabled.
- acpid—The acpid service monitors battery levels and special laptop buttons such as screen brightness, volume control, and wireless on/off. Although intended for laptops, it can also support some desktop computers that use special keys on the keyboard (for example, a www button to start the browser). If you are not using a laptop and do not have special buttons on your keyboard, then you probably do not need this service.
- bluez-utiles—This provides support for BlueTooth devices. If you don't have any, then this can be disabled.
- dns-clean, ppp, and pppd-dns—These services are used for dynamic, dial-up connections. If you do not use dialup, then these can be disabled.
- hdparm—This system is used to tune disk drive performance. It is not essential and, unless configured, does not do anything. The configuration file is /etc/hdparm.conf and it is not enabled by default.
- hplip—This provides Linux support for the HP Linux Image and Printing system. If you do not need it, then it can be disabled. Without this, you can still print using the lpr and CUPS systems.
- mdadm, mdadm-raid, and lvm—file system support for RAID (mdadm and mdadm-raid) and Logical Volume groups (lvm). If you do not use either, then these can be disabled.
- nfs-common, nfs-kernel-server, and portmap—re used by NFS—present if you installed NFS support. If you do not need NFS all the time, then you can disable these and only start the services when you need them:
sudo /etc/init.d/portmap start
sudo /etc/init.d/nfs-common start
sudo /etc/init.d/nfs-kernel-server start
- pcmcia and pcmciautils—rovide support for PCMCIA devices on laptops. If you do not have any PCMCIA slots on your computer, then you do not need these services.
- powernowd and powernowd.early—ervices are used to control variable-speed CPUs. Newer computers and laptops should have these enabled, but older systems (for example, my dual-processor 200 MHz PC) do not need it.
- readahead and readahead-desktop—ervices are used to preload libraries so some applications will initially start faster. In a tradeoff for speed, these services slow down the initial boot time of the system and consume virtual memory with preloaded libraries. If you have limited RAM, then you should consider disabling these services.
- rsync— a replacement for the remote copy (rcp) command. Few people need this—sed to synchronize files between computers.
- vbesave—rvices monitors the Video BIOS real-time configuration. This is an ACPI function and is usually used on laptops when switching between the laptop display and an external display. If your computer does not support APCI or does not switch between displays, then you do not need this service.
Tip: There is a System>Admin>Services applet for enabling and disabling some services. However, this applet only knows of a few services; it does not list every available service. The sysv-rc-conf command recognizes far more services and offers more management options.
The sysv-rc-conf command shows most of the system services. However, it does not show all of them. If the service's name ends with .sh, contains .dpkg-, or is named rc or rcS, then it is treated as a non-modifiable system service. To change these services, you will need to manually modify the /etc/init.d/ and /etc/rc*.d/ directory contents.
原文:http://blog.lxpages.com/2007/04/24/ubuntu-performance-guides/
另外一篇文章的主要内容是:
- 重新编译内核并打一个Con Kolivas patches - these are patches designed to improve system responsiveness with specific emphasis on the desktop, but suitable to any workload.
- 配置一些内核参数
- Enable/Disable一些服务
基于我的硬件现状,这些设置没什么新意,倒是它列出的一些Ubuntu服务的说明值得一看:
To enable/disable services go to System -> Administration -> Services
1. acpi-support - leave it on.
2. acpid - The acpi daemon. These two are for power management, quite important for laptop and desktop computers, so leave them on.
3. alsa - If you use alsa sound subsystem, yes leave it on. But if you have the service below, its safe to be off. The default is off when alsa-utils is on.
4. alsa-utils - On my system, this service supercedes the alsa, so I turn off the alsa and turn this on at S level.
5. anacron - A cron subsystem that executes any cron jobs not being executed when the time is on. Most likely you’ve probably turned your computer off when a certain cron job time is ready. For example, updatedb is scheduled at 2am everyday, but at that moment, you computer is off, then if anacron service is on, it will try to catch up that updatedb cron.
6. apmd - If you computer is not that old which can’t even support acpi, then you may try to turn this off.
7. atd - like cron, a job scheduler. I turned it off.
8. binfmt-support - Kernel supports other format of binary files. I left it on.
9. bluez-utiles - I turned it off. I don’t have any bluetooth devices.
10. bootlogd - Leave it on.
11. cron - Leave it on.
12. cupsys - subsystem to manager your printer. I don’t have one so I turned it off, but if you do, just leave it on.
13. dbus - Message bus system. Very important, leave it on.
14. dns-clean - Mainly for cleaning up the dns info when using dial-up connection. I don’t use dial up, so I turn it off.
15. evms - Enterprise Volumn Management system. I turned it off.
16. fetchmail - A mail receving daemon. I turned it off.
17. gdm - The gnome desktop manager. I turned it off anyway since I get use to boot to console first. This is up to you if you want to boot directly to GUI.
18. gdomap - You can turn it off.
19. gpm - Mouse support for console. If you feel you’d better have a mouse on console, go turn it on.
20. halt - Don’t change it.
21. hdparm - tuning harddisk script, should be on.
22. hibernate - If your system support hibernate, leave it on. Otherwise, its useless for you.
23. hotkey-setup - This daemon setup some hotkey mappings for Laptop. Manufacturers supported are: HP, Acer, ASUS, Sony, Dell, and IBM. If you have a laptop in those brands, you can leave it on, otherwise, this might not have any benefits for you.
24. hotplug and hotplug-net - activating hotplug subsystems takes time. I’d consider to turn them off.
25. hplip - HP printing and Image subsystem. I turned it off.
26. ifrename - network interface rename script. Sounds pretty neat but I turned it off. Mainly for managing multiple network interfaces names. Since I have a wireless card and an ethernet card, they all assigned eth0 and ath0 from kernel, so its not really useful for me.
27. ifupdown and ifupdown-clean - Leave it on. They are network interfaces activation scripts for the boot time.
28. inetd or inetd.real - take a look your /etc/inetd.conf file and comment out any services that you don’t need.
29. klogd - Leave it on.
30. laptop-mode - A service to tweak the battery utilization when using laptops. You can leave it on.
31. linux-restricted-modules-common - You need to see if you really have any restricted modules loaded on your system. I’d leave it on.
32. lvm - I don’t use it so I turned it off. Leave it on if you *DO* have lvm.
33. makedev - Leave it on.
34. mdamd - Raid management tool. I don’t use it so I turned it off.
35. mdamd-raid - Raid tool. If you don’t have Raid devices, turn it off.
36. module-init-tools - Load extra modules from /etc/modules file. You can investigate your /etc/modules file and see if there is any modules that you don’t need. Normally, this is turned on.
37. mountvirtfs - mount virtual filesystems. Leave it on.
38. networking - bring up network interfaces and config dns info during boot time by scaning /etc/network/interfaces file. Leave it on.
39. ntpdate - Sync time with the ubuntu time server. Leave it on if you want.
40. nvidia-kernel - I compiled the nvidia driver by myself, so its useless for me now. If you use the ubuntu nvidia driver from the restrict modules, just leave it on. 41. pcmcia - pcmcia device - useless if you are using desktop which doesn’t have pcmcia card. So in that case, turn it off please.
42. portmap - daemon for managing services like nis, nfs, etc. If your laptop or desktop is a pure client, then turn it off.
43. powernowd - client to manage cpufreq. Mainly for laptops that support CPU speed stepping technology. Normally, you should leave it on if you are configuring a laptop, but for desktop, it might be useless.
44. ppp and ppp-dns - Useless to me. I don’t have dial-up.
45. readahead - It seems readahead is a kind of “preloader”. It loads at startup some libs on memory, so that some programs will start faster. But it increases startup time for about 3-4 seconds. So, you can keep it… or not. I tested and I just didn’t feel difference loading programs. So I decided to turn it off. If you have a reason to keep it on, please do so.
46. reboot - Don’t change it.
47. resolvconf - Automatically configuring DNS info according to your network status. I left it on.
48. rmnologin - Remove nologin if it finds it. It wouldn’t happen on my laptop, so I got rid of it.
49. rsync - rsync daemon. I don’t use it on my laptop, so turned it off.
50. sendsigs - send signals during reboot or shutdown. Leave it as it is.
51. single - Active single user mode. Leave it as it is.
52. ssh - ssh daemon. I need this so I turned it on.
53. stop-bootlogd - stop bootlogd from 2,3,4,5 runlevel. Leave it as it is.
54. sudo - check sudo stauts. I don’t see any good to run it everytime on a laptop or desktop client, so I turned it off.
55. sysklogd - Leave it as it is.
56. udev and udev-mab - Userspace dev filesystem. Good stuff, I left them on.
57. umountfs - Leave it as it is.
58. urandom - Random number generator. Might not useful but I left it on.
59. usplash - Well, if you really want to see the nice boot up screen, leave it as it is.
60. vbesave - video card BIOS configuration tool. Its able to save your video card status. I left it on.
61. xorg-common - setup X server ICE socket. Leave it as it is.
62. adjtimex - This is a kernel hw clock time adjusting too. Normally, you shouldn’t see this on your boot up list. In very rare case if you do see its on your boot up process, then there might be a reason why it is on, so better leave it that way. In my case, it is off.
63. dirmngr - A certification lists management tool. Work with gnupg. You will have to see if you need it or not. In my case, I turned it off.
64. hwtools - A tool to optimize irqs. Not sure what’s the benefits of turning it on. In my case, I turned it off.
65. libpam-devperm - A daemon to fix device files permissions after a system crash. Sounds pretty good, so I left it on.
66. lm-sensors - If you matherboard has builtin some sensor chips, it might be helpful to see hw status via userspace. I ran it and it said “No sensors found”, so I turned it off.
67. screen-cleanup - A script to cleanup the boot up screen. Well, turn on or off is up to you. In my case, I left it on.
68. xinetd - A inetd super daemon to manage other damons. In my system, the xinetd is managing chargen, daytime, echo and time (find them from /etc/xinetd.d dir), I care none of them, so I turned it off. If you do have some important services configured under xinetd, then leave it on.
How to install/uninstall package on Ubuntu?
2007-12-25 20:04:12
Install a package:
sudo apt-get install
Uninstall a package completely:
sudo apt-get --purge remove
那天我忽然想在Ubuntu上装一个和Windows下的画笔类似的程序用来简单编辑屏幕截图,试了一下自带的GIMP,太复杂了,要画笔那么简答的就好。怎么办呢?apt-get提供搜索功能:
apt-cache search -n paint
它会搜索出paint相关的、可供安装的程序:
gpaint - GNU Paint - a small, easy to use paint program for GNOME
tuxpaint - A paint program for young children
tuxpaint-data - Data files for Tux Paint, a paint program for children
tuxpaint-stamps-default - Stamp files for Tux Paint, a paint program for children
cinepaint - motion picture image painting and retouching tool
cinepaint-data - data files for CinePaint
kolourpaint - a simple paint program for KDE
libcinepaint-dev - development library files for CinePaint
libcinepaint0 - runtime library files for CinePaint
paintlib-dev - C++ class library for image manipulation
paintlib2c2a - C++ class library for image manipulation
tkpaint - Versatile bitmap/pixmap editing tool
tuxpaint-config - Configuration tool for Tux Paint
xpaint - simple paint program for X
最后我选择了kolourpaint,很简单实用!
彻底抛弃Windows
2007-12-25 15:14:55
我的电脑主要用来:
- 编程
- 看电子书
- 在数码相机和MP3之间传输文件
- 下载电子书、足球视频、歌曲等
- 论坛灌水
- 收发电子邮件
前几天给我的DELL n1100安装了Ubuntu 7.10 English Version,发现原来Windows能做的它都能做,甚至做的更好。终于不用被Windows下面的病毒、木马、飘来飘去的垃圾网页、无休止的升级、 让人抓狂的性能和不人性化的设计所烦恼了。
Ubuntu的安装非常简单:到www.ubuntu.org下载一个ISO,刻盘,安装;装完之后也不存在什么找不到驱动之类的问题;虽然我装的是 English Version但是它默认支持中文,包括显示和输入中文都没问题(Please refer to SCIM)。
我的DELL n1100相关配置如下:
19' LCD
Intel Celeron: 533 MHz
1.2G DDR SDRAM
80G HD
Integrated Intel Extreme Graphics 2(Intel 865GV chip set)
AC97, Sound Blaster Emulation
DVD/CD-RW
512k ADSL + D-Link wireless router
Ubuntu自带的软件很丰富,可以满足我的所有需求:
- 编程
GNU software
- 看电子书
很多很小巧强大的GNU PDF软件,可以实现PDF文件的编辑、浏览,再也不用到处找Acrobat这个巨大的软件来编辑PDF了;
StarDict,很不错的翻译软件,和金山词霸差不多,但是提供很多有名而且专业的词典,这点我很喜欢
- 在数码相机和MP3之间传输文件
默认就支持我的SONY和Kodak数码相机,插上去就显示照片导出向导框;U盘等移动存储设备也都支持,和Windows一样。
- 下载电子书、足球视频、歌曲等
Ktorrent和aMule,对应Windows下的BitTorrent和eMule,都是GUI程序;
Ubuntu下面的播放器很多,解码器之类的也很丰富;
还自带一个不错的刻光盘软件
- 论坛灌水
Firefox,我最喜欢的浏览器
- 收发电子邮件
Thunderbird Mail,可以按线索查看邮件,这点我很喜欢。
美中不足,默认安装完以后的中文字体比较难看,我到网上下载了几个字体,现在看起来好多了。
