- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
背景:
我正在尝试编写一个同时记录 JSONS 的小脚本,如果文件大小很小,则一切正常。但是当文件很大时,进程开始相互覆盖。这篇 SO 帖子有助于指出正确的方向:PIPE_BUFF . Windows 似乎将其设置为 1024,在 linux 上更大 How big is the PIPE_BUFF?
PS:我在 WSL2 Ubuntu 20.04
问题
我尝试使用 Fcntl constant F_SETPIPE_SZ 设置 PIPE_BUFF 值,但是我没有成功:
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Data::Dumper qw(Dumper);
use File::Basename qw(basename dirname);
use File::Spec qw(catfile file_name_is_absolute catdir);
use feature qw(say current_sub);
use Cwd qw(abs_path);
use lib dirname(abs_path $0);
use Fcntl qw(F_SETPIPE_SZ F_GETPIPE_SZ F_GETFL F_GETFD F_SETFL O_NONBLOCK O_WRONLY O_APPEND O_CREAT O_RDWR F_DUPFD F_SETOWN F_GETOWN);
open(my $fileH,">", File::Spec -> catfile(dirname(__FILE__), "blabla.txt"));
#does F_GETFD work?
my $val = fcntl($fileH, F_GETFD, 0);
say $val; #outputs 1, works
#does F_GETFL work?
my $val2 = fcntl($fileH, F_GETFL, 0);
say $val2; #outputs 32769, works
#does F_GETOWN work?
my $val3 = fcntl($fileH, F_GETOWN, 0);
say $val3; #outputs 0 but true, so it works too.
my $pid = +$$;#process id
#does F_SETOWN work?
my $val4 = fcntl($fileH, F_SETOWN, $pid) or die("error: $!");;
say $val4; #outputs 0 but true
#does getting pipe buffer work?
my $val5 = fcntl($fileH, F_GETPIPE_SZ, 0) or die("error: $!"); #"Bad file descriptor"
say $val5; #Use of uninitialized..so $val5 is undef, did not work
#does setting pipe buffer work?
my $val6 = fcntl($fileH, F_SETPIPE_SZ, 1000 * 1000) or die("error: $!"); #"Bad file descriptor"
say $val6; #undef
像 F_GETFD 或 F_GETFL 这样的几个常量可以工作,所以我猜 Fcntl 运行正常。
fcntl
fileno($fileH)
而不是
$fileH
导致“未打开的文件句柄”错误,所以它也不会改变任何东西。
最佳答案
Linux fcntl()
标志 F_GETPIPE_SZ
和 F_SETPIPE_SZ
正如他们的名字所暗示的,是特定于管道的。您正在尝试将它们与常规文件一起使用,因此会失败。
为了清楚起见:
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw/say/;
use Fcntl qw/F_GETPIPE_SZ/;
open my $file, ">", "/tmp/foo.txt" or die "Unable to open /tmp/foo.txt: $!\n";
pipe my $reader, my $writer or die "Unable to create pipe: $!\n";
if (my $size = fcntl($file, F_GETPIPE_SZ, 0)) {
say "filehandle size: $size";
} else {
say "fcntl of file failed: $!";
}
if (my $size = fcntl($reader, F_GETPIPE_SZ, 0)) {
say "pipe size: $size";
} else {
say "fcntl of pipe filed: $!";
}
可能的输出:
fcntl of file failed: Bad file descriptor
pipe size: 65536
关于Perl Fcntl 调用 F_SETPIPE_SZ 或 F_GETPIPE_SZ 抛出 "Bad file descriptor",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71764128/
我有一个用于查找存储设备序列号的内核驱动程序,但该驱动程序存在问题。Descriptor->SerialNumberOffset 为 103但是 (LPCSTR)(UINT_PTR)Descripto
在我的程序中,每当我用导致无法检测到 ORB 功能的东西覆盖相机时,程序就会崩溃并出现错误: OpenCV Error: Assertion failed (type == src2.type() &
定义 通常,一个 descriptor 是具有“绑定行为”的对象属性。所绑定行为可通过 descriptor 协议被自定义的 __get__() , __set__() 和 __delete__(
如 normaluser : $ ulimit -n 4096 -bash: ulimit: open files: cannot modify limit: Operation not permit
我正在尝试在elasticsearch中安装ik分析,ik源来自以下位置: GitHub 我的步骤来自自述文件和来自互联网的一些资料 cd elasticsearch-analysis-ik mvn
我有以下代码: int fds[2]; if (pipe(fds) < 0) { fprintf(stderr, "ERROR, unable to open pipe: %s\n", str
我在 C 中有一个简单的生产者消费者程序,尝试用 fork 解决它当生产者试图在管道上写入时,我得到了错误:我用相同的逻辑编写了另一个程序,但这个程序没有给我任何线索,让我知道为什么? 生产者无法在管
我很难理解 FREAK 描述符中的参数 orientationNormalized 和 scaleNormalized。知道它们的意思或作用吗? OpenCV FREAK 文档:http://docs
我在做的事情是否符合通用设计模式?如果有,名字是什么? 我有一个复杂对象,它具有“简单”字段,例如字符串和字符串列表,以及其他复杂对象。我想将此对象的实例添加到 JMS 消息队列中,这意味着它们需要是
在例子中: event.events = EPOLLIN; event.data.fd = fd; int ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, event
最近,我的 Crashlytics 和 Apple 崩溃日志收到了许多崩溃信息 -[CTTelephonyNetworkInfo updateRat:descriptor:]在没有太多其他信息的情况下
是否有可能将N个文件描述符作为一个文件描述符显示给程序,以便在N个文件描述符(即从N个套接字)中接收的数据将被转发回单个文件描述符上的调用API,从而隐藏它实际上可能来自不同的文件描述符的事实吗?是否
网络编程菜鸟在这里, 我对accept和connect套接字函数的行为感到困惑。在大多数编程语言中,这些函数的包装返回不同类型的值:accept返回可用于发送/接收数据的新描述符,但是connect不
我正在尝试启动resque-web,但是会发生此错误: [Sun Mar 06 05:27:48 +0000 2011]启动“resque-web” ... [Sun Mar 06 05:27:48
我有一个项目,其中有几个为程序集插件编写的自定义描述符。有没有办法一次只运行其中一个描述符而不是整个描述符?我尝试使用文档中的描述符开关 here ,传递到我想要运行的一个描述符的完整路径,但它正在运
我正在尝试学习 POSIX 中的基本 IO 函数,我编写了以下代码,但它不起作用,并且在我尝试执行代码时返回“Bad file descriptor”错误: #include #include #
编辑:最小、完整和可验证的示例位于下面的注释中,代码实际上有效,问题出在不同的区域。抱歉,发帖错误,我现在无法删除它。 我知道,已经有一些关于此的页面,但我确实尝试了所有方法,但没有任何效果。我一直遇
#define MAX 2 int main(){ int mutex = semget(ftok("/usr",'P'),1,IPC_CREAT|0666); int wrt = s
我正在尝试实现一个 simpel c shell,它将通过管道传输任意数量的命令。这是相关的 for 循环: int status; int i,j,inputFile,outputFile,pid;
简介 我典型的swig接口(interface)文件类似如下: %{ //COPY THIS BLOCK AS IS #include static CppClass* get_Cp
我是一名优秀的程序员,十分优秀!