bool srvPortIsUsed(int devPort) { string str_dev = std::to_string(devPort)+".txt"; std::strstream srm; //srm << "lsof -i :" << devPort << " >netstat.txt"; srm << "lsof -i :" << devPort << " >" << str_dev; system(srm.str()); //std::ifstream in("netstat.txt"); std::ifstream in(str_dev); std::string line; std::getline(in, line); std::getline(in, line); if (!line.empty() && (line != "")) { line.find_first_of(' '); line = line.substr(line.find_first_of(' ') + 1); line = line.substr(0, line.find_first_of(' ')); std::string sr = "kill -9 " + line; system(sr.c_str()); return true; } else{ return false; } }