Sudo Reboot
Sudo Reboot

Reputation: 230

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?

Upvotes: 1

Views: 1342

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409166

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

Upvotes: 3

Related Questions