Skip to content

Commit

Permalink
handle invalid input PID
Browse files Browse the repository at this point in the history
  • Loading branch information
henrik242 committed Jan 11, 2024
1 parent a56a63c commit d82fd3c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions procenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,24 @@
*/

#include <iostream>
#include <exception>
#include "process.hpp"

int main(int argc, char **argv) {
if (argc != 2) {
printf("procenv <pid>\n");
std::cout << "procenv <pid>" << "\n";
return 0;
}
int proc_id = std::stoi(argv[1]);
int proc_id;
try {
proc_id = std::stoi(argv[1]);
} catch (std::exception& e) {
std::cout << "Illegal PID: " << argv[1] << "\n";
return 0;
}
std::vector<std::string> env = ngs::ps::environ_from_proc_id(proc_id);
for (std::size_t j = 0; j < env.size(); j++) {
std::cout << env[j] << "\n";
std::cout << env[j] << "\n";
}
return 0;
}

0 comments on commit d82fd3c

Please sign in to comment.