鸿蒙OS_app

init/src/init.c

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>

int main(int argc, char * const *argv)
{
    
    
    int ret;
    const char *shellPath = "/bin/shell";

    ret = fork();
    if (ret < 0) {
    
    
        printf("Failed to fork for shell\n");
    } else if (ret == 0) {
    
    
        (void)execve(shellPath, NULL, NULL);
        exit(0);
    }

    while (1) {
    
    
        ret = waitpid(-1, 0, WNOHANG);
        if (ret == 0) {
    
    
            sleep(1);
        }
    };
}

代码很简单,知识点execve waitpid

猜你喜欢

转载自blog.csdn.net/liuqingsongmsdn2014/article/details/108549528