The application layer can obtain the information in the kernel through ioctl,
In fact, you can also write data to a file at the kernel layer, and parse the file at the application layer
The way to parse strings in C language is as follows:
https://www.cnblogs.com/yi-meng/p/3620244.html
The way to parse the file is as follows:
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;
}