posix

If close(2) fails with EIO, will the file descriptor still be deleted?

时光毁灭记忆、已成空白 提交于 2019-12-19 05:06:54
问题 If a close(2) system call fails with EIO, will the file descriptor still be deleted? If yes, is it not possible to handle a spurious IO error by retrying later? If no, how should one prevent a file descriptor leak? 回答1: That's a tricky question. However, the POSIX standard does cover it in the description of close(): If close() is interrupted by a signal that is to be caught, it shall return -1 with errno set to [EINTR] and the state of fildes is unspecified. If an I/O error occurred while

getnameinfo specifies socklen_t

匆匆过客 提交于 2019-12-19 04:08:23
问题 The 2nd arg for the getnameinfo prototype asks for a socklen_t type but sizeof uses size_t. So how can I get socklen_t ? Prototype: int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags); Example: struct sockaddr_in SIN; memset(&SIN, 0, sizeof(SIN)); // This should also be socklen_t ? SIN.sin_family = AF_INET; SIN.sin_addr.s_addr = inet_addr(IP); SIN.sin_port = 0; getnameinfo((struct

How and when should I use _POSIX_C_SOURCE in C programs?

放肆的年华 提交于 2019-12-19 03:11:16
问题 I've gotten myself into having to maintain some C project which should also compile on older platforms. At the moment, for some platforms, the macro _POSIX_C_SOURCE is defined. I was wondering - if it's acceptable to have it defined, should I not just define it always, on all platforms? And perhaps with the highest relevant value? To generalize, I suppose I'm asking: When and under what conditions should _POSIX_C_SOURCE be used? 回答1: _POSIX_C_SOURCE makes different functionality available.

Constants not loaded by compiler

强颜欢笑 提交于 2019-12-18 23:14:06
问题 I started studying POSIX timers, so I started also doing some exercises, but I immediately had some problems with the compiler. When compiling this code, I get some strange messages about macros like CLOCK_MONOTONIC. Those are defined in various libraries like time.h etc. but the compiler gives me errors as if they are not defined. It is strange because I am using a Fedora 16, and some of my friends with Ubuntu get less compiler errors than I :-O I am compiling with gcc -O0 -g3 -Wall -c

Constants not loaded by compiler

心不动则不痛 提交于 2019-12-18 23:13:07
问题 I started studying POSIX timers, so I started also doing some exercises, but I immediately had some problems with the compiler. When compiling this code, I get some strange messages about macros like CLOCK_MONOTONIC. Those are defined in various libraries like time.h etc. but the compiler gives me errors as if they are not defined. It is strange because I am using a Fedora 16, and some of my friends with Ubuntu get less compiler errors than I :-O I am compiling with gcc -O0 -g3 -Wall -c

difference between exit and return after vfork() call

浪尽此生 提交于 2019-12-18 17:31:01
问题 I have a program with undefined behavior ( vfork() is used inappropriately ): #include <stdio.h> #include <unistd.h> #include <errno.h> int main ( int argc, char *argv[] ) { pid_t pid; printf("___________befor fork______________.\n"); if((pid=vfork()) < 0) perror("fork"); else if(pid > 0) printf("parent\n"); else printf("child\n"); printf("pid: %d, ppid: %d\n", getpid(), getppid()); //exit(0); return 0; } If I use exit(0) function instead return - output is: ___________befor fork_____________

Is glibc's implementation of fprintf() thread-safe?

六眼飞鱼酱① 提交于 2019-12-18 15:52:35
问题 Is fprintf thread-safe? The glibc manual seems to say it is, but my application, which writes to a file using single call to fprintf() seems to be intermingling partial writes from different processes. edit: To clarify, the program in question is a lighttpd plugin, and the server is running with multiple worker threads. Looking at the file, some of the writes are intermingled. edit 2: It seems the problem I'm seeing might be due to lighttpd's "worker threads" actually being separate processes

multiple threads doing poll() or select() on a single socket or pipe

泪湿孤枕 提交于 2019-12-18 14:09:46
问题 What do POSIX and other standards say about the situation where multiple threads are doing poll() or select() calls on a single socket or pipe handle at the same time? If any data arrives, does only one of the waiting threads get woken up or do all of the waiting threads get woken up? 回答1: Interesting question ... I read through the current POSIX and did not find a specific answer, i.e., no specification about concurrent invocations. So I'll explain why I think the standard means all will

multiple threads doing poll() or select() on a single socket or pipe

冷暖自知 提交于 2019-12-18 14:09:02
问题 What do POSIX and other standards say about the situation where multiple threads are doing poll() or select() calls on a single socket or pipe handle at the same time? If any data arrives, does only one of the waiting threads get woken up or do all of the waiting threads get woken up? 回答1: Interesting question ... I read through the current POSIX and did not find a specific answer, i.e., no specification about concurrent invocations. So I'll explain why I think the standard means all will

Name and Unnamed Semaphore

為{幸葍}努か 提交于 2019-12-18 13:24:23
问题 I'm trying to understand the similarities and differences between named and unnamed semaphore so my google searches yielded me this. I had a question about the wording on the page though, it says: Unnamed semaphores might be usable by more than one process Named semaphores are sharable by several processes Do those two words create any important distinction between those two types of semaphores or are they irrelevant? So so far here's what I have: Similarities -Several processes can do