posix

How to replace pthread_create during linkage

怎甘沉沦 提交于 2019-12-22 06:58:51
问题 I want to maintain a list of all running threads with some additional information about each thread. In this answer mentioned that it is possible to provide my own version of pthread_create and to link program with it. It is also important that I want to call original pthread_create in the end of my override version of it. Could someone explain in details how it could be done and/or provide some code example? 回答1: You can lookup the symbol for the original pthread_create-function by calling:

Determine if a function is async-signal-safe (can be called inside a signal handler)

风格不统一 提交于 2019-12-22 06:30:07
问题 My questions are: Is there a way to conclusively determine if a function is async-signal-safe if you don't have access to its implementation? If not, is there a way to test if function would be async-signal-safe enough to call from a signal handler? If you reads the man pages of signal() or sigaction(), you get a list of async-signal-safe functions (functions that can be safely called inside a signal handler). However, I believe that this list is not exhaustive. For example, the following

strdup() memory leak even after free()

☆樱花仙子☆ 提交于 2019-12-22 05:17:11
问题 I've never needed to use strdup(stringp) with strsep(&stringp_copy, token) together until recently and I think it was causing a memory leak. ( strdup() has always free 'd just fine before.) I fixed the leak, and I think I understand how, but I just can't figure out why I needed to. Original code (summarized): const char *message = "From: username\nMessage: basic message\n"; char *message_copy, *line, *field_name; int colon_position; message_copy = strdup(message); while(line = strsep(&message

Which functions are interrupted by signals even with SA_RESTART?

帅比萌擦擦* 提交于 2019-12-22 05:04:45
问题 Is there any reasonably complete list of which functions in POSIX are interrupted with EINTR when a signal is received or handled, even if there is no signal handler or if the handler was installed with SA_RESTART ? Some examples: select nanosleep etc. 回答1: tcsetattr is also not restartable, at least in Linux 2.6.18 回答2: POSIX says: If the signal-catching function executes a return statement, the behavior of the interrupted function shall be as described individually for that function, except

Which functions are interrupted by signals even with SA_RESTART?

流过昼夜 提交于 2019-12-22 05:04:14
问题 Is there any reasonably complete list of which functions in POSIX are interrupted with EINTR when a signal is received or handled, even if there is no signal handler or if the handler was installed with SA_RESTART ? Some examples: select nanosleep etc. 回答1: tcsetattr is also not restartable, at least in Linux 2.6.18 回答2: POSIX says: If the signal-catching function executes a return statement, the behavior of the interrupted function shall be as described individually for that function, except

pid=`cat $pidfile` or read pid <$pidfile?

狂风中的少年 提交于 2019-12-22 04:09:47
问题 I read a lot of init.d scripts and: pid=`cat $pidfile` lines make me sad. I don't understand why people doesn't use: read pid <$pidfile Last sample uses POSIX compliant syntax and doesn't do fork / exec to run external process ( cat ). Last solution also allow skipping content after first newline. Are there any traps with read command (despite that it perform splitting into fields)? UPDATE . Some peole use non-portable extension for shell like: How to get variable from text file into Bash

Is it safe to use getenv() in static initializers, that is, before main()?

你离开我真会死。 提交于 2019-12-22 03:15:47
问题 I looked in Stevens, and in the Posix Programmer's Guide, and the best I can find is An array of strings called the enviroment is made available when the process begins. This array is pointed to by the external variable environ , which is defined as: extern char **environ; It's that environ variable that has me hesitating. I want to say -The calling process/shell has already allocated the block of null terminated strings -the 'external' variable environ is used as the entry point by getenv()

Convert the Linux open, read, write, close functions to work on Windows

耗尽温柔 提交于 2019-12-21 21:22:53
问题 The code below was written for Linux and uses open, read, write and close. I am working on a Windows computer where I normally use fopen, fgets, fputs, fclose. Right now I get a no prototype error for open, read, write and close. Is there a header file I can include to make this work on a Windows computer or do I need to convert the code? Can you show how to convert it so it works the same on Windows or at least point me to an online document which shows how to convert it? #include <stdio.h>

Compiling/Matching POSIX Regular Expressions in C

泪湿孤枕 提交于 2019-12-21 20:54:13
问题 I'm trying to match the following items in the string pcode : u followed by a 1 or 2 digit number phaseu phasep x (surrounded by non-word chars) y (surrounded by non-word chars) z (surrounded by non-word chars) I've tried to implement a regex match using the POSIX regex functions (shown below), but have two problems: The compiled pattern seems to have no subpatterns (i.e. compiled.n_sub == 0). The pattern doesn't find matches in the string " u0", which it really should! I'm confident that the

Dealing with time-periods such as 5 minutes and 30 seconds in R

℡╲_俬逩灬. 提交于 2019-12-21 20:35:09
问题 Is there a good way to deal with time periods such as 05:30 (5 minutes, 30 seconds) in R? Alternatively what's the fastest way to convert it into an integer with just seconds? I can only convert to dates and can't really find a data type for time. I'm using R with zoo. Thanks a lot ! Seconds was the best way to deal with this. I adapted Shane's code below to my purposes, here's the result. # time - time in the format of dd hh:mm:ss # (That's the format used in cvs export from Alcatel CCS