佚名通过本文主要向大家介绍了arecord,linux arecord,arecord什么意思,alsa arecord,ubuntu下安装qt等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题:ubuntu下的QT结束arecord进程的问题
描述:
以下是源码:
1、获取进程号的函数:
int find_pid_by_name( char* ProcName, int* foundpid)
{
DIR *dir;
struct dirent *d;
int pid, i;
char *s;
int pnlen;
i = 0;
foundpid[0] = 0;
pnlen = strlen(ProcName);
/* Open the /proc directory. */
dir = opendir("/proc");
if (!dir)
{
printf("cannot open /proc");
return -1;
}
/* Walk through the directory. */
while ((d = readdir(dir)) != NULL) {
char exe [PATH_MAX+1];
char path[PATH_MAX+1];
int len;
int namelen;
/* See if this is a process */
if ((pid = atoi(d->d_name)) == 0) continue;
snprintf(exe, sizeof(exe), "/proc/%s/exe", d->d_name);
if ((len = readlink(exe, path, PATH_MAX)) < 0)
continue;
path[len] = '\0';
/* Find ProcName */
s = strrchr(path, '/');
if(s == NULL) continue;
s++;
/* we don't need small name len */
namelen = strlen(s);
if(namelen < pnlen) continue;
if(!strncmp(ProcName, s, pnlen)) {
/* to avoid subname like search proc tao but proc taolinke matched */
if(s[pnlen] == ' ' || s[pnlen] == '\0') {
foundpid[i] = pid;
i++;
}
}
}
foundpid[i] = 0;
closedir(dir);
return 0;
}
2、开启录音和关闭录音的函数: 录音功能可以正常开启,但是结束进程的时候出bug,获取不到进程号= =
case 3:
if(strncmp(argv[0],"90",2)==0 && strncmp(argv[1],"41",2)==0 && strncmp(argv[2],"0",1)==0){
sprintf(tmp_cmd,"arecord -f S16_LE -r 8000 -B -buffer-szie=4096 /mnt/test/test.wav");
//strncpy(tmp_cmd,tmp,sizeof(tmp));
fpid = fork();
log("start arecord...");
if(fpid < 0)
log("error in fork");
 
描述:
ubuntu源码
最近在做一个项目,需要在QT里面实现录音机的功能,录音的功能已经实现了,可以实现,但是结束录音的时候,需要关闭kill录音的进程。因前面实现了aplay播放的功能,已经找到一份获取进程号并且可以正常获取进程号,并成功kill进程。用一样的函数,怎么都获取不到录音的进程,哪位大神能帮忙看看,谢谢!以下是源码:
1、获取进程号的函数:
int find_pid_by_name( char* ProcName, int* foundpid)
{
DIR *dir;
struct dirent *d;
int pid, i;
char *s;
int pnlen;
i = 0;
foundpid[0] = 0;
pnlen = strlen(ProcName);
/* Open the /proc directory. */
dir = opendir("/proc");
if (!dir)
{
printf("cannot open /proc");
return -1;
}
/* Walk through the directory. */
while ((d = readdir(dir)) != NULL) {
char exe [PATH_MAX+1];
char path[PATH_MAX+1];
int len;
int namelen;
/* See if this is a process */
if ((pid = atoi(d->d_name)) == 0) continue;
snprintf(exe, sizeof(exe), "/proc/%s/exe", d->d_name);
if ((len = readlink(exe, path, PATH_MAX)) < 0)
continue;
path[len] = '\0';
/* Find ProcName */
s = strrchr(path, '/');
if(s == NULL) continue;
s++;
/* we don't need small name len */
namelen = strlen(s);
if(namelen < pnlen) continue;
if(!strncmp(ProcName, s, pnlen)) {
/* to avoid subname like search proc tao but proc taolinke matched */
if(s[pnlen] == ' ' || s[pnlen] == '\0') {
foundpid[i] = pid;
i++;
}
}
}
foundpid[i] = 0;
closedir(dir);
return 0;
}
2、开启录音和关闭录音的函数: 录音功能可以正常开启,但是结束进程的时候出bug,获取不到进程号= =

case 3:
if(strncmp(argv[0],"90",2)==0 && strncmp(argv[1],"41",2)==0 && strncmp(argv[2],"0",1)==0){
sprintf(tmp_cmd,"arecord -f S16_LE -r 8000 -B -buffer-szie=4096 /mnt/test/test.wav");
//strncpy(tmp_cmd,tmp,sizeof(tmp));
fpid = fork();
log("start arecord...");
if(fpid < 0)
log("error in fork");