ClickHouse/src/Common/getMaxFileDescriptorCount.cpp

28 lines
514 B
C++
Raw Normal View History

2021-10-27 12:26:42 +00:00
#include <Common/getMaxFileDescriptorCount.h>
#include <Common/ShellCommand.h>
#include <IO/WriteBufferFromString.h>
#include <IO/copyData.h>
#include <string>
int getMaxFileDescriptorCount()
{
#if defined(__linux__) || defined(__APPLE__)
using namespace DB;
auto command = ShellCommand::execute("ulimit -n");
WriteBufferFromOwnString out;
copyData(command->out, out);
2021-10-27 14:26:53 +00:00
if (!out.str().empty())
2021-10-27 12:26:42 +00:00
{
return std::stoi(out.str());
}
return -1;
#else
return -1;
#endif
}