於 Linux 上撰寫 daemon server 要注意的
// test.cpp
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#include <iostream>
using namespace std;
int main(void)
{
struct rlimit limit;
const struct rlimit mit = { 2048, 600000 };
getrlimit(RLIMIT_NOFILE, &limit);
cout << "Current: " << limit.rlim_cur << endl;
cout << "Max: " << limit.rlim_max << endl;
setrlimit(RLIMIT_NOFILE, &mit);
getrlimit(RLIMIT_NOFILE, &limit);
cout << "Current: " << limit.rlim_cur << endl;
cout << "Max: " << limit.rlim_max << endl;
return 0;
}Last updated