我有以下代码:
void
set_fl(int fd, int flags) /* flags are file status flags to turn on */
{
int val;
if ((val = fcntl(fd, F_GETFL, 0)) < 0)
err_sys("fcntl F_GETFL error");
val |= flags; /* turn on flags */
if (fcntl(fd, F_SETFL, val) < 0)
err_sys("fcntl F_SETFL error");
}
int
main(void)
{
char buf[BUFSIZ];
set_fl(STDOUT_FILENO, O_NONBLOCK); //set STDOUT_FILENO to nonblock
if(read(STDIN_FILENO, buf, BUFSIZ)==-1) { //read from STDIN_FILENO
printf("something went wrong with read()! %s\n", strerror(errno));
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我设置STDOUT_FILENO为非阻塞模式,但读取操作似乎STDIN_FILENO立即完成。为什么? …
在关于孤立进程组的 GNU libc手册中,它提到:
“process groups that continue running even after the session leader
has terminated are marked as orphaned process groups.
When a process group becomes an orphan, its processes are sent a SIGHUP
signal. Ordinarily, this causes the processes to terminate. However,
if a program ignores this signal or establishes a handler for it
(see Signal Handling), it can continue running as in the orphan process
group even after its controlling process terminates; but it still
cannot access …Run Code Online (Sandbox Code Playgroud) 有时我想强制子类覆盖函数,例如:
class A
{
virtual void foo() = 0;
};
class B : public A
{
virtual void foo() {...}
};
class C : public B
{
//people may forget to override function foo
};
Run Code Online (Sandbox Code Playgroud) 在ubuntu gcc 8.0中:
void bar(){}
constexpr int foo(int a)
{
if (a <=0 )
bar();
return 1;
}
int main()
{
int a1[foo(-1)]; //will give a compile error, which is expected,
//since non-constexpr function is not allowd in constexpr context
}
Run Code Online (Sandbox Code Playgroud)
但在以下测试中:
int main()
{
int a2[foo(1)]; //no compile error
}
Run Code Online (Sandbox Code Playgroud)
这里,bar是非constexpr功能.我想知道为什么在constexpr上下文中允许非constexpr函数,尽管在这个测试中它不会被调用.
nm -D /lib32/libc.so.6 | grep '\<fopen\>'
0005d0c0 T fopen
00109750 T fopen
readelf -s /lib32/libc.so.6 | egrep '0005d0c0|00109750'
181: 0005d0c0 50 FUNC GLOBAL DEFAULT 12 fopen@@GLIBC_2.1
182: 00109750 136 FUNC GLOBAL DEFAULT 12 fopen@GLIBC_2.0
679: 0005d0c0 50 FUNC GLOBAL DEFAULT 12 _IO_fopen@@GLIBC_2.1
680: 00109750 136 FUNC GLOBAL DEFAULT 12 _IO_fopen@GLIBC_2.0
Run Code Online (Sandbox Code Playgroud)
这是我的问题:
为什么/lib32/libc.so.6中有两个fopen符号?应禁止同一目标文件中的相同符号,对吗?
为什么readelf -s转出fopen @@ GLIBC_2.1和fopen@GLIBC_2.0而不是fopen?
谢谢
在html中,我们可以使用以下命令为整个文档指定charset:
<head>
<meta charset="utf-8" />
</head>
Run Code Online (Sandbox Code Playgroud)
但有时候,不可能改变整个页面的字符集,例如,使用注入.
我想声明一个指定元素的charset,就像这样
<span charset="utf-8">....</span>
Run Code Online (Sandbox Code Playgroud)
但它似乎不起作用.
有任何想法吗?
auto a = [](){};
auto b = [](){};
vector<decltype(a)> v;
v.push_back(a); //ok
v.push_back(b); //compiler error
Run Code Online (Sandbox Code Playgroud)
a和b有不同的类型.
我想知道每个lambda函数是否真的是一种匿名类,每当我们创建一个lambda函数时,我们创建一个具有随机名称的新类,只对编译器可见?
我们知道:
////////////////////////////////////////////////// ///////
close()将终止tcp连接上的两个方向
shutdown()可以阻止一个或两个方向的通信
////////////////////////////////////////////////// ///////
在这里,让我困惑的是tcp stack如何区分它们?
我写了一个示例程序:
首先我使用:
....
connect(192.168.1.100) //there is a server process running in 192.168.1.100
....
close(socketfd);
sleep(1000);
Run Code Online (Sandbox Code Playgroud)
然后我使用wireshark来转储数据包:
01 -->syn
02 <--syn,ack
03 -->ack
04 -->fin,ack
05 <--ack
Run Code Online (Sandbox Code Playgroud)
netstat -an | grep 192.168.1.100
我已经运行了大约5分钟,它打印:
首先是"tcp 0 0 ... FIN_WAIT2",然后大约2分钟后没有输出,似乎连接已被破坏.
然后,我使用:
....
connect(192.168.1.100)
....
shutdown(socketfd,SHUT_WR);
sleep(1000);
Run Code Online (Sandbox Code Playgroud)
使用wireshark转储数据包:
01 - >同义词
02 < - syn,ack
03 - >确认
04 - > fin,ack
05 < - ack
...
netstat -an | grep 192.168.1.100
运行大约10分钟,它总是打印:"tcp 0 0 …
const int ci = 10;
auto i = ci; // i will be "int" instead of "const int"
i = 20;
Run Code Online (Sandbox Code Playgroud)
我想知道为什么汽车是为这种行为而设计的?
为什么类型i是"int"而不是"const int"?
这里有什么问题?
我想明白为什么会帮助我们记住它