Thursday, August 30, 2012

The ps Command

This post is from here.



The ps (i.e., process statuscommand is used to provide information about the currently running processes, including their process identification numbers (PIDs).
A process, also referred to as a task, is an executing (i.e., running) instance of a program. Every process is assigned a unique PID by the system.
The basic syntax of ps is
ps [options]
When ps is used without any options, it sends to standard output, which is the display monitor by default, four items of information for at least two processes currently on the system: the shell and ps. A shell is a program that provides the traditional, text-only user interface in Unix-like operating systems for issuing commands and interacting with the system, and it is bash by default on Linux. ps itself is a process and it dies (i.e., is terminated) as soon as its output is displayed.
The four items are labeled PID, TTY, TIME and CMD. TIME is the amount of CPU (central processing unit) time in minutes and seconds that the process has been running. CMD is the name of the command that launched the process.
TTY (which now stands for terminal type but originally stood for teletype) is the name of the console or terminal (i.e., combination of monitor and keyboard) that the user logged into, which can also be found by using the tty command. This information is generally only useful on a multi-user network.
A common and convenient way of using ps to obtain much more complete information about the processes currently on the system is to use the following:
ps -aux | less
The -a option tells ps to list the processes of all users on the system rather than just those of the current user, with the exception of group leaders and processes not associated with a terminal. A group leader is the first member of a group of related processes.
The -u option tells ps to provide detailed information about each process. The -x option adds to the list processes that have no controlling terminal, such as daemons, which are programs that are launched during booting (i.e., computer startup) and run unobtrusively in the background until they are activated by a particular event or condition.
As the list of processes can be quite long and occupy more than a single screen, the output of ps -aux can be piped (i.e., transferred) to the less command, which lets it be viewed one screenful at a time. The output can be advanced one screen forward by pressing the SPACE bar and one screen backward by pressing the b key.
Among the information that ps -aux provides about each process is the user of the process, the PID, the percentage of CPU used by the process, the percentage of memory used by the process, VSZ (virtual size in kilobytes), RSS (real memory size or resident set size in 1024 byte units), STAT (the process state code), the starting time of the process, the length of time the process has been active and the command that initiated the process. The process state codes include D, uninterruptable sleep; N, low priority; R, runnable (on run queue); S, sleeping; T, traced or stopped; Z, defunct (zombie).
In contrast to most commands, the hyphen preceding ps's options is optional, not mandatory. Thus, the following could be (and sometimes is) used in place of the above command:
ps aux | less
An alternative set of options for viewing all the processes running on a system is
ps -ef | less
The -e option generates a list of information about every process currently running. The -f option generates a listing that contains fewer items of information for each process than the -l option.
Among the columns displayed by ps -ef, UID contains the username of the account that owns the process (which is usually the same user that started the process) and STIME displays the time the process started, or the starting date if it started more than 24 hours ago.
The processes shown by ps can be limited to those belonging to any given user by piping the output through grep, a filter that is used for searching text. For example, processes belonging to a user with a username adam can be displayed with the following:
ps -ef | grep adam
The -l option generates a long listing, and when used together with the -e and -f options creates a table with 15 columns:
ps -efl
The additional columns of most interest are NI and SZ. The former shows the nice value of the process, which determines the priority of the process. The higher the value, the lower the priority. The default nice value is 0 on Linux systems.
The latter displays the size of the process in memory. The value of the field is the number of pages the process is occupying. On Linux systems a page is 4,096 bytes.
ps is most often used to obtain the PID of a malfunctioning process in order to terminate it with the kill command. For example, if the PID of a frozen or crashed program is found to be 1125, the following can usually terminate the process:
kill 1125
ps -ef or ps -efl can then be used to confirm that the process really has stopped. If it has not, then the more forceful -9 option should be used, i.e.,
kill -9 1125
The pstree command is similar to ps in that it can be used to show all of the processes on the system along with their PIDs. However, it differs in that it presents its output in a tree diagram that shows how processes are related to each other and in that it provides less detailed information about each process than does ps.
Read more ...

Monday, August 13, 2012

Friday, August 10, 2012

Mac OS X 下修改机器名和主机名

This post is from here.


修改主机名和计算机名
sudo scutil --set HostName NewName
sudo scutil --set ComputerName NewName

修改终端提示符
vi ~/.profile
添加
export PS1="[\u@\h \W]\$ "
Read more ...

Wednesday, August 1, 2012

Ubuntu下WebQQ桌面化

This post is from here.


sudo add-apt-repository ppa:loneowais/fogger
sudo apt-get update
sudo apt-get install  fogger

然后可以搜索 fogger 打开程序,添加WEBQQ即可。

但是中文提示可能是乱码。
可以参考这里修改:


修改方式如下:

打开终端执行: sudo vim /opt/extras.Ubuntu.com/fogger/fogger/AppWindow.py  (vim不熟悉可以使用gedit,前面带行号)

22 import re         #22行加上该句

252 def unescape(self,url):
253     def repl(mobj):
254          try:
255              return unichr(int(mobj.group(0)[2:],16))
256          except:
257              return mobj.group(0)
258      return re.sub(‘%u[0-9a-fA-F]{4}’,repl,url)
259
260 def on_resource_request_starting(self, widget, frame, resource, request, response, data=None):
261      uri = urllib.unquote(request.props.uri)
262      uri = self.unescape(uri)
263      if uri.startswith(‘http://fogger.local/’):
264          request.props.uri = ‘about:blank’

因为是python代码,请严格按照四个空格键进行缩进,如果使用(tab)键有可能为制表符,这样严重影响代码运行。

修改好的脚本下载:

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2012年资料/7月/31日/Ubuntu下WebQQ桌面化替代方案完美版/

如果修改麻烦,可以下载后执行sudo cp  -f AppWindow.py  /opt/extras.Ubuntu.com/fogger/fogger/AppWindow.py 即可。
Read more ...