'Linux'에 해당되는 글 766건

  1. 2008.12.08 execl() - excute a file
  2. 2008.12.08 fork : Not Enough Memory 2
  3. 2008.11.21 mkfs - ext2 & ext3 4
  4. 2008.11.10 SRM - Secure RM
  5. 2008.11.07 Fedora Core 9 의 차이점 6
  6. 2008.11.04 리눅스에서 디렉토리 이름 변경시 주의사항 2
Linux2008. 12. 8. 16:20

#include <unistd.h>

int execl(const char *path, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);
int execle(const char *path, const char *arg,  ..., char * const envp[]);
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);


The  functions  execlp()  and execvp() will duplicate the actions of the shell in searching for an executable file if
the specified filename does not contain a slash (/) character.  The search path is the path specified in the environ-
ment  by the PATH variable.  If this variable isn’t specified, the default path ‘‘:/bin:/usr/bin’’ is used.  In addi-
tion, certain errors are treated specially.

[출처 : man page]

execl의 경우에는 path가 들어 가는데 arg에서 문제가 생긴다.




execl은 잠시 잊고 잠시 C언어로 돌아가서 main()의 프로토 타입을 생각해보자
 int void(int argc, char **argv)
그리고 argv[0] argv[1]의 내용을 떠올려 보자
argv[0]은 실행한 파일의 이름이 argv[1] 부터 인자가 넘어 오지 않았던가!




다시 execl로 돌아와서
int execl(const char *path, const char *arg, ...);
path에서는 파일 이름이 포함 된 경로를 적어주고, arg[0]에는 파일 이름 arg[1] 부터는 인자를 넘겨 주면 된다.


간단한 예를 들자면
 execl("/bin/ls","ls","-al",0);
로 실행을 하면된다.

마지막의 0은 '\0' == NULL 이다.


