| 1 | #include <iostream>
|
|---|
| 2 | #include "boost/interprocess/detail/tmp_dir_helpers.hpp"
|
|---|
| 3 |
|
|---|
| 4 | void print_boottime()
|
|---|
| 5 | {
|
|---|
| 6 | #ifdef BOOST_INTERPROCESS_HAS_BSD_KERNEL_BOOTTIME
|
|---|
| 7 | int request[2] = { CTL_KERN, KERN_BOOTTIME };
|
|---|
| 8 | struct ::timeval result;
|
|---|
| 9 | size_t result_len = sizeof result;
|
|---|
| 10 |
|
|---|
| 11 | if (::sysctl (request, 2, &result, &result_len, NULL, 0) < 0)
|
|---|
| 12 | return;
|
|---|
| 13 |
|
|---|
| 14 | std::cout << "Boot_time=" << result.tv_sec << "," << result.tv_usec << "\n";
|
|---|
| 15 |
|
|---|
| 16 | std::string s;
|
|---|
| 17 | bool add = false;
|
|---|
| 18 |
|
|---|
| 19 | char bootstamp_str[256];
|
|---|
| 20 |
|
|---|
| 21 | const char Characters [] =
|
|---|
| 22 | { '0', '1', '2', '3', '4', '5', '6', '7'
|
|---|
| 23 | , '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
|---|
| 24 |
|
|---|
| 25 | std::size_t char_counter = 0;
|
|---|
| 26 | long long fields[2] = { result.tv_sec, result.tv_usec };
|
|---|
| 27 | for(std::size_t field = 0; field != 2; ++field){
|
|---|
| 28 | for(std::size_t i = 0; i != sizeof(long long); ++i){
|
|---|
| 29 | const char *ptr = (const char *)&fields[field];
|
|---|
| 30 | bootstamp_str[char_counter++] = Characters[(ptr[i]&0xF0)>>4];
|
|---|
| 31 | bootstamp_str[char_counter++] = Characters[(ptr[i]&0x0F)];
|
|---|
| 32 |
|
|---|
| 33 | std::cout << "i=" << i << ",ptr[i]=" << ptr[i]
|
|---|
| 34 | << ",char_counter=" << char_counter
|
|---|
| 35 | << ",ptr[i]&0xF0 >> 4=" << ((ptr[i] & 0xF0) >> 4)
|
|---|
| 36 | << ",ptr[i]&0x0F=" << (ptr[i] & 0x0F)
|
|---|
| 37 | << "\n";
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 | bootstamp_str[char_counter] = 0;
|
|---|
| 41 | if(add){
|
|---|
| 42 | s += bootstamp_str;
|
|---|
| 43 | }
|
|---|
| 44 | else{
|
|---|
| 45 | s = bootstamp_str;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | std::cout << "Bootstamp=" << s << "\n";
|
|---|
| 49 | #endif
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | int main(int argc, char *argv[])
|
|---|
| 53 | {
|
|---|
| 54 | print_boottime();
|
|---|
| 55 | return 0;
|
|---|
| 56 | }
|
|---|