再阅读()制作与fgets的问题要求在Linux上 [英] Making fgets issue longer read() calls on linux

查看:141
本文介绍了再阅读()制作与fgets的问题要求在Linux上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在读比较大的线路使用文本(最多128K)与fgets 。我看到过多的上下文切换的服务器上,使用 strace的我看到以下内容:

I'm reading quite large lines(up to 128K) of text using fgets. I'm seeing excessive context switching on the server, using strace I see the following:

read(3, "9005 10218 00840023102015 201008"..., 4096) = 4096

即。 与fgets 一次读取的4096字节块。有什么办法来控制大块与fgets 采用调用时,阅读()

i.e. fgets reads chunks of 4096 bytes at a time. Is there any way to control how big chunks fgets uses to when calling read() ?

推荐答案

setvbuf用来将是明显的地方开始。

setvbuf would be the obvious place to start.

这篇关于再阅读()制作与fgets的问题要求在Linux上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