posix

Troubles with POSIX program using threads with gcc

ⅰ亾dé卋堺 提交于 2019-12-13 07:07:35
问题 I must do a program with POSIX threads with gcc and when i try to compile it, the terminal show a message like: /tmp/ccw594wa.o: In function main': POSIX.c:(.text+0xda): undefined reference to pthread_create' POSIX.c:(.text+0x102): undefined reference to `pthread_create' collect2: ld devolvió el estado de salida 1 can someone help me to identify the error cause??, the program has to implemente the producer-consumer algorithm to do some task, my code (unfinished) is the next one #include

Traversing through Directories in C

橙三吉。 提交于 2019-12-13 05:42:54
问题 I am trying to traverse through a directory whose path is given but the following program is not going inside the directories and is stuck in infinit loop. What is the problem in this code: void func(char path[]); int main(int argc, char *argv) { char buf[255]; getcwd(buf,255); func(buf); } void func(char path[]) { DIR *dirp; struct stat states; struct dirent *direntp; dirp=opendir(path); chdir(path); while((direntp=readdir(dirp))!=NULL) { if(S_ISDIR(states.st_mode))//true than returns zero {

Can setting a timeout for posix recv cause lost udp packets?

a 夏天 提交于 2019-12-13 05:26:35
问题 I found this answer on how to set a timeout for posix socket. The linux part of that answer: // LINUX struct timeval tv; tv.tv_sec = timeout_in_seconds; tv.tv_usec = 0; setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv); and the quote from the posix documentation: SO_RCVTIMEO Sets the timeout value that specifies the maximum amount of time an input function waits until it completes. It accepts a timeval structure with the number of seconds and microseconds specifying the

Block Socket with Unix and C/C++ Help

痴心易碎 提交于 2019-12-13 03:34:46
问题 I'm trying to figure out what is blocking my program. I'm running a server that uses POSIX threads. I have to for my computer programming lab. The main function listens for new connections. Once it accepts a connection, it creates a new thread by passing the FD to the thread. I'm able to successfully connect to the server using multiple telnet/client connections. I can send data to the server successfully once, but if I try sending again the server won't do anything. Part of the main function

C - select() on stdin when there is already data in stdin's buffer

时光总嘲笑我的痴心妄想 提交于 2019-12-13 02:44:10
问题 The select function blocks the calling process until there is activity on any of the specified sets of file descriptors [...] A file descriptor is considered ready for reading if a read call will not block. (See: https://www.gnu.org/software/libc/manual/html_node/Waiting-for-I_002fO.html) So I expected, that select in the following program would immediately return in the 2nd, ... iteration, if you enter a string > 4 characters in the first iteration. However it does not. Just after pressing

Understanding the fork() command Posix API

佐手、 提交于 2019-12-13 02:21:48
问题 #include<iostream> #include<unistd.h> #include<stdio.h> using namespace std; int main() { fork(); fork(); fork(); fork(); printf("*"); /*This prints 16 stars*/ return 0; } When working with fork() , why does it print 16 *'s? I understand that fork() generates a new child process that both execute the same process which would explain why one fork generates 2 stars but, with four forks it prints 16 which I can see that it doubles with each fork() . But I am not understanding why. Is each fork

Xenomai clock_nanosleep in POSIX skin jumps to Linux Kernel

自作多情 提交于 2019-12-13 01:26:34
问题 I'm testing POSIX skin in Xenomai. I'm trying to read and write from some GPIOs on a Raspberry Pi, and when I execute the program, there is an increasing number of context switching (in /proc/xenomai/stat/). The main of the program maps the GPIOs to memory and starts the pthreads. The pthread that makes trouble is this: void *productive_thread(void *arg) { struct timespec delay, sleep; unsigned long over; delay.tv_sec = 0; delay.tv_nsec = 10000; // 10 usec sleep.tv_sec = 0; sleep.tv_nsec = *

Do I have to use a signal handler for a Posix timer?

人盡茶涼 提交于 2019-12-12 15:31:58
问题 I want to start a timer and have a function called when it expires. Googling finds lots of examples, including the example in the manual, all of which use sigaction() to set a signal handler. However, @Patryk says in this question that we can just void cbf(union sigval); struct sigevent sev; timer_t timer; sev.sigev_notify = SIGEV_THREAD; sev.sigev_notify_function = cbf; //this function will be called when timer expires sev.sigev_value.sival_ptr = (void*) arg;//this argument will be passed to

unknown type name 'clockid_t'

百般思念 提交于 2019-12-12 14:27:43
问题 I am trying to use C code written on a Linux platform on Mac OS X. I am running into an error related to timers: ../src/stinger/timer.c:61:1: error: unknown type name 'clockid_t' ../src/stinger/timer.c:74:2: error: #error "Cannot find a clock!" which points to this section of code. static clockid_t clockid; #if defined(CLOCK_REALTIME_ID) #define CLKID CLOCK_REALTIME_ID #define CLKIDNAME "CLOCK_REALTIME_ID" #elif defined(CLOCK_THREAD_CPUTIME_ID) #define CLKID CLOCK_THREAD_CPUTIME_ID #define

What can cause close(2) to fail with EIO for a read-only file?

女生的网名这么多〃 提交于 2019-12-12 14:24:21
问题 I'm investigating a problem on Android where an IOException is getting thrown because of a failure to close a file: java.io.IOException: close failed: EIO (I/O error) at libcore.io.IoUtils.close(IoUtils.java:41) at java.io.FileInputStream.close(FileInputStream.java:121) at com.adamrosenfield.wordswithcrosses.io.JPZIO.convertJPZPuzzle(JPZIO.java:191) at com.adamrosenfield.wordswithcrosses.net.AbstractJPZDownloader.download(AbstractJPZDownloader.java:56) at com.adamrosenfield.wordswithcrosses