标签: fifo

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

从Python程序写入FIFO

我试图从python程序控制mplayer的数量.mplayer程序从bash脚本开始:

#!/bin/bash
mkfifo /home/administrator/files/mplayer-control.pipe
/usr/bin/mplayer -slave -input file=/home/administrator/files/mplayer-control.pipe /home/administrator/music/file.mp3
Run Code Online (Sandbox Code Playgroud)

然后我有一个用Python编写的GUI,它应该能够控制正在播放的mplayer实例的音量.我尝试过以下方法:

os.system('echo "set_property volume $musicvol" > /home/administrator/files/mplayer-control.pipe')
Run Code Online (Sandbox Code Playgroud)

如果我用数字值代替$ musicvol,那就行了,但遗憾的是没有用.我需要能够传递变量.

我也可以通过调用Python应用程序中的bash脚本来解决它,但我无法让它工作:

subprocess.call("/home/administrator/files/setvolume.sh", executable="bash", shell=True)
Run Code Online (Sandbox Code Playgroud)

python bash pipe fifo

3
推荐指数
1
解决办法
4467
查看次数

无法理解select()系统调用

我正在使用FIFO和select()系统命令运行测试.这个想法是:

  1. 进程1应该使用select()命令等待来自FIFO的消息
  2. 如果没有消息进来,进程一应该每5秒唤醒并说"还没有"
  3. 如果有消息进入,它应该唤醒,打印消息,然后终止

所以这里是代码注意我正在进行错误检查以节省空间:

