본문 바로가기

Linux

linux command : stat, fstat, lstat http://s2kiess.blog.me/220139796462 stat : 파일경로를 가지고 파일 속성을 가지고 온다.fstat : 파일 디스크립터를 가지고 파일 속성을 가지고 온다. 심볼릭 링크의 경우 원본 파일의 속성을 가지고 온다.lstat : fstat 과 동일하나, 심볼링 링크일 경우 링크 파일의 속성을 가지고 온다. The usage of "stat" on arm linux # statusage: stat [-f] [-c FORMAT] FILE... Display status of files or filesystems. -f display filesystem status instead of file status-c Output specified FORMAT string instead of d.. 더보기
epoll 에 대한 한국어 설명 poll 이나 select 의 비 효율성을 해결한 새로운 기능. http://vovheas104.blog.me/220485326114 http://cafe.naver.com/newchany/87 더보기
close_on_exec static __inline__ int adb_socketpair( int sv[2] ){ int rc; rc = unix_socketpair( AF_UNIX, SOCK_STREAM, 0, sv ); if (rc < 0) return -1; close_on_exec( sv[0] ); close_on_exec( sv[1] ); return 0;} static __inline__ void close_on_exec(int fd){ fcntl( fd, F_SETFD, FD_CLOEXEC );} #include int execve(const char *filename, char *const argv[], char *const envp[]);함수를 호출하면 기본적으로는 file descriptor 가 open 된 .. 더보기
socketpair() 출처 : http://osr507doc.sco.com/en/netguide/dusockD.socketpairs_codetext.html socketpair: read / write 가 가능한 한쌍의 socket 을 open 한다. 예제 Socketpair sample code (UNIX only)The following example illustrates the use of socketpairs, which are a slight generalization of pipes used for two-way stream communication. Because socketpairs are an extension of pipes, their use resembles that of pipes rather than.. 더보기
linux signals 출처 : http://fehead.tistory.com/146 SIGPIPE파이프가 끊겼을 경우 발생하는 signalhttp://blog.naver.com/PostView.nhn?blogId=hyungii&logNo=130081645365 * 파이프깨짐?소켓은 프로세스간 통신 메카니즘의 확장으로 볼 수 있습니다.전형적인 유닉스의 프로세스간통신(IPC라고 하지요) 메카니즘은 파이프입니다.이러한 관습(?)에 힘입어, 소켓에서도 그 연결이 끊기는 경우 파이프가 끊겼다느니, 깨졌다느니, broken pipe등의 메시지를 사용합니다.파이프깨짐은 바로 통신의 종결을 의미합니다. 통신이 끊김은 어떻게 감지하는가? 보통 3가지 방법이 있을 수 있습니다.1) 상태검사 : 소켓도 파일로 간주하므로, 파일의 상태정보를 읽어.. 더보기
linux namespace 각각의 process 가 가지고 있는 mount set다른 FS namespace 를 가지고 있는 process 는 서로 다른 mount information 을 가지고 있다.각 process 의 proc 의 ns 에서 FS namespace 를 확인 할 수 있다. root@klte:/proc/7532 # ls -al /proc/7939/ns lrwxrwxrwx bluetooth bluetooth 2015-01-02 11:09 mnt -> mnt:[4026534520]lrwxrwxrwx bluetooth bluetooth 2015-01-02 11:09 net -> net:[4026533490]root@klte:/proc/7532 # ls -al /proc/7532/nslrw.. 더보기
Android log command, logwrapper 출처 : http://elinux.org/Android_Logging_System Android log message 를 만든다. log -p e -t onegun test message25402 01-08 09:27:26.210 15852 15852 E onegun : test message Process 가 출력하는 stdout 이나 stderr 즉, terminal 로 출력될 내용들을 android log 로 보내서 로깅되도록 한다. logwrapper -x ./test_program_name -testprogram_argstag : binarypriority : LOG_INFO 더보기
logcat 사용법 정리 [adb] logcat [] ... [] ... The following table describes the logcat command line options: -c Clears (flushes) the entire log and exits. 전체로그를 삭제하고 빠져나옵니다. -d Dumps the log to the screen and exits. 저장된 로그를 화면에 출력하고 종료한다. -f Writes log message output to . The default is stdout. -g Prints the size of the specified log buffer and exits. 로그버퍼의 사이즈를 출력 -n Sets the maximum number of rotated logs to . T.. 더보기
Program 실행시간(performance time) 측정 방법, IO time 계산 방법 time command #time ./mobibench -p ....#0m2.15s real 0m0.40s user 0m0.31s system 결과는 다음과 같이 해석real : 실제 program 동작 시간user : user area program 동작 시간system : kernel area program 동작 시간 IO time = real - (user + system) 더보기
linux kernel 이 지원하는 system call list 보기 간혹 자신이 사용하는 linux kernel 이 어떤 system call 을 지원하는지 알고 싶을때 사용할 수 있는 방법이다.혹은 kernel code 의 특정 함수가 실제 빌드가 되어서 kernel binary 에 들어가 있는지도 알 수 있다. /proc # cat kallsyms > /data/local/tmp/kernal_symbal.log proc/kallsyms는 kernel 내부의 symbal table 을 모두 보여준다. 여기서 sys_ prefix 를 사용하는 함수들이 system call 이다. ...00000000 T sys_truncate00000000 T sys_ftruncate00000000 T sys_truncate6400000000 T sys_ftruncate640000000.. 더보기
linux kernel time resolution & hrtimer 원문 : http://makingdream.tistory.com/20 HZ 와 Jiffies시스템 타이머들은 프로그램 가능한 주파수 대역에서 프로세서에 끼어(interrupt, pop)든다. 주파수 즉, 초당 타이머 틱들의 수는 커널 변수인 HZ에 포함되어 있다. HZ값은 협상(trade-off)하여 선택된다. 핑거 타이머에서 결과값이 큰 HZ는 좀더 좋은 스케줄링 해결책이다. 그러나, HZ 값들이 커질수록 많은 부하가 발생하며 인터럽트 문맥교환 시간은 더 많은 사이클들이 소모되기 때문에 높은 파워 소비가 발생한다. HZ값은 아키텍처에 의존한다. x86 시스템들의 2.4 커널에서는, HZ 값이 기본적으로 100으로 설정된다. 2.6 커널에서는 1000으로 변경된다. 그러나, 2.6.13 커널에서는 250.. 더보기
윈도우 shell 에서 linux shell command 사용하기 Gow – The lightweight alternative to Cygwin가볍고 사용이 편리함.=> Gow 는 cmd 를 실행하면 자동으로 실행되면서 윈도우 shell 상에서 gnu 명령어들이 동작하도록 해 줍니다.따라서 윈도우에서도 linux shell command 를 사용하고자 한다면,이 프로그램이 대안입니다.https://github.com/bmatzelle/gow/releases clinkwondiws cmd 에서 ctrl+v 같은 단축키가 동작하도록 해주는 프로그램입니다.clink+sygwin 방법이 있다는데 아직 시도해 보지 못했습니다.Gow 와 함께 쓰면 매우 편안한 windows shell 환경을 제공합니다. ConEmuwindows cmd 의 화룡정점이라고 해야할까..ssh 프로그램.. 더보기
linux shell script file 이 실행이 안될때. # ls -al-rwxrwxrwx shell shell 1631963 2014-07-30 21:16 mobibench_arm_3.7.11-rwxrwxrwx shell shell 232 2014-08-26 10:22 msh_dio.sh 모두 권한이 있는데도 불구하고 shell 을 실행하면 permission error 가 발생함. # ./msh_dio.sh1rm failed for /cache/test.db0*, No such file or directory./msh_dio.sh[9]: ./mobibench_arm_3.7.11_dio_0819: can't execute: Permission deniedfailed on '/cache/test.db0' - No such file or directory 정확하.. 더보기
wrtie 비교 O_DIRECT and no-delay-alloc mount option - O_DIRCET optionopen 함수에 주는 flag - no-delay-alloc optionfile system mount option : file write 를 보통 지연시켜서 하는데 이기능을 사용하지 않음. umount /cache 일반적인 mount 명령어mount -t ext4 /dev/block/mmcblk0p27 /cache no delay alloc mount 명령어mount -t ext4 -o nodelalloc /dev/block/mmcblk0p27 /cache test source code 하기 파일에서 O_DIRECT 주석을 풀어주면 O_DIRECT 로 동작함.간단히 input file 을 open 하여 내용을 읽고 output 파일에 write 하는 예제임. 결과를 mos.. 더보기
[linux][platform] O_DIRECT file open, read, write example O_DIRECT flag 를 사용한 file open, read, write 예제 입니다. page size 4096 예 맞추어서 read / write 를 해야 합니다. 더보기
c code 개발을 위한 나의 vim setting 제가 사용하고 있는 vi setting 입니다.2~3일 걸쳐 setting 한만큼 한번에 쉽게 최적의 셋팅을 할 수 있도록 수정파일을 모아서 첨부하였습니다. apt-get install ctags cscope vim-runtime vim-gui-common 으로 설치하고 첨부파일을 풀어서 각각 아래 폴더에 복사하면 됩니다. /usr/bin/mkcscope.sh/etc/vim/vimrc/usr/share/vim/vim73/plugin//usr/share/vim/vim73/colors/ vi 버전은 다음과 같습니다. # vi --versionVIM - Vi IMproved 7.3 (2010 Aug 15, compiled May 4 2012 04:22:36) 소스 폴더가 있는곳에서mkcscope.sh를 실행하.. 더보기
[linux platform] LD_PRELOAD 를 이용한 android 에서의 library 교체 library 를 수정하는 개발을 할때,매번 package 로 묶어서 전체 이미지를 다운로드 하는것은 많은 시간을 소모하게 한다. 아래 방법을 사용하면, 내가 build 한 library 만 바꾸면서system reboot 이나 전체 image download 없이 디버깅을 할때 아주 유용한 방법이다. adb shell 에서 다음과 같이 입력하면,원래 설치되어 있는 library 파일이 아닌, 내가 지정한 library 파일을 load 해서 실행된다. - LD_PRELOAD 의 입력방법1. 모든 프로그램이 내가 만든 library 를 사용하기 원할때..LD_PRELOAD = "preload 되기 원하는 so 파일 경로" 2. 특정 프로그램만 내가 만든 library 를 사용하기 원할때..LD_PRELOA.. 더보기
현재 프로세스의 이름 출력, print current process name linux platform side 에서 현재 프로세스 이름을 출력하는 방법 입니다. extern char *__progname;char* get_process_name(){return __progname;} 더보기
virtual address to physical address (64bit linux) linux 64bit 에서 page address 변환에 대해서 한눈에 보기 쉽게 그려보았습니다. 사용할때는 꼭 출처를 명시해 주기 바랍니다. pde64_table = (pde64_t *)__va(BASE_TO_PAGE_ADDR(pdpe64_table->pd_base_addr) + (PDE64_INDEX(fault_addr)*sizeof(pde64_t))); if(!pde64_table->present) { uintptr_t tmp_pte64_table; tmp_pte64_table = (uintptr_t)petmem_smart_alloc_pages(map, (uintptr_t)NULL, (pte64_t *)NULL); memset((void *)__va(tmp_pte64_table), 0, PAGE_S.. 더보기
GDB 명령어 아래 사이트에서 조금 도움을 받았다.하지만, 잘못된 정보나 보충할 부분도 있어서 추가해 본다.http://hoyeden.blog.me/20206894205http://kthan.tistory.com/entry/Linux%EB%A6%AC%EB%88%85%EC%8A%A4-%EB%94%94%EB%B2%84%EA%B9%85%EC%9D%84-%EC%9C%84%ED%95%9C-gdb-%EC%82%AC%EC%9A%A9%EB%B2%95-%EB%B0%8F-%EB%AA%85%EB%A0%B9%EC%96%B4-%EC%A4%91%EA%B8%89 사용을 하려면 먼저 대상이 되는 process 를 -g 옵션으로 컴파일 해야 한다. 대상 process 가 다수의 parameter(argument) 으로 실행된다면, 아래와 같이 --.. 더보기
gdb gui debugger 인 insight 사용하기 (Ubuntu 12.04.4) gdb 는 linux 에서 process 를 debug 하기 위한 debugger 이다.여기에 GUI 를 제공하는 것들은 DDD / insight 등이 있는데, 이중 insight 를 사용해 보았다. 마치 윈도우 개발환경을 보는것 같은 편리한 환경을 제공해 준다. 환경은 ubuntu 12.04.4 LTS 버전이다. 아래 사이트에서 insight 소스 코드를 다운로드 한다. http://sourceware.org/insight/ 여러 버전들이 있는데, 이중 마지막 버전은 ubuntu 에서 요상한 애러가 발생하고instight-6.8-1a.tar.bz2 버전을 받아야 정상 동작한다. 아래 블로그의 도움을 받아서 몇가지 패키지를 설치했다.http://minimonk.net/1639이분은 결국 실패하신것 같은데.. 더보기
mmap 을 이용한 process memory mapping 원문 : http://naito.tistory.com/entry/%EB%A6%AC%EB%88%85%EC%8A%A4%EB%A9%94%EB%AA%A8%EB%A6%AC-%EB%A7%A4%ED%95%91memory-mapping 공부하면서 더 내용추가를 할 예정이다. 프로세스 메모리 매핑 대량의 데이터를 처리하는 하드웨어를 다루는 DD작성시 mmap은 필수적으로 구현해야.. app에서 dd로 hw를 제어할때 read,write,ioctl은 프로세스 메모리공간과 커널 메모리 공간사이의 메모리 전달과정이 수반되기 때문에 매우 비효율적이다. 고로 mmap을 이용해 직접 hw의 io주소 공간을 메모리 복사없이 직접적으로 사용할 수 있다. mmap함수는 메모리 주소를 이용해 파일에 접근하도록 하는 함수다. 그러나 디바이.. 더보기
linux 에서 page cache(페이지 캐쉬)란? disk I/O 의 효율을 위해 main memory 에 잡아놓은 cache buffer 의 명칭 아래와 같이 cache memory 의 상태를 알 수 있다. # free -m total used free shared buffers cachedMem: 6759 3121 3638 0 220 2008-/+ buffers/cache: 892 5867Swap: 4692 0 4692 원문 : http://wnstjqdl.tistory.com/46 시스템이 특별히 메모리 자원의 사용량이 없는데 캐쉬메모리가 많아 할당되어 여유메모리 할당이 적게 나올 경우 메모리를 초기화 하는 방법은 아래와 같다. To free pagecache(페이지캐쉬 초기화)echo 1 > /proc/sys/vm/drop_caches To fr.. 더보기
linux kernel 에서 사용 할 수 있는 file io functions 원칙적으로, linux kernel layer 에서는 file io 를 다루면 안된다. 여러 이유가 있겠지만, 일단 file descriptor list 를 각 task descriptor 에서 관리하고 있고, file을 linux kernel 단에서 접근하게 되면, 어느 process 에서 지금 kernel code 를 실행하는지 일일이 확인해야 하기 때문이다. 또한, 각 process 가 가진 access(read / write) 권한 문제도 발생하게 된다. 하지만, 이를 모두 감수하고라도, 꼭 써야만 하겠다면 다음 함수를 사용하면 된다. 여기에는 간단하게 동작하는 file operation 을 제공한다. open close size read write 더보기
linux user semaphore linux 의 user area 에서 사용하는 semaphore 에 대한 글 원문 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/system_programing/IPC/semaphores원문2 : http://www.hanbit.co.kr/network/view.html?bi_id=1399 목차 1 세마포어란 무엇인가1.1 세마포어의 작동원리2 System V 세마포어2.1 세마포어의 사용2.2 세마포어의 관리2.3 semget 을 이용해서 세마포어를 만들자.2.4 세마포어를 이용해서 접근제어 하기2.5 세마포어 조작2.6 예제3 POSIX 세마포어3.1 세마포어 만들기3.2 세마포어 얻기 (기다리기)3.3 세마포어 정보 가져오기3.4 세마포어 되돌려.. 더보기
사용가용한 physical memory block 을 얻어오는 방법 /sys/devices/system/memory/ 의 메모리들 /sys/devices/system/memory# ls block_size_bytes memory14 memory32 memory4 memory47 memory54 memory61 memory8 hard_offline_page memory15 memory33 memory40 memory48 memory55 memory62 memory9 memory0 memory16 memory34 memory41 memory49 memory56 memory63 probe memory1 memory17 memory35 memory42 memory5 memory57 memory64 soft_offline_page memory10 memory18 memory36 .. 더보기
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.. 더보기
class 에 sysfs node 등록하여 사용하기 linux kernel 에서 kernel 단과 user 사이에 통신을 위한 방법중에 sysfs node 를 사용하는 방법이 있다.지원하는 함수는 아래 3가지 함수들이 있다. devclass_create_filedevice_create_file class_create_file 이중 devclass_create_file 은 삭제된 것으로 보인다.class_create_file 의 예제를 첨부한다. #include #include #include #include #include #include #include #include static dev_t first; // Global variable for the first device number static struct cdev c_dev; // Global v.. 더보기
demand paging page fault 가 발생하면 demand paging 이 일어나게 된다. 요구 페이징은 필요한 프로그램만 메모리에 적재하는 방법으로 가상 메모리 시스템에서 많이 사용된다. 요구 페이징을 사용하는 가상메모리에서는 페이지들이 실행 과정에서 실제로 필요해질 때 적재 된다.[출처] 가상 메모리 요구 페이징(Demand Paging)|작성자 SungWook Kang http://sqlmvp.kr/140191934297 더보기
리눅스커널의메모리관리 원문 : https://www.linux.co.kr/home2/board/subbs/board.php?bo_table=lecture&wr_id=1641 linux virtual memory 에 대한 너무 좋은 강좌 꼭 한번 읽어보시길 Step by Step 커널 프로그래밍 강좌③ 리눅스커널의메모리관리 지난 호에 우리는 커널 모듈 프로그래밍에 관한 기본적인 것들을 살펴보았다. 이번 호 에서는 지난 번 모듈 프로그래밍에 이어 커널에서 가장 흔히 사용하는 함수 중의 하나 인 kmalloc을 통해 커널에서 시스템의 메모리를 어떻게 관리하는지 알아보기로 한다. 글 _ 김민찬 KLDP 멤버, 전문 프로그래머 연재 순서 ① 커널 프로그래밍 환경 구축하기와 특징 ② 모듈 구현하기 ③ 리눅스 커널의 메모리 관리 ④ 커널.. 더보기