这个程序能同步么

小神流川 2010-09-19 11:17:17
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/kd.h>
main()
{
pid_t pc,pr;
pc=fork();

if(pc<0)
{
printf("erorr ocurred!");
}
else if(!pc)
{
int console_fd;
int i;
int s[]={659,523,578,659,523,523,523,784,698,659,578,659,523,578,659,578,578,578,659,523,578,659,523,523,523,784,698,659,578,659,523,578,659,578,578,578,659,578,578,659,523,523,440,523,523,440,392,659,698,784,784,578,523,659,578,659,578,578,659,523,440,440,523,523,440,392,330,659,698,784,784,578,523,659,578,659,578,659,523,440,440,523,523,440,392,659,698,784,784,578,578,578,659,578,659,578,659,578,523,440,523,523,440,392,330,578,578,784,784,578,578,578,659,578,523,523,523,523,659,784,880,880,880,880,880,880,784,659,578,523,523,523,523,523,523,523,659,784,880,880,880,880,880,880,880,784,659,659,578,659,659,578,523,523,523,578,659,578,523,698,698,659,698,523,659,698,659,578,497,578,578,659,578,497,523,523,523,578,659,578,523,698,698,659,698,523,659,698,659,578,497,578,578,659,578,497,523};
int len[]={250,250,250,125,125,250,125,125,125,125,125,250,250,250,125,125,500,500,250,250,250,125,125,250,125,125,125,125,125,250,250,250,125,125,500,500,250,125,125,250,125,125,250,125,170,170,170,250,125,250,250,250,125,250,250,250,125,125,250,125,125,250,125,125,125,125,125,250,125,250,250,250,125,250,250,250,125,250,125,125,250,125,170,170,170,250,125,250,125,125,250,125,250,250,250,125,250,125,125,250,125,125,125,125,125,250,125,250,125,125,250,125,250,125,125,125,250,125,250,250,500,125,125,250,125,125,250,250,500,250,250,125,125,125,125,125,125,125,125,500,250,250,250,125,125,250,125,125,250,250,125,125,250,125,250,125,125,125,250,125,250,125,250,250,125,250,125,250,250,125,250,125,250,250,250,125,250,125,125,125,250,125,250,125,250,250,125,250,125,250,250,125,250,125,250,250,500};
if((console_fd=open("/dev/console",O_WRONLY))==-1)
{
fprintf(stderr,"Failed to open console.\n");
perror("open");
exit(1);
}
for(i=0;i<194;i++)
{
int magical_fairy_number=1190000/s[i];
ioctl(console_fd,KIOCSOUND,magical_fairy_number);
usleep(1000*len[i]);
ioctl(console_fd,KIOCSOUND,0);
usleep(1000*50);
}
}
else
{
printf("Oh oh oh oh oh oh \n ");
usleep(1000*12000) ;
printf("Give me freedom, give me fire\n");
usleep(1000*4000) ;
printf("give me reason take me higher see the champions take the field now \n");
usleep(1000*4000);
printf("giev me reason take me higher see the champions take the field now\n ");
usleep(1000*4000);
printf("you de-fine us make us feel proud in the streets are\n ");
usleep(1000*3000);
printf("exaliftin as we lose our inhibition \n ");
usleep(1000*1000);
printf("Celebration its around us every nations all around us \n");
usleep(1000*4000);
printf("Singin for-ever young singin songs underneath that sun \n ");
usleep(1000*4000);
printf("Lets re-joice in the beautiful game and to songs underneath that sun\n ");
usleep(1000*4000);
printf("Lets re-joice in the beautiful game and to-gether at the end of the day\n ");
usleep(1000*4000);
printf("we all say wwwhen i get older i will be stronger\n ");
usleep(1000*2000);
printf("They'll call me freedom just like a wavin'flag\n ");
usleep(1000*2000);
printf("when i get older i will be stronger.They'll call me freedom just like a wavin'flag\n");
}
}

这个程序。。能唱一句。。然后放一句歌词么???大家谁能告诉我啊。。。。
...全文
90 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
小神流川 2010-09-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 justkk 的回复:]
歌曲的播放,不懂..
两个进程之间的同步可以考虑采用system v的信号灯,或者posix的信号灯
[/Quote]
恩。。我试试。。谢谢了。。
小神流川 2010-09-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 justkk 的回复:]
没看到你采用了什么同步措施..
[/Quote]
额。。那如何采用你呢??我想编个歌。。编唱几句。。然后显示歌词的。。
该如何编写呢??就拿这个例子。。该怎样修改的啊??
能告诉我不?

justkk 2010-09-19
  • 打赏
  • 举报
回复
歌曲的播放,不懂..
两个进程之间的同步可以考虑采用system v的信号灯,或者posix的信号灯
小神流川 2010-09-19
  • 打赏
  • 举报
回复
额。。那如何采用你呢??我想编个歌。。编唱几句。。然后显示歌词的。。
该如何编写呢??
justkk 2010-09-19
  • 打赏
  • 举报
回复
没看到你采用了什么同步措施..
T-Quake 2010-09-19
  • 打赏
  • 举报
回复
推荐使用信号量System V 中的mutex机制

3,287

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 实用资料发布区
社区管理员
  • 实用资料发布区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