简体   繁体   English

C程序退出执行execlp函数

[英]C program exits on executing execlp function

I know that execlp replaces the current process.I am trying to run 我知道execlp取代了当前的进程。我正在尝试运行

execlp("mpg123", "mpg123", "-q", "1.mp3", 0);

Is there any way i can keep the program running while execlp executes? 有没有办法在execlp执行时保持程序运行?

You fork a new process, and do the exec call in the child process: fork一个新进程,并在子进程中exec调用:

pid_t child_pid = fork();
if (child_pid == -1)
    perror("fork");
else if (child_pid == 0)
{
    /* In child process, call `exec*` */
}
else
{
    /* In parent process, continue doing... things... */
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM