file-descriptor

What is the theoretical maximum number of open TCP connections that a modern Linux box can have

守給你的承諾、 提交于 2019-12-16 22:07:23
问题 Assuming infinite performance from hardware, can a Linux box support >65536 open TCP connections? I understand that the number of ephemeral ports (<65536) limits the number of connections from one local IP to one port on one remote IP. The tuple (local ip, local port, remote ip, remote port) is what uniquely defines a TCP connection; does this imply that more than 65K connections can be supported if more than one of these parameters are free. e.g. connections to a single port number on

What is the theoretical maximum number of open TCP connections that a modern Linux box can have

六月ゝ 毕业季﹏ 提交于 2019-12-16 22:06:59
问题 Assuming infinite performance from hardware, can a Linux box support >65536 open TCP connections? I understand that the number of ephemeral ports (<65536) limits the number of connections from one local IP to one port on one remote IP. The tuple (local ip, local port, remote ip, remote port) is what uniquely defines a TCP connection; does this imply that more than 65K connections can be supported if more than one of these parameters are free. e.g. connections to a single port number on

What is represented by the content of FILE*

笑着哭i 提交于 2019-12-14 03:57:08
问题 I have this program #include <stdio.h> #include <unistd.h> #include <sys/socket.h> #include <fcntl.h> int main(void) { FILE* f = fopen("/Users/user/a.cc", "rb"); printf("%i\n", f); // 1976385616 printf("%i\n", *f); // 1976385768 int sockfd = socket(AF_UNIX, SOCK_STREAM, 0); printf("%i\n", sockfd); // 4 fclose(f); close(sockfd); int fd = open("/Users/user/a.cc", O_TRUNC | O_WRONLY, 0); printf("%i\n", (int) fd); // 3 close(fd); } I know that 3 and 4 represents the file descriptors with 0, 1, 2

where is file descriptor stored in process memory?

让人想犯罪 __ 提交于 2019-12-14 03:49:36
问题 When a function A is called from a point of execution, internally it is a JMP statement to the address pointing to function A. So the current point of execution is saved onto the stack, the PC loads the address of the called function A and continues. To get back to the point of execution after the function call, the function block should have equal push and pops onto the stack. Normally in C on exiting the function, the stack variables defined are destroyed(which I presume means popped off

Can I pass a file descriptor over a 0mq (zeromq) ipc socket?

帅比萌擦擦* 提交于 2019-12-13 15:38:22
问题 I have a master process and several workers, communicating using 0mq 'ipc://' sockets (UNIX domain sockets). I want to pass a file descriptor from the master to a worker, along with a message. I know that 'raw' UNIX domain sockets can be used to pass a file descriptor from one process to another, but can I do it with my zeromq sockets? I don't care about portability, and frankly I don't care if its a slightly dirty solution. Is there any way? Thanks in advance. 回答1: Hackiest method would be

As a process child, how to know which file descriptor is parents

微笑、不失礼 提交于 2019-12-13 10:28:56
问题 I am attempting to write a program which forks and waits for his child to finish, then the child does some work on an input and then forks the same way it's parent does and so on. Now, I know that forking copies to the child the array of file descriptors and that I should close the ones associated with the parent, but I can't figure out which are the parents. Do I need to give to my child it's parents pid? I've been trying to wrap my head around it for the better part of an hour and I think I

read() on a NON-BLOCKING tun/tap file descriptor gets EAGAIN error

江枫思渺然 提交于 2019-12-12 21:05:32
问题 I want to read IP packets from a non-blocking tun/tap file descriptor tunfd I set the tunfd as non-blocking and register a READ_EV event for it in libevent. when the event is triggered, I read the first 20 bytes first to get the IP header, and then read the rest. nr_bytes = read(tunfd, buf, 20); ... ip_len = .... // here I get the IP length .... nr_bytes = read(tunfd, buf+20, ip_len-20); but for the read(tunfd, buf+20, ip_len-20) I got EAGAIN error, actually there should be a full packet, so

What does 200>“$somefile” accomplish? [duplicate]

风流意气都作罢 提交于 2019-12-12 19:39:49
问题 This question already has an answer here : How does this canonical flock example work? (1 answer) Closed 5 years ago . I've found boilerplate flock(1) code which looks promising. Now I want to understand the components before blindly using it. Seems like these functions are using the third form of flock flock [-sxun] [-w timeout] fd The third form is convenient inside shell scripts, and is usually used the following manner: ( flock -s 200 # ... commands executed under lock ... ) 200>/var/lock

linux x86 assembly language sys_read call should have first argument as 0 (stdin)

房东的猫 提交于 2019-12-12 18:13:42
问题 I was writing a simple assembly program to read from stdin, (like scanf). Here is my code. section .bss num resb 5 section .txt global _start _start: mov eax,3 ;sys_read mov ebx,0 ;fd 0 mov ecx,num mov edx,5 int 0x80 mov eax,4 ;sys_write mov ebx,1 ;fd 1 mov ecx,num mov edx,5 int 0x80 mov eax,1 ;sys_exit mov ebx,0 ;return 0 int 0x80 Now this works normally, it reads and prints. So, I tried changing file descriptor value in sys_read call to 1(stdout), 2(syserr). Code. section .bss num resb 5

Retrieve the number of opened file descriptors using the Windows API

与世无争的帅哥 提交于 2019-12-12 08:59:25
问题 I would like to know how many file descriptors have I opened in my C++ application. Can this be done using Windows API function? 回答1: You can ask each handle in the process using GetFileType. DWORD type_char = 0, type_disk = 0, type_pipe = 0, type_remote = 0, type_unknown = 0, handles_count = 0; GetProcessHandleCount(GetCurrentProcess(), &handles_count); handles_count *= 4; for (DWORD handle = 0x4; handle < handles_count; handle += 4) { switch (GetFileType((HANDLE)handle)){ case FILE_TYPE