简体   繁体   中英

C program exits on executing execlp function

I know that execlp replaces the current process.I am trying to run

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

Is there any way i can keep the program running while execlp executes?

You fork a new process, and do the exec call in the child process:

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... */
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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