0

First I have used mpg123 remotely using FIFOs to implement Pause functionality, but now I want to close the mpg123 player when file is played through automatically.

The code for playing current is

pid p = fork();  
if (p<0)  
  return;  
else if (p==0)  
  execlp("mpg123", "mpg123", "-R", "--fifo", "aFifo", NULL);  
else  
  system("load test.mp3 > aFifo");

Currently if the file is played through then also child process else if (p==0) will stay there and mpg123 player process will continue to exist

Kalu DADA
  • 53
  • 8

1 Answers1

1

You have no ? in your question, but any way your code looks wrong, because system uses fork and exec under the hood. So instead of one fork and one exec you use fork three times and uses execv twice.

Read how to run process here: how to correctly use fork, exec, wait

after you run process in proper way, you have real pid of mpg123, and so you can kill it if you want, or pause or what else you want.

Community
  • 1
  • 1
fghj
  • 8,898
  • 4
  • 28
  • 56
  • i got ur point and edited the question, i doubt whether similar commands can be used for 2nd command, and my exact question since the mpg123 player is attached to the fifo in child process, now from parents process commands are supplied, so how the status of the player we can get in parent process? – Kalu DADA Dec 30 '15 at 11:43