正在显示
1 个修改的文件
包含
0 行增加
和
48 行删除
trunk/research/arm/pipe_fds.cpp
已删除
100644 → 0
1 | -/** | ||
2 | -g++ pipe_fds.cpp -g -O0 -o pipe_fds | ||
3 | - | ||
4 | -About the limits: | ||
5 | -[winlin@dev6 srs]$ ulimit -n | ||
6 | - 1024 | ||
7 | -[winlin@dev6 srs]$ sudo lsof -p 21182 | ||
8 | - pipe_fds 21182 winlin 0u CHR 136,4 0t0 7 /dev/pts/4 | ||
9 | - pipe_fds 21182 winlin 1u CHR 136,4 0t0 7 /dev/pts/4 | ||
10 | - pipe_fds 21182 winlin 2u CHR 136,4 0t0 7 /dev/pts/4 | ||
11 | - pipe_fds 21182 winlin 3r FIFO 0,8 0t0 464543 pipe | ||
12 | - pipe_fds 21182 winlin 1021r FIFO 0,8 0t0 465052 pipe | ||
13 | - pipe_fds 21182 winlin 1022w FIFO 0,8 0t0 465052 pipe | ||
14 | -So, all fds can be open is <1024, that is, can open 1023 files. | ||
15 | -The 0, 1, 2 is opened file, so can open 1023-3=1020files, | ||
16 | -Where 1020/2=512, so we can open 512 pipes. | ||
17 | -*/ | ||
18 | -#include <stdio.h> | ||
19 | -#include <stdlib.h> | ||
20 | -#include <unistd.h> | ||
21 | -#include <errno.h> | ||
22 | -#include <string.h> | ||
23 | - | ||
24 | -int main(int argc, char** argv) | ||
25 | -{ | ||
26 | - if (argc <= 1) { | ||
27 | - printf("Usage: %s <nb_pipes>\n" | ||
28 | - " nb_pipes the pipes to open.\n" | ||
29 | - "For example:\n" | ||
30 | - " %s 1024\n", argv[0], argv[0]); | ||
31 | - exit(-1); | ||
32 | - } | ||
33 | - | ||
34 | - int nb_pipes = ::atoi(argv[1]); | ||
35 | - for (int i = 0; i < nb_pipes; i++) { | ||
36 | - int fds[2]; | ||
37 | - if (pipe(fds) < 0) { | ||
38 | - printf("failed to create pipe. i=%d, errno=%d(%s)\n", | ||
39 | - i, errno, strerror(errno)); | ||
40 | - break; | ||
41 | - } | ||
42 | - } | ||
43 | - | ||
44 | - printf("Press CTRL+C to quit, use bellow command to show the fds opened:\n"); | ||
45 | - printf(" sudo lsof -p %d\n", getpid()); | ||
46 | - sleep(-1); | ||
47 | - return 0; | ||
48 | -} |
-
请 注册 或 登录 后发表评论