diff --git a/1_3.test_code/c_test/atoi/atoi b/1_3.test_code/c_test/atoi/atoi new file mode 100755 index 0000000..f0dc018 Binary files /dev/null and b/1_3.test_code/c_test/atoi/atoi differ diff --git a/1_3.test_code/c_test/atoi/atoi.c b/1_3.test_code/c_test/atoi/atoi.c new file mode 100644 index 0000000..3b83aa7 --- /dev/null +++ b/1_3.test_code/c_test/atoi/atoi.c @@ -0,0 +1,34 @@ +/************************************************************************* + > File Name: atoi.c + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月15日 星期三 22时26分47秒 + ************************************************************************/ +#include +#include +#include + + +char buf[50]; + +char * timestamp() +{ + time_t time_stp; + time ( &time_stp ); + printf("%ld\n", time_stp); + sprintf(buf, "%d", time_stp); + return buf; +} + + +int main(int argc, char *argv[]) +{ + //printf("timestamp: %s\n", timestamp()); + char *str = timestamp(); + int test = atoi(str); + time_t tt = atoi(str); + + printf("%d\n", test); + printf("%d\n", tt); +} diff --git a/1_3.test_code/c_test/testMainArgv/testMainArgv b/1_3.test_code/c_test/testMainArgv/testMainArgv new file mode 100755 index 0000000..ed1971f Binary files /dev/null and b/1_3.test_code/c_test/testMainArgv/testMainArgv differ diff --git a/1_3.test_code/c_test/testMainArgv/testMainArgv.c b/1_3.test_code/c_test/testMainArgv/testMainArgv.c new file mode 100644 index 0000000..50248e3 --- /dev/null +++ b/1_3.test_code/c_test/testMainArgv/testMainArgv.c @@ -0,0 +1,19 @@ +/************************************************************************* + > File Name: testMainArgv.c + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月14日 星期二 12时59分50秒 + ************************************************************************/ + +#include +#include +int main(int argc,char *argv[]) +{ + printf("参数个数= %d\n", argc); + printf("参数1= %s\n", argv[1]); + printf("参数2= %s\n", argv[2]); + printf("参数3= %s\n", argv[3]); + return 0; +} + diff --git a/1_3.test_code/c_test/testTimeStamp/test b/1_3.test_code/c_test/testTimeStamp/test new file mode 100755 index 0000000..0ca7b19 Binary files /dev/null and b/1_3.test_code/c_test/testTimeStamp/test differ diff --git a/1_3.test_code/c_test/testTimeStamp/test.cpp b/1_3.test_code/c_test/testTimeStamp/test.cpp new file mode 100644 index 0000000..91c6331 --- /dev/null +++ b/1_3.test_code/c_test/testTimeStamp/test.cpp @@ -0,0 +1,46 @@ +/************************************************************************* + > File Name: test.cpp + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月15日 星期三 15时52分24秒 + ************************************************************************/ +/* 微秒 */ + +#include +#include +#include +int main() +{ + struct timeval t_val; + gettimeofday(&t_val, NULL); + printf("start, now, sec=%d m_sec=%d \n", t_val.tv_sec, t_val.tv_usec); + long sec = t_val.tv_sec; + time_t t_sec = (time_t)sec; + printf("date:%s", ctime(&t_sec)); + return 0; +} + + +/*纳秒 +#include +#include + +int main() +{ + struct timespec time1 = {0, 0}; + clock_gettime(CLOCK_REALTIME, &time1); + printf("CLOCK_REALTIME: %ld, %ld\n", time1.tv_sec, time1.tv_nsec); + time_t tmp = time1.tv_sec * 1000000000 + time1.tv_nsec; + printf("CLOCK_REALTIME: %ld\n", tmp); + + clock_gettime(CLOCK_MONOTONIC, &time1); + printf("CLOCK_MONOTONIC: %ld, %ld\n", time1.tv_sec, time1.tv_nsec); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); + printf("CLOCK_PROCESS_CPUTIME_ID: %ld, %ld\n", time1.tv_sec, time1.tv_nsec); + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time1); + printf("CLOCK_THREAD_CPUTIME_ID: %ld, %ld\n", time1.tv_sec, time1.tv_nsec); + + printf("%ld\n", time(NULL)); +} +*/ diff --git a/1_3.test_code/c_test/testTimeStamp/testTimeStamp b/1_3.test_code/c_test/testTimeStamp/testTimeStamp new file mode 100755 index 0000000..3362ca8 Binary files /dev/null and b/1_3.test_code/c_test/testTimeStamp/testTimeStamp differ diff --git a/1_3.test_code/c_test/testTimeStamp/testTimeStamp.c b/1_3.test_code/c_test/testTimeStamp/testTimeStamp.c new file mode 100644 index 0000000..0ca58f3 --- /dev/null +++ b/1_3.test_code/c_test/testTimeStamp/testTimeStamp.c @@ -0,0 +1,95 @@ +/************************************************************************* + > File Name: testTimeStamp.c + > Description: + > Conclusion: + > Author: rh_Jameson + > Created Time: 2015年07月14日 星期二 13时05分04秒 + ************************************************************************/ +/* +#include +#include +int main() +{ + time_t rawtime; + time ( &rawtime ); + printf("%ld\n", &rawtime); + printf ( "The current local time is: %s", ctime (&rawtime) ); +} +*/ +/* ctime example +#include +#include + + +int main () +{ + time_t time_stp; + time ( &time_stp ); + printf("%ld\n", time_stp); + printf ( "The current local time is: %s", ctime (&time_stp) ); + + return 0; +} +*/ + +/* 用time()取得时间(秒数),利用localtime() + +转换成struct tm 再利用mktine()将struct tm转换成原来的秒数*/ + +#include + +#include +/* +int main() + +{ + + time_t timep; + + struct tm *p; + + time(&timep); + + //printf("time() : %d \n",timep); + + p=localtime(&timep); + + timep = mktime(p); + + printf("time()->localtime()->mktime():%d\n",timep); + +} +*/ + +#include +#include + +#include + + + +int main() +{ + /* + struct timeval tv; + struct timezone tz; + gettimeofday(&tv,&tz); + + printf("tv_sec:%ld\n",tv.tv_sec); + printf("tv_usec:%ld\n",tv.tv_usec); + printf("tz_minuteswest:%d\n",tz.tz_minuteswest); + printf("tz_dsttime:%d\n",tz.tz_dsttime); + */ + struct timeval tpstart,tpend; + long iTimeInterval; + gettimeofday(&tpstart,NULL); + /* to do what you want*/ + gettimeofday(&tpend,NULL); + iTimeInterval=1000000 * (tpend.tv_sec - tpstart.tv_sec); + iTimeInterval += tpend.tv_usec - tpstart.tv_usec; + /*iTimeInterval 就是微妙级的时间跨度*/ + printf("tpstart:%ld\n", tpstart.tv_usec); + printf("tpend:%ld\n", tpend.tv_usec); + printf("iTimeInterval:%ld\n", tpend); + +} diff --git a/1_3.test_code/sh_test/testMemory.sh b/1_3.test_code/sh_test/testMemory.sh new file mode 100755 index 0000000..bc2af87 --- /dev/null +++ b/1_3.test_code/sh_test/testMemory.sh @@ -0,0 +1,9 @@ +#!/bin/sh +var=1 +obj=40 +while ((${var} < ${obj})); do + ./testMemory.sh #call self + var=$((var+1)) + echo "unlimited recursive call..." +done +