file-descriptor

Golang bad file descriptor

本小妞迷上赌 提交于 2019-12-21 03:23:39
问题 I am getting a bad file descriptor when trying to append to a logging file within my go routine. write ./log.log: bad file descriptor The file exists and has 666 for permissions. At first I thought well maybe it is because each one of them is trying to open the file at the same time. I implemented a mutex to try and avoid that but got the same issue so I removed it. logCh := make(chan string, 150) go func() { for { msg, ok := <-logCh if ok { if f, err := os.OpenFile("./log.log", os.O_APPEND,

File descriptor leak example?

天大地大妈咪最大 提交于 2019-12-20 10:42:09
问题 Is there any good example do demonstrate file descriptor leak in Android? I read somewhere that it occurs if we don't close the streams for example FileInputStream or FileOutputStream but I could not find any good reference example which demonstrates it. Please share some blog/code snippet. thank you! 回答1: Because Dalvik's FileInputStream will close itself when it is garbage collected (this is also true for OpenJDK/Oracle) it is less common than you'd think to actually leak file descriptors.

Does exec preserve file descriptors

僤鯓⒐⒋嵵緔 提交于 2019-12-20 10:28:41
问题 This is actually a two-step question: What exactly is a file descriptor? I thought it was the most fundamental way to represent an open file. But since dup2 can make two different file descriptors point to the same file, then what is it that represents a unique file? If I do dup2 before exec, the whole program is then wiped out, does it still have the same file descriptor table? Do the redirected file descriptors still are redirected? 回答1: Yes . Open file descriptors are preserved across a

Multiprocessing and sockets in Python

Deadly 提交于 2019-12-20 10:12:05
问题 I am trying to make multiprocessing and socket programming work together, but, I am stuck at this point. Problem is that, I am getting this error: File "multiprocesssockserv.py", line 11, in worker clientsocket = socket.fromfd(clientfileno, socket.AF_INET, socket.SOCK_STREAM) error: [Errno 9] Bad file descriptor Complete code that causing the error is as following: import multiprocessing as mp import logging import socket logger = mp.log_to_stderr(logging.WARN) def worker(queue): while True:

Increase max open files for Ubuntu/Upstart (initctl)

 ̄綄美尐妖づ 提交于 2019-12-20 09:57:34
问题 This is on an Ubuntu 12.04.3 LTS server. I've added the following to /etc/security/limits.conf (my Golang processes run as root): * hard nofile 50000 * soft nofile 50000 root hard nofile 50000 root soft nofile 50000 I've added the following to /etc/pam.d/common-session session required pam_limits.so I've added the following to /etc/sysctl.conf: fs.file-max = 50000 Yet when I cat /proc/{PID}/limits, I get: Limit Soft Limit Hard Limit Units Max open files 1024 4096 files This happens only when

How to execute a program from file descriptor?

你说的曾经没有我的故事 提交于 2019-12-19 17:32:42
问题 I need to execute a file when I only know the descriptor. It is also possible that there are no links to the file so finding out the name somehow is not an option. All the execve(), execvp(), etc functions take a file name. dlopen() also takes a name. Ugly solutions (like reading the file and calling some function pointer) are OK. 回答1: Use fexecve. PS: reading the file and calling some function pointer is definitely not OK. :) 回答2: Interesting. I think your best bet is going to be to use the

How to replace successive occurrences of characters in a file by the number

余生颓废 提交于 2019-12-19 05:09:04
问题 In my code, I successfully opened the file, but now I don't understand how to perform a loop using the read() function, to get all the characters in file1 . I set a buffer of size 8, but the file contents are more. Thanks. Also please help me do this using syscalls like that 回答1: You are getting confused between a char and a pointer to a char : char *buffer[4096]; Is an array of pointers to chars, an is supposed to hold pointers, not chars . What you want is an array of char : char buffer

When is FileDescriptor closed?

别来无恙 提交于 2019-12-19 04:13:16
问题 My app needs to do the following: Open a FileInputStream , and obtain the underlying FileDescriptor (via getFd() ) Create new FileInputStream objects based on the above FileDescriptor So far, I only needed one FileDescriptor , so I used to close it by calling close() on the original stream (i.e. on the stream which getFd() I called). I use it because some Android API methods have such a parameter. Now that I will have more FileInputStream objects at the same time, when will the FileDescriptor

Automatic JDBC Realm configuration

≡放荡痞女 提交于 2019-12-18 18:09:12
问题 I want to know if it's possible to create JDBC Realm configuration in Glassfish 3.1 without admin console, like creation of a Data Source with the glassfish-resources.xml . When developers download my GIT repository they don't like to configure Glassfish, it's configured in deployment time. Best regards Mounir 回答1: I'd create a shell script or batch file which runs the required asadmin commands. Here you can find a complete example: Creating JDBC Objects Using asadmin (Btw, DTD of GlassFish

Writing to child process file descriptor

孤人 提交于 2019-12-18 13:36:27
问题 I have a program "Sample" which takes input both from stdin and a non-standard file descriptor (3 or 4) as shown below int pfds[2]; pipe(pfds); printf("%s","\nEnter input for stdin"); read(0, pO, 5); printf("\nEnter input for fds 3"); read(pfds[0], pX, 5); printf("\nOutput stout"); write(1, pO, strlen(pO)); printf("\nOutput fd 4"); write(pfds[1], pX, strlen(pX)); Now i have another program "Operator" which executes the above program(Sample) in a child process using execv. Now what i want is