./a.out .
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<dirent.h>
#include<string.h>
#include<signal.h>
void music_self(void);
void mysignal(int signo);
pid_t pid;
int k=0;
int len;
char str[32][128];
void music_self(void)
{
signal(SIGINT,mysignal);
pid=fork();
if(pid==-1)
{
perror("fork");
exit(-1);
}
if(pid==0)
{
execl("/usr/bin/madplay","madplay",str[k],NULL);
}
}
void mysignal(int signo)
{
system("kill pid");
printf("hello\n");
k++;
if(k==len)
{
k=0;
}
music_self();
}
int main(int argc,char *argv[])
{
DIR *dir;
struct dirent *ent;
char str1[128];
char str2[128];
memset(str,0,sizeof(str));
dir=opendir(argv[1]);
if(NULL==dir)
{
perror("opendir");
return;
}
while(ent=readdir(dir))
{
if(ent->d_type==4)
{
continue;
}
strcpy(str1,ent->d_name);
strcpy(str2,str1+strlen(str1)-4);
if(strcmp(str2,".mp3")==0)
{
sprintf(str[k],"%s/%s",argv[1],ent->d_name);
printf("%s\n",str[k]);
k++;
}
}
closedir(dir);
len=k;
k=0;
while(1)
{
music_self();
waitpid(pid,NULL,0);
k++;
if(k==len)
{
k=0;
}
}
return 0;
}