- 论坛徽章:
- 0
|
我用多线程来循环播放MP3歌曲,(MP3歌曲保存在,pt_SongInfo 队列里面)
- static void Play( pt_SongInfo Head )
- {
- pid_t pid;
-
- pt_SongInfo temp = Head;
- if (!Head)
- {
- printf("The Head list is empty \n");
- exit(0);
- }
-
- temp = temp->prior;
- while (1)
- {
- temp = temp->next;
- pid = fork();
- printf("####play function %d##### \n",getpid());
- if (pid == 0)
- {
- pt_shareInfo shm_info = (pt_shareInfo)shmat(shmid, 0, 0);
- if (shm_info == NULL)
- {
- printf("share memory get address error \n");
- exit(0);
- }
- strcpy(shm_info->name,temp->name);
- shm_info->grandson = getpid();
- execlp("madplay","madplay","-a -50",temp->name,NULL);
- printf("\n@@@@@@@@@@@@@@@@@@@@ NEXT SONG START @@@@@@@@@@@@@@@@@@@@\n");
- }
- else
- {
- wait(NULL);
- }
- }
- }
复制代码 这个代码 我通过
printf("####play function %d##### \n",getpid());
打印测试结果:
第一次播放
####play function 1315#####
####play function 1314#####
第2收
####play function 1316#####
####play function 1314#####
第3首
####play function 1317#####
####play function 1314#####
我的疑问是:
1、为什么一个print ,会出现 两行打印信息?
2、无论循环多少次 ####play function 1314##### 一定是存在的。(只要不关闭)
刚刚学 linux 应用编程,不是特别明白,再次请教
谢谢 |
|