The last article talked about how to develop and test a simple module directly under ubuntu, how to use c to operate the module?
Use visual studio 2019 for Linux system programming
First open:
Modify and install Linux tools:
Create a new Linux project, remotely connect to the Linux server, configure the compiler:
Project property configuration:
Ubuntu system installation tools:
The target Linux system must install openssh-server, g++, gdb and make. Only CMake projects require ninja-build.
sudo apt-get install openssh-server g++ gdb make ninja-build rsync zip
Start ssh:
sudo service ssh start
Module loading location: /sys/module
Test: Remember to hit the breakpoint (otherwise you can not adjust)
test program:
#include <unistd.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
int fd = 0;
char* hello_node = "/sys/module/day";
/*O_RDWR只读打开,O_NDELAY非阻塞方式*/
if ((fd = open(hello_node, O_RDONLY)) < 0) {
printf("APP open failed %d\n", fd);
}
else {
printf("APP open success\n");
}
close(fd);
return 0;
}