Tag Archives: glibc

eventfd 소개

리눅스에서 비단 부모 자식 프로세스간 통신 뿐 아니라, 쓰레드간 메시지 전달에도 pipe()를 자주 이용합니다. 읽거나 쓸때 별도로 뮤텍스로 보호해줄 필요가 없기 때문이기도 하지만, 무엇보다도 poll(), select(), epoll() 등과 함께 사용할 수 있기 때문입니다. 예를 들어 예전에 적었던 GLib 쓰레드 프로그래밍에서 쓰레드간 통신에 g_async_queue()를 … Continue reading Continue reading

Posted in Development | Tagged , , | Comments Off

도메인 메일 호스트(MX) 주소 얻기

예를 들어 nobody@hades.net이라는 메일 주소의 서버는 hades.net인 것 같지만 실제로 메일을 호스팅하는 서버는 해당 도메인 서버에 질의해서 MX 레코드에 기록된 호스트를 찾아야 합니다. 그리고 이 작업을 위해 DNS 관련 프로토콜을 직접 구현하거나. djbdns 등과 같은 라이브러리를 이용합니다. 그런데, 요즘 기존 … Continue reading Continue reading

Posted in Development | Tagged , , | Comments Off

파일 공간 미리 할당하기

비단 비트토런트(BitTorrent)나 어뮬(aMule) 같은 P2P 응용 프로그램이 아니라도 파일 크기를 (대략이라도) 미리 알고 있을 경우, 디스크 공간을 미리 할당해서 단편화(fragmentation)를 줄이는 것은 물 Continue reading

Posted in Development | Tagged , , | Comments Off

리눅스 / 맥오에스에서 CPU 갯수 얻기

Linux / MacOS X 플랫폼에서 CPU 갯수를 얻어오는 함수입니다. 잊어버릴까봐 기록해 둡니다.

#include <stdio.h>
#ifdef __linux__
#include <sys/sysinfo.h>
#else
#ifdef __APPLE__
#include <sys/param.h>
#include <sys/sysctl.h>
#else
#error "Only Linux or OSX is supported!"
#endif /* __APPLE__ */
#endif /* __linux__ */
 
static int
get_cpu_nr (void)
{
#ifdef __linux__
return get_nprocs ();
#endif
#ifdef __APPLE__
int i = 0;
size_t s = sizeof (i);
if (sysctlbyname ("hw.ncpu", &i, &s, [...] Continue reading

Posted in Development | Tagged , , | Comments Off