본문 바로가기

예제

[JAVA] Reflection 을 이용한 변수명 출력하기 - 예제코드 예를 들면 public class Car { private String model; public String owner; public static final int FOO = 123; public static final int BAR = 456; 이런식으로 숫자값에 대한 정의만 난무한 class 가 있고, 이에 대해서 변수명을 출력할 일이 있다면 (주로 디버깅) 일일이 switch 문이나 if else 를 만드는 일은 곤욕스러운 일이다. 자바에서는아래와 같이 getDeclaredFields 함수를 이용해서 동적으로 123 의 값을 가지고 "FOO" 를 출력하는 일이 가능하다. onLine compile test : https://www.compilejava.net///********************.. 더보기
get pid by process name - example source code (예제 코드) 원문 : https://phoxis.org/2013/09/13/find-process-ids-of-a-running-process-by-name/ 이름으로 pid 를 찾아내는 예제 #include #include #include #include #include #include /* checks if the string is purely an integer * we can do it with `strtol' also */int check_if_number (char *str){ int i; for (i=0; str[i] != '\0'; i++) { if (!isdigit (str[i])) { return 0; } } return 1;} #define MAX_BUF 1024#define PID_LIST_BL.. 더보기
자바 코드 예제들을 모아놓은 사이트 http://www.programcreek.com/java-api-examples/ function 이름으로 검색하면 다양한 usage 를 볼 수 있다. 더보기
poll, sysfs sample code poll 사용 예제 man page 에는 poll_wait 가 대기를 시켜준다고 하는데..아무리 사용해 봐도 poll_wait 는 대기를 하지 않고 바로 return 처리된다. 이에 wait_event_interruptible 을 사용 하였다. 주문한 책이 오면 poll_wait 에 대해 좀 더 읽어 본 후 재업하도록 하겠다. DECLARE_WAIT_QUEUE_HEAD(wait_queue); unsigned int onegun_driver_poll(struct file *file, poll_table * wait){printk("%s()++\n", __func__);//poll_wait(file, &wait_queue, wait); /* normal case */if (wait_event_interrup.. 더보기