#include #include "boost/interprocess/detail/tmp_dir_helpers.hpp" void print_boottime() { #ifdef BOOST_INTERPROCESS_HAS_BSD_KERNEL_BOOTTIME int request[2] = { CTL_KERN, KERN_BOOTTIME }; struct ::timeval result; size_t result_len = sizeof result; if (::sysctl (request, 2, &result, &result_len, NULL, 0) < 0) return; std::cout << "Boot_time=" << result.tv_sec << "," << result.tv_usec << "\n"; std::string s; bool add = false; char bootstamp_str[256]; const char Characters [] = { '0', '1', '2', '3', '4', '5', '6', '7' , '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; std::size_t char_counter = 0; long long fields[2] = { result.tv_sec, result.tv_usec }; for(std::size_t field = 0; field != 2; ++field){ for(std::size_t i = 0; i != sizeof(long long); ++i){ const char *ptr = (const char *)&fields[field]; bootstamp_str[char_counter++] = Characters[(ptr[i]&0xF0)>>4]; bootstamp_str[char_counter++] = Characters[(ptr[i]&0x0F)]; std::cout << "i=" << i << ",ptr[i]=" << ptr[i] << ",char_counter=" << char_counter << ",ptr[i]&0xF0 >> 4=" << ((ptr[i] & 0xF0) >> 4) << ",ptr[i]&0x0F=" << (ptr[i] & 0x0F) << "\n"; } } bootstamp_str[char_counter] = 0; if(add){ s += bootstamp_str; } else{ s = bootstamp_str; } std::cout << "Bootstamp=" << s << "\n"; #endif } int main(int argc, char *argv[]) { print_boottime(); return 0; }