27#include <libexcept/file_inheritance.h>
32#include <snapdev/glob_to_list.h>
44#include <snapdev/poison.h>
48void usage(
char const * argv0)
50 std::cout <<
"Usage: sudo " << argv0 <<
" [--opts]" << std::endl;
51 std::cout <<
"where --opts is one of:" << std::endl;
52 std::cout <<
" --all deswappify all the running processes (not recommended)" << std::endl;
53 std::cout <<
" --help | -h print out this help screen" << std::endl;
54 std::cout <<
" --pid <pid> the PID of the process to deswappify" << std::endl;
58int main(
int argc,
char * argv[])
60 libexcept::verify_inherited_files();
63 for(
int i(1); i < argc; ++i)
65 if(strcmp(argv[i],
"--help") == 0
66 || strcmp(argv[i],
"-h") == 0)
71 else if(strcmp(argv[i],
"--pid") == 0)
76 std::cerr << argv[0] <<
":error: pid must be followed by a process identifier." << std::endl;
82 std::cerr << argv[0] <<
":error: invalid pid in \"" << argv[i] <<
"\"." << std::endl;
86 else if(strcmp(argv[i],
"--all") == 0)
92 std::cerr << argv[0] <<
":error: unexpected command line option \"" << argv[i] <<
"\"." << std::endl;
97 if((pid > 0 || pid == -1)
100 std::cerr << argv[0] <<
":warning: deswappifying generally requires you to be root. If it doesn't work, try again with sudo even if you own the process." << std::endl;
106 return errno == 0 ? 0 : 1;
110 snapdev::glob_to_list<std::list<std::string>> glob;
112 snapdev::glob_to_list_flag_t::GLOB_FLAG_IGNORE_ERRORS,
113 snapdev::glob_to_list_flag_t::GLOB_FLAG_ONLY_DIRECTORIES>(
"/proc/*"))
115 std::cerr << argv[0] <<
":error: could not read /proc for a list of processes." << std::endl;
119 for(
auto const & p : glob)
121 pid = atol(p.c_str());
138 std::cerr << argv[0] <<
":error: nothing to do. Try again with --pid or --all." << std::endl;
int deswappify(pid_t pid)
Go through the swapped out sections of a process and deswappify them.
Thread Runner and Managers.