애플리케이션 계층은 ioctl을 통해 커널의 정보를 얻을 수 있습니다.
실제로 커널 계층에서 파일에 데이터를 쓰고 응용 프로그램 계층에서 파일을 구문 분석 할 수도 있습니다.
C 언어로 문자열을 구문 분석하는 방법은 다음과 같습니다.
https://www.cnblogs.com/yi-meng/p/3620244.html
파일을 구문 분석하는 방법은 다음과 같습니다.
static int g_pcie_ep_fd = -1;
int BrdGetEPStatus(int *status)
{
int fd;
int ret = -1;
char *tmp;
int len;
char *line;
char *saveptr = NULL;
char *key;
char *value;
tmp = (char *)malloc(1024);
if (tmp == NULL)
return ret;
if (g_pcie_ep_fd >= 0)
goto go_on;
fd = open("/proc/pcie_ep", O_RDONLY);
if (fd < 0)
{
perror("open");
return fd;
}
g_pcie_ep_fd = fd;
go_on:
memset(tmp, 0x0, 1024);
len = read(g_pcie_ep_fd, tmp, 1024);
printf("BrdGetEPStatus: %s\n", tmp);
line = strtok_r(tmp, "\n", &saveptr);
while (line != NULL) {
/* line: "KEY=value" */
key = line;
value = strchr(line, '=');
if (!value) {
goto next_line;
}
*value = '\0';
value++;
if (strcmp(key, "devCount") == 0) {
sscanf(value, "%d", status);
printf("strcmp(key, devCount: %d\n", *status);
}
next_line:
line = strtok_r(NULL, "\n", &saveptr);
}
free(tmp);
return 0;
}