times(NULL) Segmentation fault
阿新 • • 發佈:2017-07-06
tps str ror color return nbsp cti blog turn
/****************************************************************************** * times(NULL) Segmentation fault * 說明: * 在PC機上times(NULL)是沒問題的,但在嵌入式Linux上,貌似不傳遞參數是有可能 * 會出問題的。 * * 2017-7-6 深圳 龍華樟坑村 曾劍鋒 *****************************************************************************/ 一、參考文檔: 1. Segmentation fault using ctime https://stackoverflow.com/questions/12338947/segmentation-fault-using-ctime 2. Segmentation fault on time(0); https://stackoverflow.com/questions/1731802/segmentation-fault-on-time0 3. segmentation fault (core dumped) error when usingtime function https://stackoverflow.com/questions/20939415/segmentation-fault-core-dumped-error-when-using-time-function 二、測試代碼: #include <iostream> #include <sys/times.h> #include <unistd.h> using namespace std; int main() { unsignedlong SysF = sysconf(_SC_CLK_TCK); struct tms tmp; while(1) { // unsigned long tick = times(NULL); // don‘t use this. it may cause segmentation fault. unsigned long tick = times(&tmp); unsigned long RetUl = (1000 / SysF) * tick; cout << "tick: " << tick << " RetUl: " << RetUl << endl; usleep(10000); } return 0; }
times(NULL) Segmentation fault