file-descriptor

How to get the file descriptors of TCP socket for a given process in Linux?

为君一笑 提交于 2020-07-11 04:42:49
问题 I'm trying to find the file descriptors for all TCP sockets of a given process, ie. given its pid, so that I can get the socket option at another process without modifying the original one. For example, if I know the file descriptor is fd , then I hope to call getsockopt(fd, ...) to retrieve the options at another process. I'm wondering is this doable? If so, how to get the fd I need outside the original process? I have tried to print out the return value when creating a socket, ie. s =

How to close a file descriptor from another process in unix systems

↘锁芯ラ 提交于 2020-07-04 05:48:51
问题 You can use command lsof to get file descriptors for all running processes, but what I would like to do is to close some of those descriptors without being inside that process. This can be done on Windows, so you can easily unblock some application. Is there any command or function for that? 回答1: In Windows you can use a program to do it because someone wrote a program that inserts a device driver into the running kernel to do it. By the way it can be dangerous to do this, because after you

Difference between “file pointer”, “stream”, “file descriptor” and … “file”?

那年仲夏 提交于 2020-06-16 09:51:09
问题 There are a few related concepts out there, namely file pointer , stream and file descriptor . I know that a file pointer is a pointer to the data type FILE (declared in e.g. FILE.h and struct_FILE.h ). I know a file descriptor is an int , e.g. member _fileno of FILE (and _IO_FILE ). As for the subtle difference between stream and file, I am still learning. But from here, I am not clear if there is yet another type of entity to which the "file status flags" apply. Concretely, I wouldn't know

Difference between “file pointer”, “stream”, “file descriptor” and … “file”?

我怕爱的太早我们不能终老 提交于 2020-06-16 09:50:11
问题 There are a few related concepts out there, namely file pointer , stream and file descriptor . I know that a file pointer is a pointer to the data type FILE (declared in e.g. FILE.h and struct_FILE.h ). I know a file descriptor is an int , e.g. member _fileno of FILE (and _IO_FILE ). As for the subtle difference between stream and file, I am still learning. But from here, I am not clear if there is yet another type of entity to which the "file status flags" apply. Concretely, I wouldn't know

What is difference between file descriptor and file pointer? [duplicate]

风格不统一 提交于 2020-06-14 06:38:09
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What's the difference between a file descriptor and file pointer? If I open file like this: FILE *fp = fopen("mr32.txr","r"); then fp is file pointer or file descriptor? What is difference between them? 回答1: fp is a FILE pointer File pointer: It is high level interface Passed to fread() and fwrite() functions Includes buffering,error indication and EOF detection,etc. Provides higher portability and efficiency.

Safety check prior to using fdopen

↘锁芯ラ 提交于 2020-06-09 07:07:04
问题 Motivated by Smart-write to arbitrary file descriptor from C/C++, I mean to associate a file descriptor with a file pointer and use that for writing. I put together program io.cc below: int main() { int nbytes; const int fd = 3; FILE * fp = fdopen(fd, "a"); fprintf(fp, "Writing to file descriptor %d\n", fd); cout << "Testing alternate writing to stdout and to another fd" << endl; fprintf(fp, "Writing again to file descriptor %d\n", fd); fclose(fp); return 0; } Should I perform some kind of