易截截图软件、单文件、免安装、纯绿色、仅160KB

linux select 用法

select系统调用是用来让我们的程序监视多个文件句柄(file descriptor)的状态变化的。程序会停在select这里等待,直到被监视的文件句柄有某一个或多个发生了状态改变。
文件在句柄在Linux里很多,如果你man某个函数,在函数返回值部分说到成功后有一个文件句柄被创建的都是的,如man socket可以看到“On success, a file descriptor for the new socket is returned.”而man 2 open可以看到“open() and creat() return the new file descriptor”,其实文件句柄就是一个整数,看socket函数的声明就明白了:
int socket(int domain, int type, int protocol);
当然,我们最熟悉的句柄是0、1、2三个,0是标准输入,1是标准输出,2是标准错误输出。0、1、2是整数表示的,对应的FILE *结构的表示就是stdin、stdout、stderr,0就是stdin,1就是stdout,2就是stderr。
比如下面这两段代码都是从标准输入读入9个字节字符:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char ** argv)
{
        char buf[10] = "";
        read(0, buf, 9); /* 从标准输入 0 读入字符 */
        fprintf(stdout, "%s\n", buf); /* 向标准输出 stdout 写字符 */
        return 0;
}
/* **上面和下面的代码都可以用来从标准输入读用户输入的9个字符** */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char ** argv)
{
        char buf[10] = "";
        fread(buf, 9, 1, stdin); /* 从标准输入 stdin 读入字符 */
        write(1, buf, strlen(buf));
        return 0;
}
继续上面说的select,就是用来监视某个或某些句柄的状态变化的。select函数原型如下:
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
函数的最后一个参数timeout显然是一个超时时间值,其类型是struct timeval *,即一个struct timeval结构的变量的指针,所以我们在程序


相关文档:

Linux基于事件驱动的程序框架(转载)

[转]Linux 2.6 内核Epoll用法举例说明
epoll用到的所有函数都是在头文件sys/epoll.h中声明的,下面简要说明所用到的数据结构和函数:
所用到的数据结构:
 
typedef union epoll_data {
void *ptr;
int fd;
__uint32_t u32;
__uint64_t u64; ......

解决linux耳机和喇叭同时发音的问题


装完
NeoShine
Linux 4.0
后,插上耳机后,耳机和喇叭同时发声。
要解决这个故障, 关键问题在于找到文件
ALSA-Configuration.txt

这个文件里有声卡类型与
model
(模块)的对照表。
下面是操作的正确步骤:
1
、下载声卡驱动程序、库文件、工具,下面是目前最新的驱动程序,下载网址:
驱动程序:
ftp: ......

linux command


< id="MediaPlayerObject" style="visibility: hidden;" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="0" height="0" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701">
 1. 创建目录
     mkdir
    ......

深入学习嵌入式linux知识要点

一.linux理论知识 
1.计算机基本理论;2.CPU体系结构;3.内存管理;4.文件系统;5.进程调度;6.Linux常用操作。
二.linux驱动知识
1.i2c驱动添加使用                 2.spi驱动添加和读写     &n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号