Skip to content

Instantly share code, notes, and snippets.

@daparic
Created May 23, 2023 08:26
Show Gist options
  • Save daparic/53aab9d8e03f63dd687995fc0bcdabc5 to your computer and use it in GitHub Desktop.
Save daparic/53aab9d8e03f63dd687995fc0bcdabc5 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <unistd.h>
#include <limits.h>
#include <sys/utsname.h>
int main(int argc, char* argv[]) {
std::string s = argv[0];
std::size_t idx = s.find_last_of("/");
std::string ss = s.substr(0, idx);
std::cout << ss << std::endl;
struct utsname unam;
char hostname[HOST_NAME_MAX];
char username[LOGIN_NAME_MAX];
gethostname(hostname, HOST_NAME_MAX);
getlogin_r(username, LOGIN_NAME_MAX);
uname(&unam);
std::cout << username << "@" << hostname << std::endl;
std::cout << unam.domainname << std::endl;
std::cout << unam.machine << std::endl;
std::cout << unam.nodename << std::endl;
std::cout << unam.release << std::endl;
std::cout << unam.sysname << std::endl;
std::cout << unam.version << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment