17 Star 28 Fork 9

枫言风语 / coolwrite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
collect_sound.c 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include"sound.h"
#include<stdio.h>
#include<sys/shm.h>
#include<time.h>
#include<signal.h>
#define TIME_MEM_KEY 99
#define SEG_SIZE ((size_t) 10)
#define oops(m,x) {perror(m); exit(x);}
int seg_id;
int main(int argc,char **argv)
{
int rem_1 = 0;
int rem_2 = 0;
int rem_3 = 0;
int flag = 0;
int *mem_ptr;
void close_shm();
signal( SIGINT, (void*) close_shm); //׽ctrl+c ź
seg_id = shmget(TIME_MEM_KEY, SEG_SIZE, IPC_CREAT|0777);
if ( seg_id == -1)
oops("shmget", 1);
mem_ptr = shmat( seg_id, NULL, 0);
if( mem_ptr == (void *) -1)
oops("shmat", 2);
while(1)
{
rem_1 = rem_2;
rem_2 = rem_3;
rem_3 = sound();
if( rem_1 + rem_2 + rem_3 > 2)
flag = 1;
if( rem_1 + rem_2 + rem_3 < 2)
flag = 0;
//printf("%d\n", flag);
//strcpy(mem_ptr, flag);
*mem_ptr = flag;
printf("%d\n", *mem_ptr);
}
shmctl( seg_id, IPC_RMID, NULL);
return flag;
}
void close_shm()
{
shmctl( seg_id, IPC_RMID, NULL);
exit(0);
}
C
1
https://gitee.com/fenglinwansu/coolwrite.git
git@gitee.com:fenglinwansu/coolwrite.git
fenglinwansu
coolwrite
coolwrite
master

搜索帮助