posix

How to use popen?

你。 提交于 2019-12-24 07:29:16
问题 I'm trying to do inter process communication with stdin and stdout . The Posix function I found is popen , but I failed to write a working sample code. Please help me get this work. <edit1> Do I have to use dup ? I can see some examples found with Google using it. But the Linux manual of dup really does not help me understanding how to use that. </edit1> a.c #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void){ char *s; for(;;){ scanf("%ms",&s); printf("%s\n",s); if(

POSIX path in applescript from list not opening. Raw path works

倾然丶 夕夏残阳落幕 提交于 2019-12-24 06:57:05
问题 I'm really confused with this one. All I want is the files in the list to open. Here's my codes set FilesList to {"Users/XXXXXX/Documents/07PictureArt-Related/THINGS THAT HELP/Tutorials/artNotesfromFeng.rtf", "Users/XXXXXXXX/Documents/07PictureArt-Related/THINGS THAT HELP"} repeat with theFiles in FilesList delay 0.1 tell application "Finder" to open POSIX file (theFiles) end repeat So, how come THAT won't work, but this will??? tell application "Finder" to open POSIX file "Users/XXXXXX

Are BSD/Posix sockets reentrant?

痴心易碎 提交于 2019-12-24 06:23:31
问题 Can several threads operate on the same socket descriptor, i.e accept(sock_fd) at the same time without concern? The platform I'm mostly interested in is POSIX/Linux. 回答1: Yes, they are "reentrant" - kernel locks the socket structure while working on it (see Linux accept source for example), so only one thread would get the client connection. 来源: https://stackoverflow.com/questions/2133224/are-bsd-posix-sockets-reentrant

getaddrinfo: in what way is AI_PASSIVE ignored if the nodename is specified?

时光怂恿深爱的人放手 提交于 2019-12-24 05:21:48
问题 Quoting from the specs of getaddrinfo: If the AI_PASSIVE flag is specified, the returned address information shall be suitable for use in binding a socket for accepting incoming connections for the specified service. In this case, if the nodename argument is null, then the IP address portion of the socket address structure shall be set to INADDR_ANY for an IPv4 address or IN6ADDR_ANY_INIT for an IPv6 address. This makes sense. If you specify AI_PASSIVE , you can bind() / listen() / accept()

sem_wait not working in basic code

风格不统一 提交于 2019-12-24 04:13:30
问题 Compiled with gcc. I ran this to see why the semaphores I was using in my other programs were not working correctly. Am I just using these them incorrectly or what? The string is outputted every time even though the semaphore should halt execution and cause a deadlock, right? Here is the code: #include <pthread.h> #include <semaphore.h> #include <stdlib.h> #define NUM_THREADS 5 void printHello(); int main(){ int i; pthread_t threads[NUM_THREADS]; sem_t sem1; sem_init(&sem1, 0, 0); sem_wait(

Create independent process in Linux

自作多情 提交于 2019-12-24 03:46:09
问题 I'm looking to implement a function similar to CreateProcess but on Linux. I did a lot of research and found the "Fork off and die" approach which uses a double fork to run the child under init. That is, allow the child to operate independent of the parent. Because the parent needs to return information about the newly created child process (i.e. pid, name, etc.) I need to know if I'm running into a race condition in my code. Currently, I fork and retrieve the second fork's pid via pipes then

Does `recv` work with bytes or octets, or are they one and the same in the context of POSIX documentation?

半腔热情 提交于 2019-12-24 03:09:38
问题 Reading the POSIX reference for socket send at http://pubs.opengroup.org/onlinepubs/009695399/functions/send.html I wonder, what exactly do they mean by "byte" - its traditional/historical meaning, its implied/popular meaning, or something else entirely? I am developing a binary TCP/IP-supported network protocol client-server program, and I would like to properly declare my buffer that I use to pass to recv , and being able to properly unpack its data. Yes, I know it's almost hypothetical

Why POSIX allows seeking beyond the existing end of file (fseek) for read only mode

让人想犯罪 __ 提交于 2019-12-24 01:42:47
问题 Why seek over end of file can be usefull? Why POSIX let to seek like in example in file opened for read only? c++: http://en.cppreference.com/w/c/io/fseek posix: https://www.unix.com/man-page/posix/3P/fseek/ Next code I test on MinGW-64w #include <cassert> #include <cstdio> #include <cstring> int main() { std::FILE* f = std::fopen("tmp_file.txt", "wb"); auto result = std::fwrite("1", 1, 1, f); assert(result == 1); result = std::fclose(f); assert(result == 0); f = std::fopen("tmp_file.txt",

How to store keys of associative array in C implemented via hcreate/hsearch by value (not by reference)?

◇◆丶佛笑我妖孽 提交于 2019-12-24 01:15:47
问题 Using associative arrays implented via the POSIX hcreate / hsearch functions (as described here, I struggled some unexpected behaviour finding keys I've never entered or the other way around. I tracked it down to some instance of store-by-reference-instead-of-value. This was surprising to me, since in the example uses string literals as keys: store("red", 0xff0000); store("orange", 0x123456); /* Insert wrong value! */ store("green", 0x008000); store("blue", 0x0000ff); store("white", 0xffffff)

Parent doesn't wait for child processes to finish despite reaping

﹥>﹥吖頭↗ 提交于 2019-12-24 00:52:10
问题 I am fully aware that there are tonnes of articles explaining the inner workings of parent-child process dynamics. I have gone through them and got my stuff working as I want it to function, almost. But there is one thing which is bugging me out and I am not able to understand it despite multiple tries. Problem: Despite reaping the children, main is not waiting for all children to finish and exits prematurely. I believe I did make a proper exit from the child process and I have installed the