From bf5206d049f1eb6398b39cfd954eb79b8777c416 Mon Sep 17 00:00:00 2001
From: winlin <winlin@vip.126.com>
Date: Tue, 11 Nov 2014 17:02:16 +0800
Subject: [PATCH] Revert "Revert "add test file to show the max open files.""

This reverts commit ea70f29648e6ab431dfc18dddc4a4831d78e7f84.
---
 trunk/research/arm/pipe_fds.cpp | 48 +++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 trunk/research/arm/pipe_fds.cpp

diff --git a/trunk/research/arm/pipe_fds.cpp b/trunk/research/arm/pipe_fds.cpp
new file mode 100644
index 000000000..d1c024f51
--- /dev/null
+++ b/trunk/research/arm/pipe_fds.cpp
@@ -0,0 +1,48 @@
+/**
+g++ pipe_fds.cpp -g -O0 -o pipe_fds
+
+About the limits:
+[winlin@dev6 srs]$ ulimit -n
+    1024
+[winlin@dev6 srs]$ sudo lsof -p 21182
+    pipe_fds 21182 winlin    0u   CHR  136,4      0t0       7 /dev/pts/4
+    pipe_fds 21182 winlin    1u   CHR  136,4      0t0       7 /dev/pts/4
+    pipe_fds 21182 winlin    2u   CHR  136,4      0t0       7 /dev/pts/4
+    pipe_fds 21182 winlin    3r  FIFO    0,8      0t0  464543 pipe
+    pipe_fds 21182 winlin 1021r  FIFO    0,8      0t0  465052 pipe
+    pipe_fds 21182 winlin 1022w  FIFO    0,8      0t0  465052 pipe
+So, all fds can be open is <1024, that is, can open 1023 files.
+The 0, 1, 2 is opened file, so can open 1023-3=1020files, 
+Where 1020/2=512, so we can open 512 pipes.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+int main(int argc, char** argv)
+{
+    if (argc <= 1) {
+        printf("Usage: %s <nb_pipes>\n"
+            "   nb_pipes the pipes to open.\n"
+            "For example:\n"
+            "   %s 1024\n", argv[0], argv[0]);
+        exit(-1);
+    }
+    
+    int nb_pipes = ::atoi(argv[1]);
+    for (int i = 0; i < nb_pipes; i++) {
+        int fds[2];
+        if (pipe(fds) < 0) {
+            printf("failed to create pipe. i=%d, errno=%d(%s)\n", 
+                i, errno, strerror(errno));
+            break;
+        }
+    }
+    
+    printf("Press CTRL+C to quit, use bellow command to show the fds opened:\n");
+    printf("    sudo lsof -p %d\n", getpid());
+    sleep(-1);
+    return 0;
+}