我想运行两个不同的主进程

问题描述 投票:0回答:1

我想终止第一个进程,然后我想运行第二个进程。我该怎么做?

我想在嵌入式linux中做,我该怎么做?我不知道。任何示例都会有帮助。 第二个进程应该独立运行,第一个和第二个进程之间不应该有任何关系。

c linux multithreading process multiprocess
1个回答
0
投票

您可以使用 fork 创建一个子进程,然后在两个进程中执行操作。您不需要多个进程来处理您可能想要读取线程与多处理的所有内容。这是使用 fork 的场景示例:

#include <stdio.h>
#include <stdlib.h>
int main() {
    if(fork()>0) {
        puts("hello from child process!");
    }
    else {
         puts("hello from parent process!");
    }
}

终结者

© www.soinside.com 2019 - 2024. All rights reserved.