2021-11-12 12:48:42 +00:00
|
|
|
#include <IO/ReadHelpers.h>
|
2021-10-27 12:26:42 +00:00
|
|
|
#include <IO/WriteBufferFromString.h>
|
|
|
|
#include <IO/copyData.h>
|
2021-11-12 12:48:42 +00:00
|
|
|
#include <Common/ShellCommand.h>
|
|
|
|
#include <Common/getMaxFileDescriptorCount.h>
|
2021-10-27 12:26:42 +00:00
|
|
|
|
|
|
|
int getMaxFileDescriptorCount()
|
|
|
|
{
|
2021-11-12 12:48:42 +00:00
|
|
|
#if defined(__linux__) || defined(__APPLE__)
|
2021-10-27 12:26:42 +00:00
|
|
|
using namespace DB;
|
|
|
|
|
|
|
|
auto command = ShellCommand::execute("ulimit -n");
|
2021-11-12 12:48:42 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
command->wait();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2021-10-27 12:26:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2021-11-12 12:48:42 +00:00
|
|
|
return parse<Int32>(out.str());
|
2021-10-27 12:26:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|