posix

Detect if X is running and if it's usable for application

Hi all, On a POSIX-compliant system, how do one detect if X is running and if it's usable for the application. ...

implementing ioctl() commands in FreeBSD

I am adding some code to an existing FreeBSD device driver and I am trying to pass a char* from user space to the driver. I've implemented a custom ioctl() command using the _IOW macro like so: #define TIBLOOMFILTER _IOW(0,253,char*) My call looks something like this: int file_desc = open("/dev/ti0", O_RDWR); ioctl(file_desc, TIBLOOMF...

are posix pipes lightweight?

In a linux application I'm using pipes to pass information between threads. The idea behind using pipes is that I can wait for multiple pipes at once using poll(2). That works well in practice, and my threads are sleeping most of the time. They only wake up if there is something to do. In user-space the pipes look just like two file-h...

Regex for mysql query to match html entities.

I understand PCRE pretty well, but MySQL's regular expression flavor seems to get the best of me. Can someone help me correct this expression? The PCRE equivalent would be &\w+; I'm guessing something like: select body from email where body rlike '&[[:alpha:]]+;%' Bonus: MySQL's docs on their regex flavor seem kinda sparse. Does any...

C++ wrapper for posix and linux specific functions

Hi Do you know about any good library wrapping posix and linux functions and structures ( eg. sockets or file descriptors ) into C++ classes? For example I'm thinking about a base FileDescriptor class and some inheriting classes ( unix sockets etc ) with methods like write, read or even some syscalls ( sendfile, splice ) - all throwing ...

replace file with hardlink to another file atomically

I have two directory entries, a and b. Before, a and b point to different inodes. Afterwards, I want b to point to the same inode as a does. I want this to be safe - by which I mean if I fail somewhere, b either points to its original inode or the a inode. most especially I don't want to end up with b disappearing. mv is atomic when ove...

Detecting Requests Using Posix Semaphores

You know we can use message queues with the function mq_receive(); what is a good way to implement that functionality (you know, waiting until the shared data is changed) with semaphores? ...

Can I use POSIX signals in my Perl program to create event-driven programming?

Is there any POSIX signals that I could utilize in my Perl program to create event-driven programming? Currently, I have multi-process program that is able to cross communicate but my parent thread is only able to listen to listen at one child at a time. foreach (@proc) { sysread(${$_}{'read'}, my $line, 100); #problem here chomp($l...

C: lseek() related question.

I want to write some bogus text in a file ("helloworld" text in a file called helloworld), but not starting from the beginning. I was thinking to lseek() function. If I use the following code (edited): #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <stdlib.h> #include <stdio.h> #define fna...

How do you capture a group with regex?

Hi, I'm trying to extract a string from another using regex. I'm using the POSIX regex functions (regcomp, regexec ...), and I fail at capturing a group ... For instance, let the pattern be something as simple as "MAIL FROM:<(.*)>" (with REG_EXTENDED cflags) I want to capture everything between '<' and '>' My problem is that regmatch...

How do I synchronize access to shared memory in LynxOS/POSIX?

I am implementing two processes on a LynxOS SE (POSIX conformant) system that will communicate via shared memory. One process will act as a "producer" and the other a "consumer". In a multi-threaded system my approach to this would be to use a mutex and condvar (condition variable) pair, with the consumer waiting on the condvar (with pt...

Daemonize() issues on Debian

Hi, I'm currently writing a multi-process client and a multi-treaded server for some project i have. The server is a Daemon. In order to accomplish that, i'm using the following daemonize() code: static void daemonize(void) { pid_t pid, sid; /* already a daemon */ if ( getppid() == 1 ) return; /* Fork off the parent process */ p...

Which POSIX flavor of regex does Perl use?

Specifically, I'm using the Linux command: $ find . -regextype posix-extended -regex '<some regex>' ... I just want to make sure the POSIX type I'm using is the type Perl uses, since that is by far the one I am most familiar with. ...

Is there a c++ library that provides functionality to execute an external program and read its output?

Basically, I'm looking for something that will allow me to replicate the following Perl code: my $fh = new FileHandle; $fh->open("foo |"); while (<$fh>) { # Do something with this line of data. } This is in the context of Linux, so a library that is specific to Windows will not help. I know how to write a program that does fork/e...

Thread scheduling Round Robin / scheduling dispatch

#include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <semaphore.h> #define NUM_THREADS 4 #define COUNT_LIMIT 13 int done = 0; int count = 0; int quantum = 2; int thread_ids[4] = {0,1,2,3}; int thread_runtime[4] = {0,5,4,7}; pthread_mutex_t count_mutex; pthread_cond_t count_threshold_cv; void * inc_c...

Multi-Thread Programming

Is there a function call that can associate with a specific thread to make the thread run or wait? I have 4 threads in my program and I am trying to figure out a way to tell any one of the threads to wait or run when I want them to. ...

Suggestions for duplicate file finder algorithm (using C)

Hello, I wanted to write a program that test if two files are duplicates (have exactly the same content). First I test if the files have the same sizes, and if they have i start to compare their contents. My first idea, was to "split" the files into fixed size blocks, then start a thread for every block, fseek to startup character of ev...

Mac OS X 10.5+ and POSIX

Hello, I need to program an authentication module that has to work with Mac OS X 10.6 Snow Leopard and at the same time needs to be POSIX-compliant. I read here: developer.apple.com/leopard/overview/osfoundations.html that since Mac OS X 10.5 Leopard, Mac OS X is POSIX-compliant (to POSIX 1003.1), but working under MAC OS X 10.5 Leopa...

Help with implementing signal handlers via signal()

void main () { int c; signal (SIGINT, Handle); while (( c = getchar()) != '\n' ); return(); } void Handle(signum) { signal {SIGINT, Handle); printf ("beep \n"); } I thought it would print 'beep' until any key has been pressed but the method call is outside the loop? :S ...

How to signal a buffer full state between posix threads

Hi I have two threads, the main thread 'A' is responsible for message handling between a number of processes. When thread A gets a buffer full message, it should inform thread B and pass a pointer to the buffer which thread B will then process. When thread B has finished it should inform thread A that it has finished. How do I go abo...