posix

Suppressing “ISO C99 requires rest arguments to be used”

拈花ヽ惹草 提交于 2019-12-23 07:25:41
问题 Consider the following two macros: #define PNORM( v, s, ... ) { \ if( VERBOSITY_CHECK( v ) ) { \ if( ( errno = pthread_mutex_lock(&server.output_mutex) ) ) { \ PERROR_LOCKFREE( normal, "\tpthread_mutex_lock failed on output_mutex.\r\n" ) ; \ } \ fprintf( stdout, s, ## __VA_ARGS__ ) ; \ fflush( stdout ) ; \ if( ( errno = pthread_mutex_unlock(&server.output_mutex) ) ) { \ PERROR_LOCKFREE( normal, "\tpthread_mutex_unlock failed on output_mutex.\r\n" ) ; \ } \ } \ } #define PERROR_LOCKFREE( v, s,

Is creating two FILEs for the same file descriptor well-defined?

旧巷老猫 提交于 2019-12-23 07:11:40
问题 POSIX specifies an fdopen function that creates a FILE for a file descriptor. POSIX also specifies a fileno function that returns the file descriptor for a FILE . Together, these two could be used to create a second FILE accessing the same underlying file descriptor as an existing file: FILE *secondfile(FILE *f, const char *mode) { int fd = fileno(f); return fd >= 0 ? fdopen(fd, mode) : NULL; } Is this a well-defined operation under POSIX? What happens when I access both the original FILE and

Is it possible to avoid a wakeup-waiting race using only POSIX semaphores? Is it benign?

雨燕双飞 提交于 2019-12-23 05:58:11
问题 I'd like to use POSIX semaphores to manage atomic get and put from a file representing a queue. I want the flexibility of having something named in the filesystem, so that completely unrelated processes can share a queue. I think this plan rules out pthreads. The named posix semaphores are great for putting something in the filesystem that any process can see, but I can't find the standard CondWait primitive: ... decide we have to wait .... CondWait(sem, cond); When CondWait is called by a

Applescript: Get absolute path of item in a File > Open window

。_饼干妹妹 提交于 2019-12-23 05:09:05
问题 I'm trying to automate JPEGmini which is not entirely scriptable - the only way to control it is via the "Open" dialog. Repeatedly calling it once per image is extremely slow. Instead I'm trying to to perform a search for .jpg or .jpeg files in the "Open" dialog, so that within that result set I can select the batch of files I want to process and open them in a single pass. (More detail after the code example) -- later within the search results list I get, I want to select these set

Prevent control-c from sending SIGINT to all process group children

余生长醉 提交于 2019-12-23 04:54:14
问题 I'm trying to interface with a really crappy, completely opaque API that creates two subprocesses within a POSIX-like environment (OS X/Linux) in C. Basically, it starts an external program and provides rudimentary support for passing messages back and forth. The process tree looks something like this: + My_program \ + an initiation shell script (csh -f -c external_program_startup_script) \ - the external program instance When I press control-c in the terminal while My_program is running, the

Prevent control-c from sending SIGINT to all process group children

房东的猫 提交于 2019-12-23 04:54:08
问题 I'm trying to interface with a really crappy, completely opaque API that creates two subprocesses within a POSIX-like environment (OS X/Linux) in C. Basically, it starts an external program and provides rudimentary support for passing messages back and forth. The process tree looks something like this: + My_program \ + an initiation shell script (csh -f -c external_program_startup_script) \ - the external program instance When I press control-c in the terminal while My_program is running, the

fibonacci sequence using shared memory in C

江枫思渺然 提交于 2019-12-23 04:47:24
问题 I got a question to solve but it is giving me errors: 2009-EE-182-Part2.c: In function ‘main’: 2009-EE-182-Part2.c:35:13: error: expected identifier or ‘(’ before ‘->’ token 2009-EE-182-Part2.c:40:22: error: expected identifier or ‘(’ before ‘->’ token 2009-EE-182-Part2.c:41:14: error: expected identifier or ‘(’ before ‘->’ token 2009-EE-182-Part2.c:42:22: error: expected expression before ‘shared_data’ 2009-EE-182-Part2.c:44:15: error: expected identifier or ‘(’ before ‘->’ token 2009-EE-182

Making existing ANSI C code threadsafe and re-entrant

人走茶凉 提交于 2019-12-23 03:23:44
问题 I am working on an old legacy ANSI C system, which is littered with a lot of global variables. I am part of a team refactoring the existing codebase, to make the code re-entrant and threadsafe. I found useful material on writing thread safe and re-entrant ANSI C code here. Based on my (admittedly non-perfect) understanding, I have come up with a proposal on how to proceed - but I have already come up with some issues that need addressing, and decided it best to come in here to find out the

Output from fork() in c

我们两清 提交于 2019-12-23 01:02:07
问题 I recently ran into this piece of code, and don't fully understand it. What circumstances would cause pid == 0? Why does wait(NULL) cause the program to go into the if(pid == 0) Basically I don't fully understand the output below. Any help would be appreciated. Thank you. Code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> // standard POSIX header file #include <sys/wait.h> // POSIX header file for 'wait' function int main(void) { int i = -1; int pid; pid = getpid(); fprintf

How to limit the execution time of a function in C/POSIX?

喜欢而已 提交于 2019-12-22 19:30:22
问题 Similar to this question, I'd like to limit the execution time of a function--preferably with microsecond accuracy--in C. I imagine that C++ exceptions could be used to achieve a result similar to this Python solution. Though it's not ideal, such an approach is wholly unavailable in plain C. I wonder, then, how might I interrupt the execution of a function after a certain time interval in C on a Posix system? For relatively simple situations a bit of silly business works just fine, but that