select() function
in socket between server and many clients we need select().i want to know where shoude be the select() function?server or client? if it should be in server so what changes we should make in client ...
in socket between server and many clients we need select().i want to know where shoude be the select() function?server or client? if it should be in server so what changes we should make in client ...
I have been learning thread programming in Java, where there are are sophisticated APIs for thread management. I recently came across this. I am curious to know if these are used now. Is the POSIX thread obsolete or is it the standard used now for threading in C++. I am not familiar with Threading in any other language apart from Java. ...
I have multiple threads, and I want each thread to wait for every others to complete at certain point in the code before proceeding as following: void *run() { for (i=0;i<1000;i++){ do_1st(); // sync() all stop here wait for all then resume do_2nd(); } } I tried to use pthread_cond_wait.. but It seems very complicated...
Hi, Totday, I posted a problem about a segmentation fault after destruction of a std::string (see this post). I've stripped the code so that I don't use the STL and still have a segmentation fault sometimes. The following code works just fine on my PC running Linux. But using the ARM crosscompiler suppplied by the manufactor of our emb...
With reference to the semaphore implementation of semaphore.h in Linux, does an uninitialized semaphore sem_t default to 0? I just discovered that I had forgotten to initialize my semaphores to 0. Even so, the program worked fine without sem_init. (To all the purists, I completely agree that doing so is a bad practice.) ...
Hello all! I'm migrating a multi threaded application from HP-UX to Solaris and so far, everything is OK except for one thing! The application has a thread that is handling the signals and, when some of them are received, it runs some cleaning (logging, kill child processes and so on). I've reduced the code as much as it was possible t...
ATM I do it this way which is far slow and incorrect: for i in `find -type f`; do echo $i`LANG=C hg log -v $i | grep user | tail -1 | awk '{print " "; print $2}'`; done When someone has moved a file to a new name, yes he is the creator of that new file, but not of the code which he moved. I could extract the revision number out of t...
This is my code of function that wants to read file: int sendByByte(int filed,int sockfd,int filesize) { int i=0; int sent=0; char buf[BUFSIZE]; while(i<filesize) { printf("fd is : %d\n",filed); printf("i: %d\n",i); int byte_read=read(filed,buf,BUFSIZE); if(byte_read == -1) { printf("MOSHKEL dar read\n"); return -1;...
Can you help me to understand why it is recommended to use: while ((s = sem_timedwait(&sem, &ts)) == -1 && errno == EINTR) continue; // Restart when interrupted by handler (EINTR: The call was interrupted by a signal handler) Instead of simply: s = sem_timedwait(&sem, &ts); In witch cases I have to manage EINTR ? ...
I'm trying to compile Redis for Windows x64 with no luck. I tried different things Cygwin works perfectly but GCC produces only 32 bit executables Compling with Mingw-w64 will not work without a lot of code changes (My understanding is that MinGw does not provide POSIX compatibility for Windows) Microsoft Services for Unix has an outd...
I'm using socat to create a virtual serial port with: socat PTY,link=/dev/ttySV0,echo=1 PTY,link=/dev/ttySV1,echo=1 The in my program written in C++, I open the ttySV1 port and start to read. The read function is in a while, but the problem is that the read function hangs until I send data to the port. Do you know how to make the tah...
I have a father process and a child process, the second created with fork, the child receive from the father a char s[] (s can be something like "cd Music" ), i extract Music from "cd Music" using strtok, but when chdir(dir) executes i get "No such file or directory". But if i test chdir("Music") i get no error. I want to change the work...
What is the best way in C on Linux for setting up a program that can handle multiple POSIX-signals with the same function? For example in my code I have a handler function that I want to generically call when ever a signal is caught to perform some actions: /* Exit handler function called by sigaction */ void exitHandler( int sig, sigi...
When using a serial port via POSIX, it's recommended to save the original attributes using tcgetattr() before changing them with tcsetattr(), and then restore them before closing the port. What about when a program is terminated by pressing control-C or when the program receives SIGINT? I haven't seen this covered in any of the serial tu...
I'm trying to retrofit an API to be compatible with IPv4. Basically the API at one stage creates a socket and then calls bind() to open a port for listening. The port is specified by passing a sockaddr returned by getaddrinfo(), specifying the port in the service parameter. Later, the caller has the choice of assigning a multicast gro...
I have to do a program where I need to index the files in a specified directory. I've gotten the indexing part down, but what I'm having trouble with is how to navigate to the directory. For example, say when I start the program, it will ask "What directory would you like to index," And then the input would be "usr/Documents/CS/Assignme...
On POSIX systems, termination signals usually have the following order (according to many MAN pages and the POSIX Spec): SIGTERM - politely ask a process to terminate. It shall terminate gracefully, cleaning up all resources (files, sockets, child processes, etc.), deleting temporary files and so on. SIGQUIT - more forceful request. It...
I have just been reading the section on the poll() function in "Advanced Unix Programming" second edition by Marc Rochkind. In this section, the author mentions that poll() is not supported under Darwin 6.6 and I have seen other items on the internet that suggests that poll() is emulated on OSX using the select() system call. I am want...
Hi, I wrote a code in C/C++ which forks a child process, duplicates the stdin/stdout into a pipe ends and calls execvp. Everything is working fine (i.e. the output from stdin/err/out is captured by the parent process) The problem is that the child stdout is buffered. so if the child code looks like this: printf("Enter any key and hi...
As in the title what does EAGAIN mean? ...