posix

A question about semaphore.

#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <semaphore.h> void *thread_function(void *arg); sem_t bin_sem; #define WORK_SIZE 1024 char work_area[WORK_SIZE]; int main() { int res; pthread_t a_thread; void *thread_result; res = sem_init(&bin_sem, 0, 0); if...

UDP-Broadcast on all interfaces

On a Linux system with a wired and a wireless interface (e.g. 192.168.1.x and 192.168.2.x subnets) I want to send a UDP broadcast that goes out via ALL available interfaces (i.e. both through the wired and the wireless interface). Currently I sendto() to INADDR_BROADCAST, however it seems that the broadcast only is sent through one of t...

TCP and POSIX sockets accept() semantics

Situation: The server calls accept(). The client sends a SYN to the server. The server gets the SYN, and then sends a SYN/ACK back to the client. However, the client now hangs up / dies, so it never sends an ACK back to the server. What happens? Does accept() return as soon as it receives the SYN, or does block until the client's ACK is...

Is there a way to schedule a cron job that does not run on the 3rd weekend of the month?

Any ideas, anyone? ...

Is Fortran 77 POSIX conformant? - Write binary files

I'm trying to write binary data files from fortran, but I find the regular file interfaces very limiting, I wonder if Fortran has POSIX compilant functions. I found this standard: IEEE 1003.9-1992, but I don't know it if is fully supported by most common compilers (or if I have to activate any flags). I can't find any practical informat...

Linux MMAP internals

I have several questions regarding the mmap implementation in Linux systems which don't seem to be very much documented: When mapping a file to memory using mmap, how would you handle prefetching the data in such file? I.e. what happens when you read data from the mmaped region? Is that data moved to the L1/L2 caches? Is it read direct...

Find out if a command exists on POSIX system

I want to be able to tell if a command exists on any POSIX system from a shell script. On Linux, I can do the following: if which <command>; then ...snip... fi However, Solaris and MacOS which do not give an exit failure code when the command does not exist, they just print an error message to STDOUT. Also, I recently discovered ...

Implementing worker threads (in Linux): How offensive is this?

#include <pthread.h> static void * worker_thread(void *); void some_func(void) { pthread_t * tmp; tmp = malloc(sizeof(pthread_t)); if (NULL != tmp) { if (!pthread_create(tmp, NULL, worker_thread, (void *)tmp)) pthread_detach(*tmp); else free(tmp); } } static void * worker_thre...

socket:client waiting even after recieving last byte

I have client/server program in C, through which I am transferring files to the client from server. But the client is waiting for recv even after receiving the last byte of the file. Client is terminating only if I kill it or server is killed by me. But server has to be in a loop as it to has to entertain the request of other clients. ...

Warning with nftw

Hi, I'm trying to use the nftw to process some files under a directory #include <ftw.h> #include <stdio.h> int wrapper(const char * fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { printf("File %d\n", ftwbuf->base); return(0); } int main(int argc, char ** argv) { const char *name; int flags = 0; n...

RE: Posix and System V IPC

Which IPC among message queues, shared memory and semaphores is easiest to convert to network IPC and which is the hardest. Would it be easier to convert System V shared memory to network IPC or Posix shared memory to network IPC ...

POSIX ACLs and the 'sticky' bit applied to a directory

POSIX.1e was going to define ACL (Access Control List) mechanisms for POSIX (amongst other security-related issues), but the proposals were never converted to a formal standard. Nevertheless, ACLs (not necessarily POSIX.1e ACLs) are supported at least optionally in all the main variants of Unix (Linux, BSD, MacOS X(ACL), HP-UX, AIX (p10...

What's the easiest way to get a user's full name on a Linux/POSIX system?

I could grep through /etc/passwd but that seems onerous. 'finger' isn't installed and I'd like to avoid that dependency. This is for a program so it would be nice if there was some command that let you just access user info. ...

Is there an equivalent to WinAPI's MAX_PATH under linux/unix?

If I want to allocate a char array (in C) that is guaranteed to be large enough to hold any valid absolute path+filename, how big does it need to be. On Win32, there is the MAX_PATH define. What is the equivalent for Unix/linux? ...

Under a debugger

How do I detect in my program that it's being run under a debugger? I am aware that this seems to indicate that I try to do something I shouldn't, and that is too messy. I think it is an interesting question tho. Specifically, is there a way to do it in a POSIX environment? For example using sigaction (2) to detect that some handler ...

Is there a way to flush a POSIX socket?

Is there a standard call for flushing the transmit side of a POSIX socket all the way through to the remote end or does this need to be implemented as part of the user level protocol? I looked around the usual headers but couldn't find anything. ...

whoami in python

Duplicate of: Is there a portable way to get the current username in Python? What is the best way to find out the user that a python process is running under? I could do this: name = os.popen('whoami').read() But that has to start a whole new process. os.environ["USER"] works sometimes, but sometimes that environment variable i...

Does the OS (POSIX) flush a memory-mapped file if the process is SIGKILLed?

If a process is killed with SIGKILL, will the changes it has made to a memory-mapped file be flushed to disk? I assume that if the OS ensures a memory-mapped file is flushed to disk when the process is killed via SIGKILL, then it will also do so with other terminating signals (SIGABRT, SIGSEGV, etc...). ...

C Timer Callback

Interested in something similar to JavaScript setTimeout in C on both UNIX and Windows. Basically, I want: start_timer(&function_pointer, int time_in_secs) or as close to that as I can get. Also, something similar to setInterval would be nice (where it calls the callback every n seconds), but that can be implemented using setTimeout...

Where do you place POSIX semaphores when using POSIX shared memory?

I'm trying to build a client server application using POSIX shared memory and POSIX semaphores. Do I have to place the semaphores inside the shared memory segment or can the semaphores just be global variables? I wish to adhere to POSIX convention. ...