ERRORS EACCES The requested access to the file is not allowed, or search permission is denied for one of the directories
in the path prefix of pathname, or the file did not exist yet and write access to the parent directory is
not allowed. (See also path_resolution(2).)
EEXIST pathname already exists and O_CREAT and O_EXCL were used.
EFAULT pathname points outside your accessible address space.
EISDIR pathname refers to a directory and the access requested involved writing (that is, O_WRONLY or O_RDWR is
set).
ELOOP Too many symbolic links were encountered in resolving pathname, or O_NOFOLLOW was specified but pathname was
a symbolic link.
EMFILE The process already has the maximum number of files open.
ENAMETOOLONG
pathname was too long.
ENFILE The system limit on the total number of open files has been reached.
ENODEV pathname refers to a device special file and no corresponding device exists. (This is a Linux kernel bug;
in this situation ENXIO must be returned.)
ENOENT O_CREAT is not set and the named file does not exist. Or, a directory component in pathname does not exist
or is a dangling symbolic link.
ENOMEM Insufficient kernel memory was available.
ENOSPC pathname was to be created but the device containing pathname has no room for the new file.
ENOTDIR
A component used as a directory in pathname is not, in fact, a directory, or O_DIRECTORY was specified and
pathname was not a directory.
ENXIO O_NONBLOCK | O_WRONLY is set, the named file is a FIFO and no process has the file open for reading. Or,
the file is a device special file and no corresponding device exists.
EOVERFLOW
pathname refers to a regular file, too large to be opened; see O_LARGEFILE above.
EPERM The O_NOATIME flag was specified, but the effective user ID of the caller did not match the owner of the
file and the caller was not privileged (CAP_FOWNER).
EROFS pathname refers to a file on a read-only filesystem and write access was requested.
ETXTBSY
pathname refers to an executable image which is currently being executed and write access was requested.
EWOULDBLOCK
The O_NONBLOCK flag was specified, and an incompatible lease was held on the file (see fcntl(2)).
access()
DESCRIPTION
mode is a mask consisting of one or more of R_OK, W_OK, X_OK and F_OK.
R_OK, W_OK and X_OK request checking whether the file exists and has read, write and execute permissions,
respectively. F_OK just requests checking for the existence of the file.
ERRORS
access() shall fail if:
EACCES The requested access would be denied to the file or search permission is denied for one of the directories in
the path prefix of pathname. (See also path_resolution(2).)
ELOOP Too many symbolic links were encountered in resolving pathname.
ENAMETOOLONG
pathname is too long.
ENOENT A directory component in pathname would have been accessible but does not exist or was a dangling symbolic
link.
ENOTDIR
A component used as a directory in pathname is not, in fact, a directory.
EROFS Write permission was requested for a file on a read-only filesystem.
access() may fail if:
EFAULT pathname points outside your accessible address space.
EINVAL mode was incorrectly specified.
EIO An I/O error occurred.
ENOMEM Insufficient kernel memory was available.
ETXTBSY
Write access was requested to an executable which is being executed.
fstat()
ERRORS EACCES Search permission is denied for one of the directories in the path prefix of path. (See also path_resolu-
tion(2).)
EBADF filedes is bad.
EFAULT Bad address.
ELOOP Too many symbolic links encountered while traversing the path.
ENAMETOOLONG
File name too long.
ENOENT A component of the path path does not exist, or the path is an empty string.
ENOMEM Out of memory (i.e. kernel memory).
ENOTDIR
A component of the path is not a directory.
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] 부터는 인자를 넘겨 주면 된다.
리눅스에서 프로그램을 실행 시키는 방법은
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() 가 어플리케이션이 여러개의 쓰레드를 가지고 있을때 새로운 문제를 일으킬 수 있음이 밝혀 졌습니다: 데드락.
몇몇 운영체제 (리눅스, IBM AIX, HP-UX 같은) 들은
memory overcommit 이라는 기능을 가지고 있습니다.( lazy swap allocation 이라고도 불림) memory
overcommit 모드에서 malloc() 은 스왑스페이스를 예약하지 않고 시스템에 충분한 VM이 있든 없든 항상NULL 이 아닌 포인터를 리턴 합니다.
...
리눅스 커널 버젼 2.6과 그후에 버젼에서는 이론적으로 커널의 동작을 수정할 수 있는 방법이 존재 합니다. 그러므로 overcommit memory 가 발생하지 않을 것입니다. 이것은 strict overcommit mode 을 sysctl을 통해 조정함으로써 가능합니다:
sysctl -w vm.overcommit_memory=2
혹은 동일한 의미를 가지고 있는 vm.overcommit_memory=2 을 /etc/sysctl.conf 에 삽입합니다.
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.
일단 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
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
리눅스에서 파일을 완전 소거 하는 방법이 필요 해서 검색을 해봤더니
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.