Probably the core of this question has been asked a lot on this site.
I'mm working with pocketsphinx and I'm trying to play music each time I request it.
When I say "MUSIC" the program executes the music, my idea is that when I say "STOP" music should stop. I'm trying to get the PID the following way. I got this idea from this question
I though using popen I will get the PID, but isn't that way when it get to pid_t pid = strtoul(line, NULL, 10); it's returning me 0.
How I can get this PID and continue with the program running at the same time?
I'm using the same template that you will find on the pocketsphinx want to see it with modifications here: http://pastebin.com/Duu2nbCA
if(strcmp(word, "MUSIC") == 0)
{
FILE *fpipe;
char *command = (char *)"aplay BobMarley.wav";
char line[256];
if ( !(fpipe = (FILE*)popen(command,"r")) )
{ // If fpipe is NULL
perror("Problems with pipe");
exit(1);
}
fgets( line, sizeof line, fpipe);
pid_t pid = strtoul(line, NULL, 10);
printf("The id is %d\n", pid);
}