当前位置:  操作系统/服务器>linux
本页文章导读:
    ▪newlisp获取cpu信息的方法分享      本节内容: newlisp获取cpu信息 之前我们介绍过 Linux CPU 负载度量公式,今天使用newlisp写了一个获取本机cpu信息的小程序,每次都会调用REST API将数据发送给linux系统下的web server. 例子:   代.........
    ▪ps命令常用参数详解      本节内容: ps命令常用参数 一直都用ps命令,但是很少去琢磨其中参数的含义,今天分享一些ps命令的常用参数,供大家参考。 我的常用命令:   代码示例: ps -def  -d Select all processes except s.........
    ▪linux下命令行弹出光驱      本节内容: linux系统中命令行弹出光驱 例如:使用eject命令弹出光驱   代码示例: eject cdrom  查看光驱就用检查pci的命令:   代码示例: dean@xxx:~$ lspci  00:00.0 Host bridge: Advanced Micro Devices, In.........

[1]newlisp获取cpu信息的方法分享
    来源: 互联网  发布时间: 2013-12-24

本节内容:
newlisp获取cpu信息

之前我们介绍过 Linux CPU 负载度量公式,今天使用newlisp写了一个获取本机cpu信息的小程序,每次都会调用REST API将数据发送给linux系统下的web server.

例子:
 

代码示例:
#!/usr/bin/newlisp 
 
(load "config.lsp") 
 
(define (add-log msg) 
  (append-file "cpu.log" (append "\n" (string (now 480)) " ")) 
  (append-file "cpu.log" (append  ": " msg)) 
  ) 
 
