Is there a way to run any function of the exec family as a stream in c

I think the question requires no explanation.

I know that exec starts in another process, so if I wanted to use a directory, I would do something like this.

int pid;
if((pid = fork()) != -1) {
     if(!pid) {
         execl("/bin/ls", "-a", "-l", (char *) 0);
     } else {
         wait(&status);
     }
} else //error

This is great if you want to create a process, but what about threads ?. Although I’m going to create a stream and then an exec function, it will make the stream I just created has two processes

+3
source share
3 answers

. , ( ); , , .

+6

, exec , . , , , " ".

+4

. , , , . , , .

, POSIX, , .

, , . , , exec, . ( ), ls ( ) .


:

... because my main process has a lot of variables and stuff and I didn't want to duplicate that memory space because of the fork.

fork, , .

Linux, , . , .

, Linux vfork, , , , exec, ( _exit), , , .

+3

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


All Articles