headermask image

header image

category archive listing Category Archives: Linux

Linux raw device

使用
raw -qa
命令来查询当前已经存在的绑定。
Use  the /etc/sysconfig/rawdevices file to define the set of raw device mappings automatically created during the system startup sequence.
在/etc/sysconfig/rawdevices中,注意裸设备对应的块设备如果是SATA或者iSCSI,则应该使用/dev/disk/by-id中的链接来进行指定。
如何确定裸设备对应的块设备?以裸设备/dev/raw/raw57为例:
# ls -l /dev/raw/raw57
crw-rw—-  1 root disk 162, 57 Jul 31 02:02 /dev/raw/raw57
# raw -qa | grep raw57
/dev/raw/raw57: bound to major 65, minor 233
# ls -l /dev | grep 65 | grep 233
brwxrwxrwx  1 root    disk    [...]

Rediscover Linux top command

以往我使用top命令都是不带任何开关的,直接一个top之后就任其不停地刷屏。可是最近才发现原来这个命令不简单,有不少的开关可以用,而且默认启动的时候还是一个交互式(interactive)程序,彻底服了-_-b
这里搜集了几个最近用到的开关:
-b
批处理模式,批处理模式在需要将top命令的输出发送到其他程序或者是文件时非常有用
-c
显示命令行(command line)而不只是程序名称(program name)
-d delay
屏幕刷新时间延迟
-n iterations
指定命令在退出前产生的输出的最大递归次数
-p PID [, PID...]
仅监控指定PID所对应的进程
最后是一个综合使用以上所有开关的top命令示例:
$ top -bc -d 5 -n 2 -p 8648,8752,8715
top – 22:48:27 up 16 days, 22:20,  4 users,  load average: 2.40, 2.18, 2.07
Tasks:   3 total,   0 running,   3 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.6% us,  2.1% sy,  0.0% ni, 69.9% id, 25.4% wa,  0.0% hi,  0.0% si
Mem:   6227868k total,  [...]

Linux system calls

最近学习了在Linux平台上使用strace来观察程序所调用的系统调用,它给出的输出中涉及到了很多Linux平台的系统调用,这里我搜集了一些常见的,以备参考:
int access (const char *pathname, int mode);
检查当前用户对于文件所拥有的权限(R_OK, W_OK, X_OK),或是检查文件是否存在(F_OK)
int fcntl (int fd, int cmd, long arg);
操作文件描述符fd对应的文件
int fstat (int fd, struct stat *buf);
返回文件描述符fd对应的文件的状态
long getcwd (char *buf, unsigned long size);
获取当前工作目录的绝对路径
int getrlimit (int resource, struct rlimit *rlim);
获取资源限制
off_t lseek (int fd, off_t offset, int whence);
重定位读写文件时的偏移量(offset)
ssize_t read (int fd, void *buf, size_t count);
从文件描述符fd对应的文件读
int statfs (const char *path, struct statfs *buf);
获取文件系统统计数据
int [...]