'Linux API > linux' 카테고리의 다른 글
| linux kernel governor 관련 코드 (0) | 2018.04.17 |
|---|---|
| linux shared memory 관련 (0) | 2016.12.22 |
| pthread detach while (0) | 2016.12.20 |
| fd <-> fp 변환 (0) | 2016.10.07 |
| shared memory - linux/IPC (0) | 2016.06.28 |
| linux kernel governor 관련 코드 (0) | 2018.04.17 |
|---|---|
| linux shared memory 관련 (0) | 2016.12.22 |
| pthread detach while (0) | 2016.12.20 |
| fd <-> fp 변환 (0) | 2016.10.07 |
| shared memory - linux/IPC (0) | 2016.06.28 |
쓰레드 보다보니
공부는 해냐하는데 끄응 ㅜㅜ
암튼 쓰레드를 분리하면 자식 스레드가 종료시 자원을 반납하지만
분리할 쓰레드가 무한루프 돌면
메모리 누수로 이어지는 듯
프로세스는 종료되었고 그럼 프로세스로서 cpu를 할당받진 않을테나
해당 쓰레드가 공유하던 메모리만 붕 떠버리려나?
[링크 : http://www.joinc.co.kr/w/Site/system_programing/Book_LSP/ch07_Thread]
[링크 : http://stackoverflow.com/questions/25655706/how-to-terminate-or-stop-a-detached-thread-in-c]
| linux shared memory 관련 (0) | 2016.12.22 |
|---|---|
| linux ipc (0) | 2016.12.20 |
| fd <-> fp 변환 (0) | 2016.10.07 |
| shared memory - linux/IPC (0) | 2016.06.28 |
| 메시지 큐 - ipc (0) | 2016.06.28 |
int fileno(FILE *stream);
FILE *fdopen(int fd, const char *mode);
[링크 : http://stackoverflow.com/.../how-can-i-convert-a-file-pointer-file-fp-to-a-file-descriptor-int-fd]
[링크 : http://stackoverflow.com/.../how-to-get-a-file-pointer-from-a-file-descriptor]
| linux ipc (0) | 2016.12.20 |
|---|---|
| pthread detach while (0) | 2016.12.20 |
| shared memory - linux/IPC (0) | 2016.06.28 |
| 메시지 큐 - ipc (0) | 2016.06.28 |
| pthread mutex shm_open (0) | 2016.06.27 |
System V와 POSIX 차이
[링크 : http://stackcanary.com/?p=59]
System V
[링크 : http://linux.die.net/man/2/shmget]
[링크 : http://linux.die.net/man/2/shmat] attach
[링크 : http://linux.die.net/man/2/shmdt] detach
[링크 : http://linux.die.net/man/2/shmctl]
POSIX
System V shared memory (shmget(2), shmop(2), etc.) is an older shared memory API. POSIX shared memory provides a simpler, and better designed interface; on the other hand POSIX shared memory is somewhat less widely available (especially on older systems) than System V shared memory.
[링크 : http://linux.die.net/man/7/shm_overview]
[링크 : http://linux.die.net/man/3/shm_open]
| pthread detach while (0) | 2016.12.20 |
|---|---|
| fd <-> fp 변환 (0) | 2016.10.07 |
| 메시지 큐 - ipc (0) | 2016.06.28 |
| pthread mutex shm_open (0) | 2016.06.27 |
| 리눅스 동적 라이브러리(*.so) 사용하기 (0) | 2016.04.04 |
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
struct msgbuf {
long mtype; /* message type, must be > 0 */
char mtext[1]; /* message data */
};
int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);
int msgget(key_t key, int msgflg);
[링크 : http://linux.die.net/man/2/msgsnd]
[링크 : http://linux.die.net/man/2/msgget]
[링크 : http://www.joinc.co.kr/w/Site/system_programing/Book_LSP/ch08_IPC]
[링크 : http://www.joinc.co.kr/w/Site/system_programing/IPC/MessageQueue]
| fd <-> fp 변환 (0) | 2016.10.07 |
|---|---|
| shared memory - linux/IPC (0) | 2016.06.28 |
| pthread mutex shm_open (0) | 2016.06.27 |
| 리눅스 동적 라이브러리(*.so) 사용하기 (0) | 2016.04.04 |
| 리눅스 커널 모듈 관련 문서 (0) | 2015.11.06 |
pthread_mutexattr_destroy, pthread_mutexattr_init - destroy and initialize the mutex attributes object
[링크 : http://linux.die.net/man/3/pthread_mutexattr_init]
mutex 속성을 설정하여 프로세스간 mutex로도 사용이 가능
ret = pthread_mutexattr_setpshared(&mtx_attr, PTHREAD_PROCESS_SHARED);
[링크 : https://kldp.org/node/107186]
[링크 : http://stackoverflow.com/questions/4252005/what-is-the-attribute-of-a-pthread-mutex]
[링크 : http://mintnlatte.tistory.com/357] mmap
결론은.. 공유 메모리를 통해 mutex 키를 공유하여
다른 프로세스들과도 mutex가 가능하다?
| shared memory - linux/IPC (0) | 2016.06.28 |
|---|---|
| 메시지 큐 - ipc (0) | 2016.06.28 |
| 리눅스 동적 라이브러리(*.so) 사용하기 (0) | 2016.04.04 |
| 리눅스 커널 모듈 관련 문서 (0) | 2015.11.06 |
| readl(), writel() (0) | 2015.11.06 |
어떻게 보면 당연한..(?)
함수 포인터
#include <stdio.h> #include <dlfcn.h> #include "ctest.h" int main(int argc, char **argv) { void *lib_handle; double (*fn)(int *); int x; char *error; lib_handle = dlopen("/opt/lib/libctest.so", RTLD_LAZY); if (!lib_handle) { fprintf(stderr, "%s\n", dlerror()); exit(1); } fn = dlsym(lib_handle, "ctest1"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(1); } (*fn)(&x); printf("Valx=%d\n",x); dlclose(lib_handle); return 0; } |
[링크 : http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html]
| 메시지 큐 - ipc (0) | 2016.06.28 |
|---|---|
| pthread mutex shm_open (0) | 2016.06.27 |
| 리눅스 커널 모듈 관련 문서 (0) | 2015.11.06 |
| readl(), writel() (0) | 2015.11.06 |
| 리눅스 모듈 프로그래밍 관련 (0) | 2015.10.30 |
kmalloc() <-> kfree()
빌드 옵션
-c: 커널 모듈은 독립적으로 실행 가능한 파일이 아니며, insmod를 사용하여 실행 시간 중에 커널에 링크되는 오브젝트 파일 이다. 결론적으로 모듈은 -c옵션을 주고 컴파일 해야 한다. -O2: 커널은 인라인 함수를 주로 사용하기 때문에 모듈은 이 옵션 플래그를 사용해야 한다. 이 옵션을 사용하지 않은 경우 어떤 어셈블러 매크로는 함수 호출 시 정상적으로 작동하지 않을 것이다. insmod는 커널에서 원하는 함수를 찾지 못하고 결국 모듈의 적재는 실패할 것이다. -W -Wall: 프로그램에서의 실수는 당신의 시스템을 다운 시킬 수도 있다. 컴파일러 경고 기능은 항상 켜둬라, 이것은 모듈 컴파일 뿐 아니라 당신의 모든 컴파일 행위에 적용된다. -isystem /lib/modules/uname -r/build/include: 컴파일 대상이 되는 커널의 헤더를 사용해야만 한다. 기본적인 /usr/include/linux를 사용하는 것은 작동하지 않을 것이다. -DKERNEL:이 심볼을 정의 하는 것은 헤더 파일에 이 코드가 유저 프로세스로 동작하지 않고 커널 모드에서 작동한다는 사실을 알린다. -DMODULE: 이 심볼은 헤더 파일에 커널 모듈을 위한 올바른 정의를 하게 한다. |
이름을 정해준대로 쓰거나
int init_module(void); void cleanup_module(void); |
int hello_2_init(void); static void hello_2_exit(void); module_init(hello_2_init); module_exit(hello_2_exit); |
표준 라이브러리는 사용할 수 없다. 당신이 커널 모듈에서 사용 할 수 있는 함수는 /proc/ksyms에서 보이는 함수들 뿐이다.
[링크 : https://wiki.kldp.org/wiki.php/KernelModuleProgrammingGuide]
/proc/ksyms 가 2.6 에서는 /proc/kallsyms 로 바뀌었습니다.
[링크 : https://kldp.org/node/27882]
커널에서 FP 쪽은 데이터 주고 받는 용도로 써서 floating point 연산불가
math 라이브러리도 사용불가 -_-
[링크 : http://stackoverflow.com/.../how-to-include-math-h-include-math-h-on-kernel-source-file]
[링크 : http://hisjournal.net/./The_Linux_Kernel_Module_Programming_Guide_v2.6_by_YoonMin_Nam.pdf]
[링크 : http://www.joinc.co.kr/.../system_programing/proc/ProcFsPrograming] proc fs
| pthread mutex shm_open (0) | 2016.06.27 |
|---|---|
| 리눅스 동적 라이브러리(*.so) 사용하기 (0) | 2016.04.04 |
| readl(), writel() (0) | 2015.11.06 |
| 리눅스 모듈 프로그래밍 관련 (0) | 2015.10.30 |
| linux open mode (0) | 2015.10.29 |
커널 모듈 소스에서 보다 발견
결론은.. 걍 포인터?
[링크 : http://lxr.free-electrons.com/source/arch/mn10300/include/asm/io.h#L38]
109 #ifndef readb 110 #define readb readb 111 static inline u8 readb(const volatile void __iomem *addr) 112 { 113 return __raw_readb(addr); 114 } 115 #endif 116 117 #ifndef readw 118 #define readw readw 119 static inline u16 readw(const volatile void __iomem *addr) 120 { 121 return __le16_to_cpu(__raw_readw(addr)); 122 } 123 #endif 124 125 #ifndef readl 126 #define readl readl 127 static inline u32 readl(const volatile void __iomem *addr) 128 { 129 return __le32_to_cpu(__raw_readl(addr)); 130 } 131 #endif 132 133 #ifdef CONFIG_64BIT 134 #ifndef readq 135 #define readq readq 136 static inline u64 readq(const volatile void __iomem *addr) 137 { 138 return __le64_to_cpu(__raw_readq(addr)); 139 } 140 #endif 141 #endif /* CONFIG_64BIT */ 142 143 #ifndef writeb 144 #define writeb writeb 145 static inline void writeb(u8 value, volatile void __iomem *addr) 146 { 147 __raw_writeb(value, addr); 148 } 149 #endif 150 151 #ifndef writew 152 #define writew writew 153 static inline void writew(u16 value, volatile void __iomem *addr) 154 { 155 __raw_writew(cpu_to_le16(value), addr); 156 } 157 #endif 158 159 #ifndef writel 160 #define writel writel 161 static inline void writel(u32 value, volatile void __iomem *addr) 162 { 163 __raw_writel(__cpu_to_le32(value), addr); 164 } 165 #endif 166 167 #ifdef CONFIG_64BIT 168 #ifndef writeq 169 #define writeq writeq 170 static inline void writeq(u64 value, volatile void __iomem *addr) 171 { 172 __raw_writeq(__cpu_to_le64(value), addr); 173 } 174 #endif 175 #endif /* CONFIG_64BIT */ [링크 : http://lxr.free-electrons.com/source/include/asm-generic/io.h#L127] |
| 리눅스 동적 라이브러리(*.so) 사용하기 (0) | 2016.04.04 |
|---|---|
| 리눅스 커널 모듈 관련 문서 (0) | 2015.11.06 |
| 리눅스 모듈 프로그래밍 관련 (0) | 2015.10.30 |
| linux open mode (0) | 2015.10.29 |
| named pipe / mkfifo() (0) | 2015.10.27 |
int register_blkdev (unsigned int major, const char * name);
[링크 : https://www.kernel.org/doc/htmldocs/kernel-api/API-register-blkdev.html]
int __register_chrdev ( unsigned int major,
unsigned int baseminor,
unsigned int count,
const char * name,
const struct file_operations * fops);
[링크 : http://linux.die.net/lkmpg/x892.html]
[링크 : http://linux.die.net/lkmpg/x569.html]
[링크 : https://wiki.kldp.org/KoreanDoc/html/EmbeddedKernel-KLDP/device-understanding.html]
| 리눅스 커널 모듈 관련 문서 (0) | 2015.11.06 |
|---|---|
| readl(), writel() (0) | 2015.11.06 |
| linux open mode (0) | 2015.10.29 |
| named pipe / mkfifo() (0) | 2015.10.27 |
| signal (0) | 2015.10.26 |