posix

What is the epoch of CLOCK_TAI?

▼魔方 西西 提交于 2019-12-21 17:38:02
问题 Since Linux kernel version 3.10, the function clock_gettime() now accept CLOCK_TAI . I didn't manage to find a detailed description of this clock. What is its epoch ? EDIT 1 : Just compared the output of CLOCK_REALTIME and CLOCK_TAI on my Linux 3.19 OS and it returns the exact same value (1442582497) !? Is CLOCK_REALTIME decremented at leap seconds ? EDIT 2 : According to this article, the difference between CLOCK_TAI and the (badly named) CLOCK_REALTIME should be the number of leap seconds.

How to legally use type-punning with unions to cast between variations of struct sockaddr without violating the strict aliasing rule?

孤街醉人 提交于 2019-12-21 17:32:54
问题 POSIX intends pointers to variations of struct sockaddr to be castable, however depending on the interpretation of the C standard this may be a violation of the strict aliasing rule and therefore UB. (See this answer with comments below it.) I can, at least, confirm that there may at least be a problem with gcc: this code prints Bug! with optimization enabled, and Yay! with optimization disabled: #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> sa_family_t test(struct

Detach child process from parent

随声附和 提交于 2019-12-21 17:16:46
问题 When a child process forked from a parent dies, it still exists to some extent and is left in a zombie state, until it is reaped from a wait() call. Is is possible to detach this parent-child relationship and have the children be automatically reaped? Maybe orphan off the child to init, or something? Possible use case: Creating a lot of fire-and-forget processes in a long-lived program, without "holding" on to an increasing list of zombie PIDs that cannot be recycled by the OS. 回答1: Per the

posix threads block signal and unblock

牧云@^-^@ 提交于 2019-12-21 12:40:04
问题 Is there a way to block certain signals and unblock other signals in the same set? I just dont seem to get my head around it! An example sigset_t set; sigemptyset(&set); sigaddset(&set, SIGUSR1); // Block signal SIGUSR1 in this thread pthread_sigmask(SIG_BLOCK, &set, NULL); sigaddset(&set, SIGALRM); // Listen to signal SIGUSR2 pthread_sigmask(SIG_UNBLOCK, &set, NULL); pthread_t printer_thread1, printer_thread2; pthread_create(&printer_thread1, NULL, print, (void *)&f1); pthread_create(

Why create system call is called creat? [closed]

心不动则不痛 提交于 2019-12-21 07:06:23
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Why create system call is called creat ? Also, why a define for a buffer size is called BUFSIZ and not BUFSIZE ? Are there any other

Why create system call is called creat? [closed]

断了今生、忘了曾经 提交于 2019-12-21 07:06:12
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Why create system call is called creat ? Also, why a define for a buffer size is called BUFSIZ and not BUFSIZE ? Are there any other

Non-busy blocking Queue Implementation in C

南楼画角 提交于 2019-12-21 05:58:07
问题 I am trying to implement a queue in C that causes a process to non-busy wait until there is an element in the queue to consume. I have tried two different things to try to achieve this. The first problem I have is if the enqueue/dequeue operations have if conditionals to check the bounds( if (q->count == QUEUESIZE) ), the call to sem_wait will return immediately because no other process has obtained a lock. If I change the conditional to while (q->count == QUEUESIZE), I believe the consumer

What is POSIX compliance and how does it affect me?

自作多情 提交于 2019-12-21 05:49:09
问题 I keep seeing this come up and every time I look it up I never get a good explanation of what it is or what it means to me. What is POSIX compliance? How does assuming my program will only be run on POSIX-compliant machines simplify things for me as a programmer? Does it even? 回答1: POSIX defines a set of C headers, System Interfaces, a Shell Command Language and Utilities, that a conforming system must implement. As a developer, you can rely on these standard interfaces being available on

Is there a way to reuse pthreads?

主宰稳场 提交于 2019-12-21 05:46:06
问题 I have a function that is called millions of times, and the work done by this function is multithreaded. Here is the function: void functionCalledSoManyTimes() { for (int i = 0; i < NUM_OF_THREADS; i++) { pthread_create(&threads[i], &attr, thread_work_function, (void *)&thread_data[i]); } // wait } I'm creating the threads each time the function is called, and I give each thread its data struct (that's been set once at the beginning of the algorithm) to use in the thread_work_function . The

Does the Python regular expression module use BRE or ERE?

拟墨画扇 提交于 2019-12-21 04:44:07
问题 It appears that POSIX splits regular expression implementations into two kinds: Basic Regular Expressions (BRE) and Extended Regular Expressions (ERE). Python re module reference does not seem to specify. 回答1: Except for some similarity in the syntax, re module doesn't follow POSIX standard for regular expressions . Different matching semantics POSIX regular expression (which can be implemented with a DFA/NFA or even a backtracking engine) always finds the leftmost longest match , while re