posix

How to cleanly interrupt a thread blocking on a recv call?

妖精的绣舞 提交于 2019-12-18 04:47:15
问题 I have a multithreaded server written in C, with each client thread looking something like this: ssize_t n; struct request request; // Main loop: receive requests from the client and send responses. while(running && (n = recv(sockfd, &request, sizeof(request), 0)) == sizeof(request)) { // Process request and send response. } if(n == -1) perror("Error receiving request from client"); else if(n != sizeof(act)) fprintf(stderr, "Error receiving request from client: Incomplete data\n"); // Clean

Run Linux commands from Qt4

我是研究僧i 提交于 2019-12-18 04:09:22
问题 How can I run command-line programs under Linux from Qt4? And of course I want to obtain the output in some way I can use. I'd use it for an ls | grep , but it's good to know for any future issues. 回答1: QProcess p; p.start( /* whatever your command is, see the doc for param types */ ); p.waitForFinished(-1); QString p_stdout = p.readAllStandardOutput(); QString p_stderr = p.readAllStandardError(); 回答2: Use QProcess. 回答3: What about using popen? 来源: https://stackoverflow.com/questions/2148185

Run Linux commands from Qt4

梦想与她 提交于 2019-12-18 04:09:06
问题 How can I run command-line programs under Linux from Qt4? And of course I want to obtain the output in some way I can use. I'd use it for an ls | grep , but it's good to know for any future issues. 回答1: QProcess p; p.start( /* whatever your command is, see the doc for param types */ ); p.waitForFinished(-1); QString p_stdout = p.readAllStandardOutput(); QString p_stderr = p.readAllStandardError(); 回答2: Use QProcess. 回答3: What about using popen? 来源: https://stackoverflow.com/questions/2148185

How to get POSIX strerror_r instead of GNU version?

左心房为你撑大大i 提交于 2019-12-18 04:07:39
问题 How do I get the POSIX strerror_r instead of GNU version? I'm compiling with g++ on Ubuntu 8.04 with glibc version 2.7 ( based on what's in ). Edit On the above man page it says: Feature Test Macro Requirements for glibc (see feature_test_macros(7)): The XSI-compliant version of strerror_r() is provided if: (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE Otherwise, the GNU-specific version is provided. It then says in feature_test_macros(7): If no feature test macros are

munmap() failure with ENOMEM with private anonymous mapping

喜夏-厌秋 提交于 2019-12-18 03:51:13
问题 I have recently discovered that Linux does not guarantee that memory allocated with mmap can be freed with munmap if this leads to situation when number of VMA (Virtual Memory Area) structures exceed vm.max_map_count . Manpage states this (almost) clearly: ENOMEM The process's maximum number of mappings would have been exceeded. This error can also occur for munmap(), when unmapping a region in the middle of an existing mapping, since this results in two smaller mappings on either side of the

Do I need to do anything with a SIGCHLD handler if I am just using wait() to wait for 1 child to finish at a time?

感情迁移 提交于 2019-12-18 03:46:06
问题 I've got a program that is forking to a child to do some work, but I am only doing one child at a time at this time. I am using wait() to wait for the child to finish, do I need to do anything with SIGCHLD as well (such as disable the handler)? In my situation I am getting a value of EINTR in errno which leads me to think that I need to mask SIGCHLD . In broad strokes, this is the program: read arguments for(list of work to do) fork() if child, execlp() to work program if parent, wait() for

whoami in python [duplicate]

早过忘川 提交于 2019-12-18 01:26:08
问题 This question already has answers here : Is there a portable way to get the current username in Python? (12 answers) Closed 2 years ago . What is the best way to find out the user that a python process is running under? I could do this: name = os.popen('whoami').read() But that has to start a whole new process. os.environ["USER"] works sometimes, but sometimes that environment variable isn't set. 回答1: import getpass print getpass.getuser() See the documentation of the getpass module. getpass

Unix vs BSD vs TCP vs Internet sockets?

时光总嘲笑我的痴心妄想 提交于 2019-12-18 01:23:43
问题 I am reading The Linux Programming Interface and it describes several different types of socket used on Linux: Unix domain Berkeley TCP Internet One of the things the book said is that if you want to communicate between remote hosts, you couldn't use Unix domain sockets because they are for IPC on the same host. You have to use "Internet" sockets. However, I am still a little confused how this relates with "TCP" sockets, Berkeley sockets and the other 2? What is their relationship? Why would

Where are all my inodes being used?

北慕城南 提交于 2019-12-17 21:39:58
问题 How do I find out which directories are responsible for chewing up all my inodes? Ultimately the root directory will be responsible for the largest number of inodes, so I'm not sure exactly what sort of answer I want.. Basically, I'm running out of available inodes and need to find a unneeded directory to cull. Thanks, and sorry for the vague question. 回答1: So basically you're looking for which directories have a lot of files? Here's a first stab at it: find . -type d -print0 | xargs -0 -n1

zero length read from file

岁酱吖の 提交于 2019-12-17 21:14:27
问题 I have two processes, one of which is writing (appending) to a file, the other is reading from it. Both processes are running concurrently, but do not communicate. Another reader process may start before the writer process has finished. This approach works, but read() often returns having read zero bytes with no error. They ratio of zero length reads to non-zero length reads is high, which is inefficient. Is there any way around this? This is on POSIX filesystems. 回答1: Without a communication