其他小笔记
【Linux的usb设备的命名规则】
BUS号/或者叫根HUB号
-HUB接口号
[.HUB接口号
]:USB配置号
.USB接口号
,方括号[]中内容可重复,例如1-2.0.1.2.3.5:1.0
。
【signalfd、timerfd 和 eventfd】
// 可以将信号抽象成文件描述符
#include <sys/signalfd.h>
int signalfd(int fd, const sigset_t *mask, int flags);
// 可以将定时器抽象成文件描述符
#include <sys/timerfd.h>
int timerfd_create(int clockid, int flags);
int timerfd_settime(int fd, int flags, const struct itimerspec *new_value, struct itimerspec *old_value);
int timerfd_gettime(int fd, struct itimerspec *curr_value);
// 可以将用于线程间通信的计数器抽象成文件描述符
#include <sys/eventfd.h>
int eventfd(unsigned int initval, int flags);
// 抽象成文件描述符后就可以使用 select()、poll() 和 epoll() 进行监听。
【C语言变参宏写法举例】
#define LOG(...) printf(__VA_ARGS__) // 该写法等同于printf
#define LOG(...) // 该写法可关闭日志
#define LOG(format, ...) printf("MYLOG" format, ##__VA_ARGS__) // 该写法可以添加前缀"MYLOG"
#define LOG(format, args...) printf("MYLOG" format, ##args) // 这是gcc写法,__VA_ARGS__是C99标准。
【C语言函数数组写法】
static int func0(int a, int b){
return a+b;
}
static int func1(int a, int b){
return a-b;
}
static int func2(int a, int b){
return b-a;
}
static int func3(int a, int b){
return a*b;
}
// 写法1
int (*funcArray[])(int,int) = {func0, func1, func2, func3};
// 写法2
typedef int(FUNC_T)(int,int);
FUNC_T *funcArray[] = {func0, func1, func2, func3};
// 写法3
typedef int(*FUNC_T)(int,int);
FUNC_T funcArray[] = {func0, func1, func2, func3};
【usbip源码地址】
usbip以前是独立项目(http://usbip.sourceforge.net/),从linux-4.0.y开始并入Linux主分支。"uname -r
" 可查看内核版本。
Linux内核官网:https://www.kernel.org/
usbip驱动路径:root/drivers/usb/usbip/
usbip应用路径:root/tools/usb/usbip/
usbip协议路径:root/Documentation/usb/usbip_protocol.txt
【openssl源码地址】
官网:https://www.openssl.org
github:https://github.com/openssl/openssl
【创建守护进程】
创建守护进程有现成的函数
#include <unistd.h>
int daemon(int nochdir, int noclose);
如果nochdir
为零,daemon()将进程的当前工作目录更改为根目录"/"
,否则保持不变。
如果noclose
为零,daemon()将标准输入,标准输出和标准错误重定向到"/dev/null"
,否则保持不变。
如果成功函数返回0,失败返回-1并设置errno。举例:
#include <unistd.h>
int main(int argc, char* argv[]){
if(daemon(0, 0) < 0) return -1;
// 一些代码
// 一些代码
return 0;
}
【设置或获取线程名】
#include <sys/prctl.h>
int prctl(int option, unsigned long arg2, unsigned long arg3,unsigned long arg4, unsigned long arg5);
参数option
是要执行的操作:
PR_SET_NAME
:设置当前线程名,例如prctl(PR_SET_NAME, "name1");
。
PR_GET_NAME
:获取当前线程名,例如prctl(PR_GET_NAME, nameBuffer);
。
【sendfile()】
#include <sys/sendfile.h>
ssize_t senfile(int out_fd, int in_fd, off_t *offset, size_t count);
// 内核版本 2.6.33 之前 out_fd 必须是 socket,2.6.33开始 out_fd 可以是任意类型文件描述符。
// in_fd 不能是 socket。
// offset 指从 in_fd 的 offset 位置开始传送,调用返回后 offset 被更新。
// count 指要传输的字节数
【FreeRDP添加新参数】
- 在
/client/common/cmdline.h
的参数列表args[]
中添加一个新参数成员; - 在
/client/common/cmdline.c
的freerdp_client_settings_parse_command_line_arguments()
中读取这个新的参数的值; - 在
/include/freerdp/settings.h
中定义有struct rdp_settings
结构体,应该在其中添加新成员来储存读取的参数的值。
【notepad++ 添加高亮关键字】
我需要给C语言添加 int8_t
、int16_t
、int32_t
、int64_t
、uint8_t
、uint16_t
、uint32_t
、uint64_t
8个高亮关键字,打开C:\Users\Administrator\AppData\Roaming\Notepad++\langs.xml
,找到C语言部分,如图所示,在<Keywords name="type1">...</Keywords>
中添加即可。

【一些shell命令】
命令 | 解释 |
---|---|
mkfifo | 创建管道文件 |
wc | 统计文件 |
ldd | 查看所依赖的动态库 |
【Linux查看网卡MAC地址】
cat /sys/class/net/<网卡名>/address
【Win7开启RemoteAPP】
先保证开启了远程桌面,然后打开注册表 regedit.exe,修改下列键的值为 1:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\TSAppAllowList\fDisabledAllowList
【dbus用法】
https://blog.csdn.net/eastmoon502136/article/details/10044993