;; return a list 
;; which contains total_jiffies and work_jiffies 
(define (check-cpu) 
  (set 'in-file (open "/proc/stat" "read")) 
  (set 'line (read-line in-file)) 
  (set 'r (parse line)) 
  (close in-file) 
  (set 'total_jiffies 0) 
  (println r) 
  (set 'i 1) 
  (do-while (< i 8) 
        (set 'total_jiffies (+ total_jiffies (int (nth i r)))) 
        (inc i) 
        ) 
  (set 'work_jiffies 0) 
  (set 'i 1) 
  (do-while (< i 3) 
        (set 'work_jiffies (+ work_jiffies (int (nth i r)))) 
        (inc i) 
        ) 
  (list total_jiffies work_jiffies) 
  ) 
 
(set 'r2 (check-cpu)) 
(set 'r3 (post-url "http://localhost/wind_tunnel/api/post/cpu" 
      (format "ip=%s&hostName=%s&epoch=%lld&totalJiffies=%lld&workJiffies=%lld" ip host_name 123456789 (nth 0 r2) (nth 1 r2)))) 
(add-log r3) 
 
(exit) 

config.lsp文件,两行配置:
 

代码示例:
(set 'host_name "beijinghome") 
(set 'ip "192.168.1.101") 

    
[2]ps命令常用参数详解
    来源: 互联网  发布时间: 2013-12-24

本节内容:
ps命令常用参数

一直都用ps命令,但是很少去琢磨其中参数的含义,今天分享一些ps命令的常用参数,供大家参考。

我的常用命令:
 

代码示例:
ps -def 
-d Select all processes except session leaders.

什么是session leader。
参考该解释:http://www.win.tue.nl/~aeb/linux/lk/lk-10.html#ss10.3
 

Every process group is in a unique session. (When the process is created, it becomes a member of the session of its parent.) By convention, the session ID of a session equals the process ID of the first member of the session, called the session leader. A process finds the ID of its session using the system call getsid(). 
 
Every session may have a controlling tty, that then also is called the controlling tty of each of its member processes. A file descriptor for the controlling tty is obtained by opening /dev/tty. (And when that fails, there was no controlling tty.) Given a file descriptor for the controlling tty, one may obtain the SID using tcgetsid(fd). 
 
A session is often set up by a login process. The terminal on which one is logged in then becomes the controlling tty of the session. All processes that are descendants of the login process will in general be members of the session. 

进程是按照进程组管理的,进程组又属于session。

关系如下:
每个session拥有一个或者多个进程组,每个进程组拥有一个或多个进程。
第一个属于某个session的进程id就是这个session的 leader, session id就用它的进程id。
和进程相关的id有几种,进程id, 父进程id, 进程组id 和 session id.
参考:http://unix.stackexchange.com/questions/18166/what-are-session-leaders-in-ps

-e 参数等同于 -A,
[plain] view plaincopyprint?
-e     Select all processes.  Identical to -A. 

-f 参数 显示完整格式
[plain] view plaincopyprint?
-f     Do full-format listing. This option can be combined with many other UNIX-style options to add additional columns.  It also causes the command arguments to be 
              printed.  When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added.  See the c option, the format keyword args, and the 
              format keyword comm. 

不过还有个常用的方式:
ps axu
不同于ps -def 用标准风格,这是BSD风格(不用-作为引导参数), BSD风格会在另一篇博客中介绍。
-a 参数
-a     Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal. 
-x 参数 和tty有关,tty会在另一篇文章中解释
x      Lift the BSD-style "must have a tty" restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when 
              the ps personality setting is BSD-like.  The set of processes selected in this manner is in addition to the set of processes selected by other means.  An 
              alternate description is that this option causes ps to list all processes owned by you (same EUID as ps), or to list all processes when used together with the 
              a option. 
-u 参数
-u userlist 
              Select by effective user ID (EUID) or name.  This selects the processes whose effective user name or ID is in userlist. 
 
              The effective user ID describes the user whose file access permissions are used by the process (see geteuid(2)).  Identical to U and --user. 

还有一种,通过直接输入命令查找,用-C参数,比如:
 

代码示例:
$ UNIX95= ps -C nginx 
  PID TTY          TIME CMD 
 1258 ?        00:00:00 nginx 
 1259 ?        00:00:00 nginx 
CHN\shu6889@sloop2:~$ ps aux | grep nginx 
root      1258  0.0  0.0  31188  1028 ?        Ss   09:24   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf 
root      1259  0.0  0.0  47312  2708 ?        S    09:24   0:00 nginx: worker process                    
70780027  4336  0.0  0.0  13652   976 pts/1    S+   10:40   0:00 grep --color=auto nginx 

注意,前面需要输入UNIX95=。

相关阅读:linux命令实例教程,大家可以深入学习下常用的linux命令。


    
[3]linux下命令行弹出光驱
    来源: 互联网  发布时间: 2013-12-24

本节内容:
linux系统中命令行弹出光驱

例如:使用eject命令弹出光驱
 

代码示例:
eject cdrom 

查看光驱就用检查pci的命令:
 

代码示例:
dean@xxx:~$ lspci 
00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD/ATI] RD780 Host Bridge 
00:02.0 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] RX780/RD790 PCI to PCI bridge (external gfx0 port A) 
00:04.0 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] RD790 PCI to PCI bridge (PCI express gpp port A) 
00:0a.0 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] RD790 PCI to PCI bridge (PCI express gpp port F) 
00:11.0 SATA controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 SATA Controller [IDE mode] 
00:12.0 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI0 Controller 
00:12.1 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0 USB OHCI1 Controller 
00:12.2 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB EHCI Controller 
00:13.0 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI0 Controller 
00:13.1 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0 USB OHCI1 Controller 
00:13.2 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB EHCI Controller 
00:14.0 SMBus: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 SMBus Controller (rev 3c) 
00:14.1 IDE interface: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 IDE Controller 
00:14.2 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 Azalia (Intel HDA) 
00:14.3 ISA bridge: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 LPC host controller 
00:14.4 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 PCI to PCI Bridge 
00:14.5 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI2 Controller 
00:18.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor HyperTransport Configuration 
00:18.1 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor Address Map 
00:18.2 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor DRAM Controller 
00:18.3 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor Miscellaneous Control 
00:18.4 Host bridge: Advanced Micro Devices, Inc. [AMD] Family 10h Processor Link Control 
01:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Juniper XT [Radeon HD 5770] 
01:00.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Juniper HDMI Audio [Radeon HD 5700 Series] 
02:00.0 SATA controller: JMicron Technology Corp. JMB363 SATA/IDE Controller (rev 02) 
02:00.1 IDE interface: JMicron Technology Corp. JMB363 SATA/IDE Controller (rev 02) 
03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 02) 
04:0e.0 FireWire (IEEE 1394): Texas Instruments TSB43AB23 IEEE-1394a-2000 Controller (PHY/Link) 

以上输出中的那个IDE接口,就是光驱。

命令行运行是ok,不过报错,无法弹出光驱。
原来是机械故障,:). 用针捅那个眼,有个东西被顶开,然后就搞定了,光驱哇地就弹出了,呵呵。


    
最新技术文章:
▪linux系统中的列出敏感用户的脚本代码
▪a10 config backup for aXAPI
▪一键备份gitolite服务器的Shell脚本
▪nagios 分发文件实现代码
▪阿里云云服务器Linux系统更新yum源Shell脚本
▪一个监控LINUX目录和文件变化的Shell脚本分享
▪Linux下实现SSH免密码登录和实现秘钥的管理、...
▪Shell正则表达式之grep、sed、awk实操笔记
▪3个备份系统文件并邮件发送的Shell脚本分享
▪CentOS 6.3下给PHP添加mssql扩展模块教程
▪监控网站是否可以正常打开的Shell脚本分享
▪shell脚本编程之if语句学习笔记
▪shell脚本编程之循环语句学习笔记
▪shell脚本编程之case语句学习笔记
▪Shell脚本实现的阳历转农历代码分享
▪shell脚本编程之case语句学习笔记 iis7站长之家
▪Shell脚本实现批量下载网络图片代码分享
▪Shell脚本实现检测文件是否被修改过代码分享
▪Shell脚本数组用法小结
▪Shell脚本批量重命名文件后缀的3种实现
▪C语言实现的ls命令源码分享
▪Linux下查找后门程序 CentOS 查后门程序的shell脚...
▪Shell 函数参数
▪linux shell 自定义函数方法(定义、返回值、变...
▪Shell实现判断进程是否存在并重新启动脚本分...
▪Shell脚本break和continue命令简明教程
▪Shell脚本函数定义和函数参数
▪让代码整洁、过程清晰的BASH Shell编程技巧
▪shell常用重定向实例讲解
▪awk中RS、ORS、FS、OFS的区别和联系小结
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3