Linux中的延时函数及获取系统时间函数
应用层:
#include <unistd.h>
1、unsigned int sleep(unsigned int seconds); 秒级
2、int usleep(useconds_t usec); 微秒级:1/10^-6
#define _POSIX_C_SOURCE 199309
#include <a(const struct timespec *req, struct timespec *rem);
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
// The value of the nanoseconds field must be in the range 0 to 999999999.
内核层:
include <linux/delay.h>
1、void ndelay(unsigned long nsecs); 纳秒级:1/10^-10
2、void udelay(unsigned long usecs); 微秒级: 1/10^-6
3、void mdelay(unsigned long msecs); 毫秒级:1/10^-3
linux下获取时间的若干函数(z)
asctime(将时间和日期以字符串格式表示)
相关函数
time,ctime,gmtime,localtime
表头文件
#include<time.h>
定义函数
char * asctime(const struct tm * timeptr);
函数说明
asctime()将参数timeptr所指的tm结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果以字符串形态返回。此函数已经由时区转换成当地时间,字符串格式为:“Wed Jun 30 21:49:08 1993\n”
返回值
若再调用相关的时间日期函数,此字符串可能会被破坏。此函数与ctime不同处在于传入的参数是不同的结构。
附加说明
返回一字
相关文档:
存储管理
MMU与内核内存管理的关系
从线性地址到物理地址的映射,通过页目录表和页表来实现的。
内核为存储管理维护了一套复杂的数据结构,页目录表和页表是主要的结构之一。这些表也是存储在物理内存页面中的,因此,也是以4K为单位。
表中的每个表项都记录了一个32位的地址,为4个字节,因此,一个表中最多可以有1K项 ......
说是exec系统调用,实际上在Linux中,并不存在一个exec()的函数形式,exec指的是一组函数,一共有6个,分别是:
#include <unistd.h>
int execl(const char *path, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);
int execle(const char *path, const c ......
参考资料 : linux内核设计和实现 P13
likely()和unlikely()是内核编译时用于优化 if 判断语句的宏
likely()代表优化
unlikely()代表不优化
一般为了效率 由程序员自己判断if语句里面的内容是否要优化,显然如果if语句里面的内容有很大的概率会执行到就该优化,不然就不必优化
if(likely(A != 0))
{
.. ......
1.可执行程序
os.system('pgrep %s > %s' % (process, output))
pidfile = open("output", 'r')
totalpid = len(pidfile.readlines())
pidfile.close()
if totalpid == 0 :
&nbs ......
linux下有专门的文件系统用来对设备进行管理,devfs和sysfs就是其中两种。
1,devfs:devfs是在2.4内核就出现了,它是用来解决linux中设备管理混乱的问题,linux内核开发人员开发了devfs。
2,sysfs:是Linux 内核中设计较新的一种虚拟的基于内存的文件系统,它的作用与proc 有些类似,但 ......