unordred_map<int,bool>[key]未设值前,获取到可能是true。
坑爹啊!!!
unordred_map<int,bool>[key]未设值前,获取到可能是true。
坑爹啊!!!
sscanf(k_mem, "%ld", &l_pid);
printk(KERN_INFO "k_mem=%s,read l_pid=%ld\n", k_mem, l_pid);
include文件夹中可能有很多其他文件夹。
target_include_directories(mytarget PRIVATE linux-master/include) mytarget是个通过add_executable弄的target
exec()系函数,替换成了就不会返回,替换失败了才返回。
因此若替换成功,则原进程在exec()后的代码将不会执行。
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int c = 1;
int main() {
int ret;
char *myfifo = "/tmp/myfifosharefile";
ret=mkfifo(myfifo, 0666);
pid_t pid = fork();
int fd;
if (pid == 0) {
char buf[4096];
fd = open(myfifo, O_RDONLY);
read(fd, buf, 4096);
printf("received:%s\n", buf);
close(fd);
} else {
fd = open(myfifo, O_WRONLY);
char *msg = "hi";
write(fd, msg, sizeof(msg));
printf("%d\n", c++);
close(fd);
unlink(myfifo);
wait(NULL);
}
}
这个使用过程中涉及 阻塞
进程间通信之fifo,在阻塞模式下,只有当读和写模式都打开时才返回,否则一直阻塞;
非阻塞模式下,当读端没打开,则打开写端无效,返回错误。
建议你读一读UNP卷2。
a. 不使用O_NONBLOCK标志时,只读open要阻塞到某个其它进程为写而打开它为止
b. 不使用O_NONBLOCK标志时,只写open要阻塞到某个其它进程为读而打开它为止
c. 如果在open的时候指定O_NONBLOCK标志,当只读open时,没有进程为写而打开FIFO的话,会返回-1,只写open时,没有进程为读而打开FIFO的话也会返回-1表示失败。
以上的情况使FIFO的使用带来了一些不便,但有一个常用的技巧是,只要用O_RDWR(读写)来打开一个管道,则不会返回失败,而open也不会阻塞。两个进程使用FIFO来进行通信时,通常会使用两个FIFO,一个用于发送数据(即进行写操作),一个用于接收数据(即进行读操作),而这两个FIFO需要均使用O_RDWR来打开。使用系统调用open, read, write来操作这两个FIFO没有什么问题,程序工作得很好。
————————————————
版权声明:本文为CSDN博主「Mr_John_Liang」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liangzhao_jay/article/details/47108977
这个-lrt必须放在最右边
-lrt表示使用library: librt
在CMakeLists.txt中指定lrt:
target_link_libraries(helloapp rt)
NAME
librt, libposix4 - POSIX.1b Realtime Extensions library
SYNOPSIS
cc [ flag... ] file... -lrt [ library... ]
DESCRIPTION
Functions in this library provide most of the interfaces
specified by the POSIX.1b Realtime Extension. See stan-
dards(5). Specifically, this includes the interfaces defined
under the Asynchronous I/O, Message Passing, Process
Scheduling, Realtime Signals Extension, Semaphores, Shared
Memory Objects, Synchronized I/O, and Timers options. The
interfaces defined under the Memory Mapped Files, Process
Memory Locking, and Range Memory Locking options are pro-
vided in libc(3LIB)
See the man pages for the individual interfaces in section
3RT for information on required headers.
The name libposix4 is maintained for backward compatibility
and should be avoided. librt is the preferred name for this
library.
当在linux下使用一些库,如<sys/shm.h>时,需要指定这个选项
virtualbox上使用linux server版才是最佳实践。速度快、无bug。
当然,这样做的话,virtualbox里面是非常不方便复制粘贴的,因此ssh连接virtualbox里的linux server, 连接里的是通过路由转发实现ssh的。但其实可以直接把网络设置成为桥接模式,效果相当于多了台设备连接路由器、进入内网
接着再在Clion等的toolchain里设置remote host, 不要太爽
另外clion还可以直接打开remote的文件、文件夹
Access a remote server
Open the Remote Host tool window by choosing Tools | Deployment | Browse Remote Host from the main menu.
Select the required deployment server from the list. The tool window shows a tree view of files and folders under the server root. If no relevant server is available in the list, click.
输入bash,即可进入界面友好的bash了
uiautomator dump可能会提示ERROR: null root node returned by UiTestAutomationBridge.
解决方案是写个循环多试几(十)次