[참고 : http://kldp.org/node/1548]
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 구차니
Linux2008. 11. 21. 11:29

일단 mkfs는 DOS로 치자면 format 명령인데
linux에서는 ext2는 이제 잘 안쓰고 ext3를 주로 쓴다.

흥미롭게도 mkfs 과정중에 mkfs.ext2 와 mkfs.ext3 의 결과의 차이가 한줄 뿐이라는 사실을 발견했다.
그리고 부가적으로는 자동으로 체크하는 mount 횟수의 차이도 있다.


[root@localhost mnt]# mkfs.ext2 /dev/sda2
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
3842720 inodes, 7679070 blocks
383953 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
235 block groups
32768 blocks per group, 32768 fragments per group
16352 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 [root@localhost mnt]# mkfs.ext3 /dev/sda3
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2093056 inodes, 4178908 blocks
208945 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4282384384
128 block groups
32768 blocks per group, 32768 fragments per group
16352 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.





사진 : 클릭하면 크게 보입니다!
Posted by 구차니
Linux2008. 11. 10. 15:11
리눅스에서 파일을 완전 소거 하는 방법이 필요 해서 검색을 해봤더니
sourceforge project로 SRM이라는 것이 발견 되었다.

rpm 버전이 있는지는 모르겠고,
make install로 설치를 하도록 되어 있다.

 srm(1)                                                                  srm(1)

NAME
       srm - securely remove files or directories

SYNOPSIS
       srm [OPTION]... FILE...

DESCRIPTION
       srm  removes each specified file by overwriting, renaming, and truncat-
       ing it before unlinking. This prevents other people from undeleting  or
       recovering  any  information  about  the file from the command line. By
       default srm uses 35 passes to overwrite the file?셲  contents.  If  this
       seems  overkill  you  can  use  use  the --dod or --openbsd or --simple
       option which use less passes.

       srm, like every program that uses the  getopt  function  to  parse  its
       arguments,  lets  you  use the -- option to indicate that all following
       arguments are non-options.  To remove a file called ??f??in the current
       directory, you could type either
              rm -- -f
       or
              rm ./-f

OPTIONS
       Remove (unlink) the FILE(s).

       -d, --directory
              ignored (for compatability with rm(1))

       -f, --force
              ignore nonexistent files, never prompt

       -i, --interactive
              prompt before any removal

       -r, -R, --recursive
              remove the contents of directories recursively

       -s, --simple
              only overwrite the file with a single pass of random data

       -P, --openbsd
              OpenBSD  compatible  rm. Overwrite regular files before deleting
              them.  Files are overwritten three times, first  with  the  byte
              pattern  0xff,  then  0x00, and then 0xff again, before they are
              deleted.  Files with multiple links will  be  unlinked  but  not
              overwritten.

       -D, --dod
              Dod compliant 7-pass overwrite.

       -v, --verbose
              explain what is being done

       -h, --help
              display this help and exit

       -V, --version
              output version information and exit

NOTES
       srm can not remove write protected files owned by another user, regard-
       less of the permissions on the directory containing the file.

       Development and discussion of srm  is  carried  out  at
       http://source-forge.net/project/?group_id=3297   which   is   also   accessible   via
       http://srm.sourceforge.net.

SEE ALSO
       rm(1)

Matt Gauthier                        1.2.9                              srm(1)


윈도우용 완전 소거 프로그램과 비슷하게
소거 알고리즘에 의해서 7pass / 35pass으로 삭제 하며, 기본값은 35pass 라고 되어 있다.

[주소 : http://srm.sourceforge.net/]

----
2011.10.24 추가
우분투에서는 secure-delete 패키지로 존재한다. 
Posted by 구차니
Linux/Fedora Core2008. 11. 7. 12:15
생각을 해보니.. 회사 서버랑은 Fedora Core 8 이었는데..
일단 조금은더 Ubuntu 스러워졌다.(욕아님)

일단 보안 강화를 위해서 Gnome 자체에서 권한을 상당히 자주 물어 보게 되고,
X-windows 로그인시 Root로 로그인을 할 수 없다.(LiveCD에서 이미 겪었었지만..
실제 Live가 아닌 것에도 적용이 될줄이야 ㄱ-)

결정적으로 SCIM이 없다(다국어 입력기). 한글로 설정하면 한글은 잘나오는데 입력할 방법이 없다 ㄱ-

검색을 해보니 SCIM으로는 linux 네이트온 한글 입력이 안된다고 하는데
nabi 라는 녀석을 추천해 주던데 이녀석은 libhangul.so 종속성 땜시 이것저것 요청해서 귀차니즘.



결론 : 리눅스는 역시.. gcc 없으면 단팥없는 호빵.. 프로그램 설치를 위해서라도 반드시 gcc가 필요 하다
결론2 : 그러니까 오늘 다시 포맷 OTL 덤으로 윈도우로 파티션 조정? ㅠ.ㅠ
Posted by 구차니
Linux2008. 11. 4. 14:43
졸지에 낙시글이 되것 같아. 디렉토리 이름 변경하는 방법 급조 -ㅁ-
리눅스에서는 엄밀하게 디렉토리 이름 바꾸는 방법은 존재하지 않습니다.
리눅스의 모든 것들은 파일로 관리 되기 때문이죠.

그런 이유로 리눅스에서 디렉토리 이름을 변경하려면 mv
다른 이름으로 디렉토리를 옮기면 됩니다.

예) test_1 디렉토리를 test_opps로 바꾸기
$ mv test_1 test_oops

---------------------------------------------
오늘 작업을 하다가 신기한 현상을 발견했다.

리눅스에서 컴파일 하고, 윈도우에서 samba와 cvs로 관리하는 시스템인데,
리눅스 에서 열어 놓은 디렉토리를 윈도우에서 다른 이름으로 변경하고
리눅스에서 열린 디렉토리의 이름으로 cvs checkout을 했다.(그러니까 백업본을 가져왔다)

그리고 나서 소스를 변경하고 다시 컴파일 하는데, 변경사항이 없음?!?!?!
먼가 이상해서 경로를 빠져 나왔다가 다시 들어 가니 그 제서야 제대로 컴파일이 된다.

결론만 말하자면, linux에서 directory는 이름으로 확인하는것이 아니라 inode로 확인하므로,
다른 곳에서 디렉토리를 수정했을 경우, 반드시 cd 명령어로 다시 경로를 이동해서 사용하자!!


삭제 테스트
step 1. 임의의 디렉토리를 만든다. (귀찮으니 tt라고 하자)
           [user@hostname ~] $ mkdir tt

step 2. 임의의 디렉토리로 들어간다.
           [user@hostname ~] $ cd tt

step 3. 임의의 디렉토리의 inode를 확인해본다.
           [user@hostname tt] $ ls -ali
           11044597 drwxrwxr-x 2 user hostname 4096 Nov  4 14:38 .
            3866626 drwxrwxrwx 9 user hostname 4096 Nov  4 14:38 ..

step 4. 임의의 디렉토리를 다른 콘솔이나 윈도우의 다른 창에서 삭제한다.

step 5. 다시 inode를 출력해본다.
           [user@hostname tt] $ ls -ali
           total 0

step 6. 현재 경로를 알아본다.
           [user@hostname tt] $ pwd
           /home/user/tt

'Linux' 카테고리의 다른 글

파일 존재 유무 확인하기(how to check existence of file on C,linux)  (2) 2008.12.16
execl() - excute a file  (0) 2008.12.08
fork : Not Enough Memory  (2) 2008.12.08
mkfs - ext2 & ext3  (4) 2008.11.21
SRM - Secure RM  (0) 2008.11.10
Posted by 구차니