Plug () on iPhone

Does the iPhone support SDK fork()and pipe()traditional unix features? I can not get them to work.

Edit

The problem is resolved. Here I offer a solution to anyone who encounters similar problems to me. I was inspired by the answers in this thread.

There is no way to unlock the process on iPhone. However, it is impossible to realize the pipeline. In my project, I create a new POSIX thread (read Apple's documentation on how to do this). The child stream will use the file descriptor created by pipe () with the parent stream. Real and parent streams can communicate through channels. For example, my child stream dup2 () fd [1] before its standard output. Thus, any standard output can be detected in the parent stream. Similar to fd [0] and standard input.

Pseudocode (I do not have the code, but you understand):

int fd[2];
pipe(fd);
create_posix_thread(&myThread, fd);
char buffer[1024];
read(fd[0], buffer, 1024);
printf("%s", buffer); // == "Hello World"    

void myThread(int fd[])
{
  dup2(fd[1], STANDARD_OUTPUT);
  printf("Hello World");
}

The strategy is very convenient if you want to use a third-party library in your iPhone application. However, the problem is that standard debugging using printf () is no longer available. In my project, I just redirected all debugging outputs to a standard error, Xcode will display the outputs to the console.

+3
source share
2 answers

You cannot use fork (), but you can use as many streams as you want, and now you even have a GCD on the iPhone to help maintain the stream in use.

Why do you want fork () instead of just using more threads?

+6

. exec. 1 .

+4

Source: https://habr.com/ru/post/1762673/


All Articles