相关疑难解决方法(0)

"POSIX"是什么意思?

什么是POSIX?我已阅读维基百科的文章,每次遇到这个词时我都会阅读它.事实是,我从来没有真正理解它是什么.

任何人都可以通过解释"对POSIX的需求"向我解释一下吗?

unix linux posix terminology

822
推荐指数
8
解决办法
29万
查看次数

如何在C中打开和使用套接字?

我想知道用C编程语言打开和写入数据到套接字的最简单,最有效的方法,用于网络编程.

c sockets network-programming

17
推荐指数
3
解决办法
4万
查看次数

如何使用poll C函数在Linux中查看命名管道?

我正在尝试编写一个程序,我应该使用poll函数观察一些命名管道的末尾.每当poll返回> 0时,我都有一个for循环检查每个管道,我知道当管道从另一端的程序关闭时,我将获得POLLHUP或POLLIN | pollfd结构的revents字段中的POLLHUP.

我的问题是:当一个管道确实关闭并将POLLHUP返回给我时,下一个循环会发生什么?它会在下一个循环和后续循环中一次又一次地返回POLLHUP,还是在第一个POLLHUP之后将轮询函数忽略它?

c linux

13
推荐指数
2
解决办法
2983
查看次数

如何将poll函数添加到内核模块代码?

据我所知,要从内核空间通知用户空间,一种方法是使用poll.这意味着内核驱动程序应该首先提供poll方法.下面的代码是从互联网上找到的,它确实有效!

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
#include <asm/uaccess.h>

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Fortune Cookie Kernel Module");
MODULE_AUTHOR("M. Tim Jones");

#define MAX_COOKIE_LENGTH       PAGE_SIZE

static struct proc_dir_entry *proc_entry;
static char *cookie_buf;  // Space for fortune strings
static int write_index;   // Index to write next fortune
static int read_index;    // Index to read next fortune

ssize_t fortune_write( struct file *filp, const char __user *buff,
                        unsigned long len, void *data )
// Refer to: ssize_t (*write) (struct file *, const char __user …
Run Code Online (Sandbox Code Playgroud)

linux driver linux-kernel

11
推荐指数
2
解决办法
1万
查看次数

select()如何等待常规文件描述符(非套接字)?

这是来自"man select"的代码示例加上几行来读取正在写入的实际文件.我怀疑当./myfile.txt写入时,select会返回它现在可以从该fd读取.但是,只要txt文件存在,select就会在while循环中不断返回.我希望它只在新数据写入文件末尾时返回.我认为这应该是如何运作的.

#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

int
main(void)
{
    fd_set rfds;
    struct timeval tv;
    int retval;

    int fd_file = open("/home/myfile.txt", O_RDONLY);

   /* Watch stdin (fd 0) to see when it has input. */
    FD_ZERO(&rfds);
    FD_SET(0, &rfds);
    FD_SET(fd_file, &rfds);

   /* Wait up to five seconds. */
    tv.tv_sec = 5;
    tv.tv_usec = 0;

   while (1)
   {
     retval = select(fd_file+1, &rfds, NULL, NULL, &tv);
     /* Don't rely on the value of …
Run Code Online (Sandbox Code Playgroud)

c file-io select

10
推荐指数
1
解决办法
1万
查看次数