'Fork'에 해당되는 글 2건

  1. 2010.01.08 mount.cifs mount.ntfs 등 자동연결의 비밀(?)
  2. 2008.12.08 fork : Not Enough Memory 2
Linux2010. 1. 8. 16:26
# mount -t ntfs-3g

머.. 이런식으로 실행하면 자동으로 mount.ntfs-3g 라는 파일을 찾아서 실행을 한다.
처음에는 오 졸라 신기해!!! 하면서 뻘짓으로 ..

make 과정중에 나온 intall-exec-hook 인줄 알고 파고 들었다가 웬걸 ㄱ-
아무튼 install-exec-hook은 설치후 trigger 식으로 실행해주는 루틴을 의미할 뿐,
execution hook 이랑은 연관이 없다. (젠장 된장 미네랄!)
[링크 : http://wiki.kldp.org/wiki.php/DocbookSgml/Autotools-KLDP]

아무튼, linux kernel utils 를 검색해서 mount.c 를 열어보니 busybox와는 다른 확연한 차이가 있었다.
일단 exec() 패밀리와 fork()를 사용하는 루틴의 존재유무

util-linux-2.12r/mount/mount.c

static int
check_special_mountprog(const char *spec, const char *node, const char *type,
			int flags, char *extra_opts, int *status) {
  char mountprog[120];
  struct stat statbuf;
  int res;

  if (!external_allowed)
      return 0;

  if (type && strlen(type) < 100) {
       sprintf(mountprog, "/sbin/mount.%s", type);
       if (stat(mountprog, &statbuf) == 0) {
	    res = fork();
	    if (res == 0) {
		 const char *oo, *mountargs[10];
		 int i = 0;

		 setuid(getuid());
		 setgid(getgid());
		 oo = fix_opts_string (flags, extra_opts, NULL);
		 mountargs[i++] = mountprog;
		 mountargs[i++] = spec;
		 mountargs[i++] = node;
		 if (nomtab)
		      mountargs[i++] = "-n";
		 if (verbose)
		      mountargs[i++] = "-v";
		 if (oo && *oo) {
		      mountargs[i++] = "-o";
		      mountargs[i++] = oo;
		 }
		 mountargs[i] = NULL;
		 execv(mountprog, (char **) mountargs);
		 exit(1);	/* exec failed */
	    } else if (res != -1) {
		 int st;
		 wait(&st);
		 *status = (WIFEXITED(st) ? WEXITSTATUS(st) : EX_SYSERR);
		 return 1;
	    } else {
	    	 int errsv = errno;
		 error(_("mount: cannot fork: %s"), strerror(errsv));
	    }
       }
  }
  return 0;
}

위에 소스에서 보면

sprintf(mountprog, "/sbin/mount.%s", type);
res = fork();
execv(mountprog, (char **) mountargs);

mount -t ntfs 는 mount.ntfs 로
mount -t cifs 는 mount.cifs 로

-t type 으로 받은 인자를 이용하여 실행을 넘겨준다.



결론 : busybox에서는 mount 소스가 많이 간략화 되어있으므로
         표준 mount 파일에서 지원하는 mount.type 실행치환 기능을 지원하지 않는다.

[링크 : ftp://ftp.kernel.org/pub/linux/utils/util-linux/] 리눅스용 mount.c
[링크 : http://www.koders.com/c/fid840A8124E3B838F1EC7B690C35A7A6F9BF10277B.aspx] busybox용 mount.c

'Linux' 카테고리의 다른 글

linux에 연결된 HDD의 IO 상태보기  (0) 2010.01.11
fork-exec 종료시 리턴값  (0) 2010.01.11
ntfs-3g 크로스 컴파일 하기 (ntfs-3g cross compile)  (0) 2010.01.07
FUSE 넌 머냐?  (0) 2010.01.07
ntfs-3g at Tuxera  (0) 2010.01.06
Posted by 구차니
Linux2008. 12. 8. 15:56
리눅스에서 프로그램을 실행 시키는 방법은
fork() / exec() 로 하는 방법과 system() 으로 하는 방법이 있다고 한다.
(내가 직접해본게 아니니 발뺌하기 모드 -.-v)

아무튼 fork()의 경우 parent 의 메모리를 복사해서(COW - Copy On Write) 사용하므로 메모리의 낭비가 생기는데,
이런 이유로 메모리가 넉넉해 보임에도
"fork 시에 ENOMEM 을 뱉어 내고 실행을 못한다"면 fork 대신에 vfork를 사용하면 된다.


어플리케이션 서브프로세스를 생성할때 메모리 사용량 최대로 줄이기
Greg Nakhimovsky, 2006년 5월

Fork의 퍼포먼스
...
fork()exec() 에 뒤따라 바로 살행되는 fork/exec 모델의 단점을 다루기 위해 버클리 버젼의 유닉스(BDS)는 1980년대 초반에 vfork() 시스템 콜을 내놓았습니다. vfork(2)부모 프로세스를 자식 프로세스에 카피하지 않습니다. 두 프로세스가 모두 부모의 가상 주소 공간을 공유 합니다; 부모 프로세스는 자식 프로세스가 종료 되거나 exec() 를 호출할때 까지 정지 상태로 들어 갑니다.
...
오랜 시간이 지난후에 멀티쓰레딩(MT)이 가능해 지고 많이 사용되면서 vfork() 가 어플리케이션이 여러개의 쓰레드를 가지고 있을때 새로운 문제를 일으킬 수 있음이 밝혀 졌습니다: 데드락.

메모리 overcommit: 솔라리스 vs 다른 운영체제들

몇몇 운영체제 (리눅스, IBM AIX, HP-UX 같은) 들은 memory overcommit 이라는 기능을 가지고 있습니다.( lazy swap allocation 이라고도 불림) memory overcommit 모드에서 malloc()스왑스페이스를 예약하지 않고 시스템에 충분한 VM이 있든 없든 항상 NULL 이 아닌 포인터를 리턴 합니다.

...

리눅스 커널 버젼 2.6과 그후에 버젼에서는 이론적으로 커널의 동작을 수정할 수 있는 방법이 존재 합니다. 그러므로 overcommit memory 가 발생하지 않을 것입니다. 이것은 strict overcommit modesysctl을 통해 조정함으로써 가능합니다:

sysctl -w vm.overcommit_memory=2

혹은 동일한 의미를 가지고 있는 vm.overcommit_memory=2/etc/sysctl.conf 에 삽입합니다.



[출처 : http://kr.sun.com/developers/solaris/techdocs/subprocess.html]

 Memory overcommit is a Linux kernel feature that lets applications allocate more memory than is actually available. The idea behind this feature is that some applications allocate large amounts of memory "just in case", but never actually use it. Thus, memory overcommit allows you to run more applications than actually fit in your memory, provided the applications don't actually use the memory they've allocated. If they do, then the kernel terminates the application.

[출처 : http://www.gnu.org/software/gnusound/Documentation/ar01s05.html]



Posted by 구차니