posix

How to check if a process with a pid X is a zombie?

I got the PID of a process and I need to check if it is a zombie using POSIX system calls in C. How should I do that? The problem I'm having is that I have a process and it forks into many children, the children all do execs and sometimes I want to do the exec in background so I can't really wait() the children that go in background. I ...

List regular files only (without directory) problem

Hello, Do you know why a lot of file are not listed by this program, even if they are "regular"? #include <stdio.h> #include <sys/types.h> #include <sys/param.h> #include <sys/stat.h> #include <dirent.h> int main(void) { DIR *dh = opendir("./"); // directory handle struct dirent *file; // a 'directory entity' AKA file struct...

listing shared memory objects on Solaris by name

I can use ipcs(1) to list out the active shared memory objects on a Solaris 10 box, but it lists them by key. I'm opening the objects via shm_open(3), though, which takes a character string as a name to identify the object. Is there a way to list the shared memory objects by name, or to just get the key<->name mapping? I'm mostly inte...

How can I catch a ctrl-c event? (C++)

How do I catch a ctrl-c event in C++? ...

What non-Linux unixes support openat()?

openat() was added to POSIX in the POSIX.1-2008 revision, and has been supported by Linux since 2.6.16. How is support on non-Linux UNIXes? eg, Darwin, the *BSDs, and proprietary UNIXes. ...

Posix threads problem

Hello, I am trying to understand pthreads by example. I have made the following code that is giving different answers everytime I run! Could anyone explain the bug please? TIA, Sviiya The code is here: #include <pthread.h> #include <stdio.h> #include <stdlib.h> #define NUM_THREADS 4 struct thread_data { int thread_id; ...

malloc results in segmentation fault after mprotect

I'm getting a segmentation fault the first time I call malloc() after I protect a memory region with mprotect(). This is a code sniplet that does the memory allocation the the protection: #define PAGESIZE 4096 void* paalloc(int size){ // Allocates and aligns memory int type_size = sizeof(double); void* p; p = ...

how to increase the priority of a child pthread relative to the parent thread

My application creates a helper pthread that I need to have run at a higher priority than the main thread. I tried to set the priority of the created thread like this: struct sched_param param; pthread_attr_t tattr; pthread_attr_init(&tattr); pthread_attr_getschedparam(&tattr, &param); param.sched_priority = sched_get_priority_max(SCHE...

Kernel threads and POSIX library

How does one create a Kernel Thread using Posix library? ...

Shared POSIX objects cleanup on process end / death.

Hi, Is there any way to perform POSIX shared synchronization objects cleanup especially on process crash? Locked POSIX semaphores unblock is most desired thing but automatically 'collected' queues / shared memory region would be nice too. Another thing to keep eye on is we can't in general use signal handlers because of SIGKILL which ca...

c library function to get number of active threads

Hi everybody, I'm developing a multi threaded Unix application in C. Is there a simple way to get the count of the number of simultaneously active threads? I don't want to have to write the code to keep track of the number of active thread if it already can be done for me by the library! :-) I'm using POSIX pthreads, and I'm trying to ...

How can I get a human-readable description from a signal number?

Does the POSIX standard or another C standard provide a way to recover a meaningful message from a signal number, in the same way that strerror() makes it possible to recover a message from errno? The Gnu C library has strsignal(), but if possible, I would like something portable to BSD and other Unix variants. ...

PHP - Killing child process started by pcntl_fork

I am using pcntl_fork to start a child process to send an email via SMTP. The child process uses the PEAR Mail package to send the email, but the trouble is if the remote server doesn't respond the process just runs forever waiting for a response, regardless of any time limit that is set in php.ini. To get around this I'm using pcntl_a...

thread termination issue (c programming)

I'm working on an application for Linux in C which uses multiple threads. The threads which are spawned by the main function do most of the work, and therefore usually finish last. I'm seeing some strange behavior, and I believe it's due to the main thread terminating before the spawned threads have a chance to finish their jobs. Here's ...

passing a pointer to a structure as an argument to a thread cancellation cleanup handler

I'm having trouble passing a pointer to a structure as an argument to a thread cancellation cleanup handler. Here's some sample code that blows up when it hits the compiler. Any idea what I'm doing wrong? #include <pthread.h> typedef struct struct_def { /* data */ } struct_def; struct_def *ptr_to_struct_def; void * thread_functi...

How to set the terminal's size?

How do I get the terminal size in Go. In C it would look like this: struct ttysize ts; ioctl(0, TIOCGWINSZ, &ts); But how to i access TIOCGWINSZ in Go ...

Read a file into dynamic memory array using malloc and POSIX file operations

Possible Duplicate: reading a text file into an array in c Hi, I'm trying to read a file into a dynamic array. Firstly I open the file using open() so I get the file descriptor But then I don't know how can I allocate the memory using malloc to a dynamic array in order to do some data modification in the file from memory. Than...

Pthreads question

How to check if a thread is terminated? In my case, I have my_pthread[5] and I want to check if any in 5 threads has finished its job (terminated???I'm not sure) then I can give them another work to do. If I use pthread_join(), then it has to be pthread_join(my_pthread[0]); ... pthread_join(my_pthread[4]); What if thread[3] finishes...

I never really understood: what is POSIX?

What is POSIX? I read the Wikipedia article and I read it ever time I encounter the term. Fact is that I never really understood what it is. Can anyone please explain it to me by explaining "the need for POSIX" too? ...

Zero Window when sending files through posix sockets

Hi I have a problem - when I'm trying to send huge amounts of data through posix sockets ( doesn't matter if it's files or some data ) at some point I don't receive what I expect - I used wireshark to determine what's causing errors, and I found out, that exactly at the point my app breaks there are packets marked red saying "zero windo...