//process 1's code
int main()
{
  int fd, ret;
  fd_set rfds;
  char buffer[100] = {0}; 
  char * myfifo = "/tmp/myfifo";
  struct timeval tv;

  tv.tv_sec = 5;  // 5 second sleep
  tv.tv_usec = 0;

  mkfifo(myfifo, 0666); //Make the fifo

  fd = open(myfifo, O_RDONLY);
  FD_ZERO(&rfds);    // clear the flags
  FD_SET(fd, &rfds); // set "read" on fd

  while((ret = select(fd+1, &rfds, NULL, NULL, &tv)) <= 0) //should be 1 when we're ready …
Run Code Online (Sandbox Code Playgroud)

c linux posix file-descriptor fifo

3
推荐指数
1
解决办法
2071
查看次数

当我尝试打开一个FIFO O_WRONLY时,我收到"没有这样的设备或地址"错误

在我的代码中,我创建了一个名为"my_fifo"的fifo,如果我在O_WRONLY | O_NONBLOCK模式下打开它,open()返回-1并且错误号为"No such device or address",另一方面,如果我打开fifo in O_RDONLY | O_NONBLOCK模式,它完美地运作.为什么会这样?有什么我做错了吗?

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

int main(int argc, char *argv[])
{

    char *fifoname = "my_fifo";
    mkfifo(fifoname, 0666);

    int fd;
    if ((fd = open(fifoname, O_WRONLY | O_NONBLOCK)) == -1)
    {
        perror("open pipe");
        exit(EXIT_FAILURE);
    }

    close(fd);

    exit(EXIT_SUCCESS);
}
Run Code Online (Sandbox Code Playgroud)

c linux fifo

3
推荐指数
1
解决办法
5433
查看次数

将列表修剪为最大元素数

我想删除列表中最旧的(即第一个)元素,这样该列表永远不会超过100个元素.

我想过:

L = [327983, 232382, 1, 2, 3, 4, 5, 6, 23]

if len(L) > 100:
    for i in range(len(L)-100):
        del L[0]

print L    # [4, 5, 6, 23]
Run Code Online (Sandbox Code Playgroud)

是否有一个没有迭代的解决方案(或更一般地说:一个更好的解决方案)来修剪列表的开头,以便它有<= 100个元素?


旁注:为此目的,除了列表之外,还有其他什么吗?即具有最大大小的数据结构,并且如果有更多数据,则删除最旧的数据!(这让我想到FIFO?Stack?Pipe?)

python list fifo

3
推荐指数
1
解决办法
1256
查看次数

c - 如何在 FIFO 上的 read() 时检查 EOF

在客户机-服务器程序,需要检查EOFread()FIFO

问题:

  • 是否EOF在FIFO回报0,或者-1并将errno设置?
  • 该规则是否也适用于其他 IPC 设施?

@更新

我仍然发现结果有效,所以需要继续询问它。


以下是源代码:

cs_fifo.h:

// fifo header
#ifndef _CS_FIFO
#define _CS_FIFO

#define CLIENT_DATA_SIZE 2
#define SERVER_DATA_SIZE 10

#define SERVER_FIFO_PATH "/tmp/server_fifo"

#define CLIENT_COUNT 3

#endif
Run Code Online (Sandbox Code Playgroud)

fifo_server.c:

// client - server fifo, server part,
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "cs_fifo.h"

int fifo_server() {
    int flag;
    int fd;

    char buf[CLIENT_DATA_SIZE];

    // remove fifo, …
Run Code Online (Sandbox Code Playgroud)

c linux ipc fifo eof

3
推荐指数
1
解决办法
3466
查看次数

C - 创建/写入/读取命名管道

我想创建一个命名管道,然后写入它,然后我想读取它。这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#define FIFO "fifo0001"
int main(intargc, char *argv[]){
    char input[256];
    FILE *fp;
    char str[50];
    printf("Please write some text:\n");
    scanf("%s", input);
    unlink(FIFO); /* Because it already exists, unlink it before */
    umask(0);
    if(mkfifo(FIFO, 0666) == -1){
        printf("Something went wrong");
        return EXIT_FAILURE;
    }
    if((fp = fopen(FIFO, "a")) == NULL){
        printf("Something went wrong");
        return EXIT_FAILURE;
    }
    fprintf(fp, "%s", input);
    if(fgets(str, 50, fp) != NULL){
        puts(str);
    }
    fclose(fp); …
Run Code Online (Sandbox Code Playgroud)

c fopen file pipe fifo

3
推荐指数
1
解决办法
8032
查看次数

尝试了解 Azure 服务总线会话

所以我试图了解用于在我的队列中创建 FIFO 的 Azure 服务总线会话 ID。

我的想法非常直接,但我不知道在 FIFO 方面是否正确。

我在想在我的队列中创建 FIFO 的这些步骤中:

创造:

首先:检查消息队列及其会话 ID 并公开 ID 层次结构。

Next:使用层次结构中最新的 Session-ID 创建新消息并将该值迭代 1 (+1)

下一步:发送到服务总线队列。

阅读:

首先:检查消息队列及其会话 ID 并公开 ID 层次结构。

下一步:读取并删除层次结构中最早的会话 ID。

下一个:过程...

请记住,我没有包括错误处理,例如读取和删除部分,因为我已经弄清楚了。

所以问题是这是正确的思维方式,而且,我如何在 C# 中实现这一点,我真的无法找到以直接方式解释这个概念的东西。

c# session fifo sessionid azure-servicebus-queues

3
推荐指数
2
解决办法
7119
查看次数

AWS SQS:可见性超时到期后,FIFO 队列中的消息顺序是什么?

在 AWS SQS FIFO 的队列中;当已读消息的可见性超时时,消息将位于队列的哪个位置?

例如:

  • 我在队列中有这些消息:'[A, B, C, D]'(顺序:A first in)
  • 我从队列中读取了一条消息,因此收到消息“A”
  • 消息“A”的可见性超时到期,消费者可以再次使用它

消息的新顺序是什么?

  • a) [A、B、C、D]
  • b) [B、C、D、A]

timeout message-queue fifo amazon-sqs amazon-web-services

3
推荐指数
1
解决办法
1058
查看次数

FIFO 通道读取不正确

我有 2 个不相关的进程。第一个创建一个 FIFO 通道并将数据写入其中。

测试组合:

int main(int argc, char *argv[])
{
    int f1;
    char *send_buf = "Hello";
    char recv_buf[128] = {0};

    if (mkfifo("mk.fifo", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == -1 && errno != EEXIST)
        error(0, errno, "mkfifo() error");

    f1 = open("mk.fifo", O_RDWR);
    perror("Opening ");

    printf("Sending string '%s'...\n", send_buf);
    write(f1, send_buf, strlen(send_buf));
    perror("Writing ");

    close(f1);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

第二个进程应该从先前创建的通道读取数据。

test2comp:

int main(int argc, char *argv[])
{
    int f2;
    char recv_buf[128] = {0};

    f2 = open("mk.fifo", O_RDONLY|O_NONBLOCK);
    perror("Opening "); …
Run Code Online (Sandbox Code Playgroud)

c linux named-pipes fifo

3
推荐指数
1
解决办法
92
查看次数