- 論壇徽章:
- 0
|
我用多線程來循環(huán)播放MP3歌曲,(MP3歌曲保存在,pt_SongInfo 隊(duì)列里面)
- 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);
- }
- }
- }
復(fù)制代碼 這個(gè)代碼 我通過
printf("####play function %d##### \n",getpid());
打印測試結(jié)果:
第一次播放
####play function 1315#####
####play function 1314#####
第2收
####play function 1316#####
####play function 1314#####
第3首
####play function 1317#####
####play function 1314#####
我的疑問是:
1、為什么一個(gè)print ,會出現(xiàn) 兩行打印信息?
2、無論循環(huán)多少次 ####play function 1314##### 一定是存在的。(只要不關(guān)閉)
剛剛學(xué) linux 應(yīng)用編程,不是特別明白,再次請教
謝謝 |
|