Linux2009. 12. 7. 17:07
# /usr/sbin/lsof
COMMAND     PID      USER   FD      TYPE     DEVICE     SIZE       NODE NAME
init          1      root  cwd       DIR      253,0     4096          2 /
init          1      root  rtd       DIR      253,0     4096          2 /
init          1      root  txt       REG      253,0    38620   10322027 /sbin/init
init          1      root  mem       REG      253,0    89408    6882935 /lib/libselinux.so.1
init          1      root  mem       REG      253,0   121652    6882916 /lib/ld-2.5.so
init          1      root  mem       REG      253,0  1589336    6882917 /lib/i686/nosegneg/libc-2.5.so
init          1      root  mem       REG      253,0    16528    6882918 /lib/libdl-2.5.so
init          1      root  mem       REG      253,0   245376    6882934 /lib/libsepol.so.1
init          1      root   10u     FIFO       0,15                 996 /dev/initctl

lsof는 열린파일의 목록을 보여준다.
umount 실패를 찾다가 나온 유틸리티이다.

음.. 일단 /proc 에서 프로세스 별로 fd를 확인해도 되겠지만 노가다이니 이런 착한 프로그램을 이용해 주어야한다!

[링크 : http://linux.die.net/man/8/lsof]


certcc 문서의 본래 링크를 못찾아서 대체링크
[링크 : http://unix.co.kr/bbs/board.php?bo_table=02_06&wr_id=6]

'Linux' 카테고리의 다른 글

USB가 읽기전용이 되었어요! (FAT rw -> ro)  (6) 2009.12.07
umount(), umount  (0) 2009.12.07
filesystem - msdos, vfat, umsdos  (0) 2009.12.06
/proc/net/route 파싱  (0) 2009.11.30
좀비 프로세스 생성하기(!)  (0) 2009.11.20
Posted by 구차니
Linux2009. 12. 6. 16:36
리눅스 마스터 보는데 umsdos라는 파일 시스템이 나오길래
첨들어서 틀렸다고 하려다가, 다른 더 수상한 녀석이 있어서 일단 패스 했는데
시험보고 나와서 검색을 해보니, 존재하긴 하는데 음..

UMSDOS filesystem

Ok, here is just a quick informational page about Linux UMSDOS filesystem.
Please note that all work on UMSDOS (or UVFAT) in 2.6.x kernels has stopped and is non-working. They should work ok in 2.4.x kernels, but I've haven't heard for some time from users (assuming some are still existing :)
Last change: 06 Mar 2006

[링크 : http://linux.voyager.hr/umsdos/]

구버전용인데.. 왜 몰랐을까?


One of the user experience goals for the designers of Windows 95 was the ability to use long filenames (LFNs—up to 255 UTF-16 code points long), in addition to classic 8.3 filenames. LFNs were implemented using a workaround in the way directory entries are laid out (see below).

The version of the file system with this extension is usually known as VFAT after the Windows 95 virtual device driver, also known as "Virtual FAT" in Microsoft's documentation. Interestingly, the VFAT driver actually appeared before Windows 95, in Windows for Workgroups 3.11, but was only used for implementing 32-bit file access and did not support long file names.

In Windows NT, support for long filenames on FAT started from version 3.5. OS/2 added long filename support to FAT using extended attributes (EA) before the introduction of VFAT; thus, VFAT long filenames are invisible to OS/2, and EA long filenames are invisible to Windows.


[링크: http://en.wikipedia.org/wiki/File_Allocation_Table]



[링크 : http://en.wikipedia.org/wiki/FAT_filesystem_and_Linux]

'Linux' 카테고리의 다른 글

umount(), umount  (0) 2009.12.07
lsof - list Open File  (0) 2009.12.07
/proc/net/route 파싱  (0) 2009.11.30
좀비 프로세스 생성하기(!)  (0) 2009.11.20
ps에서 [프로세스] 의 의미 - bracket process name in ps  (0) 2009.11.20
Posted by 구차니
Linux2009. 11. 30. 16:53
본것중에 가장 간단하게 /proc/net/route를 파싱하는 소스인 듯하다.

# cat /proc/net/route
Iface   Destination     Gateway         Flags   RefCnt  Use     Metric  Mask            MTU     Window  IRTT
eth0    000AA8C0        00000000        0001    0       0       0       00FFFFFF        0       0       0
eth0    00000000        010AA8C0        0003    0       0       0       00000000        0       0       0

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.10.0    *               255.255.255.0   U     0      0        0 eth0
default         192.168.10.1    0.0.0.0         UG    0      0        0 eth0

아무튼 route로 출력하는 default가 UG 플래그로 default gateway이며,
파일에서는 Destination과 Mask가 0x00000000 인 녀석이 default gateway이다.

#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"

#define IP_PRINT(a) \
    *((unsigned char *)(&a)), \
    *(((unsigned char *)(&a)) + 1), \
    *(((unsigned char *)(&a)) + 2), \
    *(((unsigned char *)(&a)) + 3)

int main()
{
    FILE* fp = fopen("/proc/net/route", "r");
    char buf[256];
    static char iface[256];
    unsigned int destination, gateway, flags, refcnt, use, metric, mask;
    int ret;

    if (fp == NULL)
        exit(-1);

    while (fgets(buf, 255, fp)) {
        if (!strncmp(buf, "Iface", 5))
            continue;

        ret = sscanf(buf, "%s\t%x\t%x\t%d\t%d\t%d\t%d\t%x",
                    iface, &destination, &gateway, &flags,
                    &refcnt, &use, &metric, &mask);

        if (ret < 8) {
            fprintf(stderr, "ERROR: line read error\n");
            continue;
        }

        if (destination != 0) {
            fprintf(stderr, "%s: gateway %u.%u.%u.%u, "
                    "destination %u.%u.%u.%u netmask %u.%u.%u.%u\n",
                    iface,
                    IP_PRINT(gateway),
                    IP_PRINT(destination),
                    IP_PRINT(mask));
            continue;
        }

        if (mask != 0) {
            fprintf(stderr, "%s: gateway %u.%u.%u.%u, default, "
                    "but have netmask %u.%u.%u.%u???\n",
                    iface,
                    IP_PRINT(gateway),
                    IP_PRINT(mask));
            continue;
        }

        fprintf(stderr, "%s: gateway %u.%u.%u.%u, default\n",
                iface,
                IP_PRINT(gateway));
    }
    fclose(fp);
}


[링크 : http://elenoa.tistory.com/72]

'Linux' 카테고리의 다른 글

lsof - list Open File  (0) 2009.12.07
filesystem - msdos, vfat, umsdos  (0) 2009.12.06
좀비 프로세스 생성하기(!)  (0) 2009.11.20
ps에서 [프로세스] 의 의미 - bracket process name in ps  (0) 2009.11.20
ps - Process Status  (2) 2009.11.20
Posted by 구차니
Linux2009. 11. 20. 16:23
마지막으로 소스를 대충 보면, wait()를 하는 부분이 없네요. TestA가 daemon 형태로 re-parent한다면 상관없겠지만, 그렇지 않다면 아마 zombie 프로세스가 될 듯 합니다. zombie를 막으려면 daemon 형태로 만들거나, wait()로 child process의 return을 받아야 합니다. 그리고 이 때, SIGCHLD를 비롯, signal 처리를 하려면 pthread_sigmask() 등을 써서, signal을 원하지 않은 thread에서는 해당 시그널이 발생하지 않도록 block시켜야 합니다.

[링크 : http://kldp.org/node/103568]

All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed. A state change is considered to be: the child terminated; the child was stopped by a signal; or the child was resumed by a signal. In the case of a terminated child, performing a wait allows the system to release the resources associated with the child; if a wait is not performed, then terminated the child remains in a "zombie" state (see NOTES below).

[링크 : http://linux.die.net/man/2/waitpid]

프로세스 생성하고 parent에서 waitpid 하지 않으면 좀비가 생성된다.
ps 치면 Zombie 들이 우글우글 -ㅁ-
Posted by 구차니
Linux2009. 11. 20. 15:46
Kernel Threads

Sometimes the process args will be unavailable; when this is happens, ps will instead print the executable name in brackets.

This is correct, try execl(program_path, NULL) and you will see your process listed in brackets.

[링크 : http://www.linuxquestions.org/questions/linux-newbie-8/square-brackets-in-output-of-ps-aux-not-matching-output-of-ps-ejh-716134/]

Low PIDs. Very perceptive of you. Low PIDs usually denote a process started by init on boot

[링크 : http://www.linuxquestions.org/questions/linux-general-1/ps-process-names-in-brackets-644364/]


딱히 이렇다할 편한 대답은 없는데..
아무튼 부팅시에 구동된 낮은 번호의 PID를 지는 프로세스와, (낮은 숫자가 아니어도.. 되긴한다)
 root     29953    11  0 Nov17 ?        00:00:00     [pdflush]
커널 쓰레드가 []를 둘러 싼다고 하는데
 root      1936     1  0 Oct05 ?        00:00:12   [nfsd]

일단은 전반적으로 root가 돌리는 데몬 프로세스 라는 유사성이 있다.
자세한 내용은 나중에 검색해서 추가해야겠다.
Posted by 구차니
Linux2009. 11. 20. 15:26
state     The state is given by a sequence of characters, for example, "RWNA". The first character indicates the run state of the process:

D     Marks a process in disk (or other short term, uninterruptible) wait.
I     Marks a process that is idle (sleeping for longer than about 20 seconds).
L     Marks a process that is waiting to acquire a lock.
R     Marks a runnable process.
S     Marks a process that is sleeping for less than about 20 seconds.
T     Marks a stopped process.
W     Marks an idle interrupt thread.
Z     Marks a dead process (a "zombie").

Additional characters after these, if any, indicate additional state information:

+     The process is in the foreground process group of its control terminal.
<     The process has raised CPU scheduling priority.
E     The process is trying to exit.
J     Marks a process which is in jail(2). The hostname of the prison can be found in /proc/<pid/status>.
L     The process has pages locked in core (for example, for raw I/O).
N     The process has reduced CPU scheduling priority (see setpriority(2)).
s     The process is a session leader.
V     The process is suspended during a vfork(2).
W     The process is swapped out.
X     The process is being traced or debugged.

[링크 : http://www.gsp.com/cgi-bin/man.cgi?section=1&topic=ps]


Posted by 구차니
Linux2009. 11. 20. 13:49
#include <sys/param.h>
#include <libutil.h>

struct pidfh *pidfile_open(const char *path, mode_t mode, pid_t *pidptr);
int pidfile_write(struct pidfh *pfh);
int pidfile_close(struct pidfh *pfh);
int pidfile_remove(struct pidfh *pfh);

[링크 : http://fuse4bsd.creo.hu/localcgi/man-cgi.cgi?pidfile+3]


데몬들은 서비스 관리를 위해서 pid 파일을 가지고 있다.
이녀석은 열어 보면, 단순하게 pid를 %d 로 출력한 내용뿐인데,
일일이 열어서 읽고, atoi 돌리기 귀찮아서 검색을 해보니 pidfile 이라는 함수 패밀리가 있었다.

음. 그런데 die.net에 없는거 보면.. 표준 함수는 아닌건가?
FC6에도 존재하지 않는 함수 -ㅁ-

사족 : 음.. 아마도.. Linux가 아니라 Freebsd Man page 라서 인가?
Posted by 구차니
Linux2009. 11. 18. 16:03
if [ -f filename] 으로 파일의 유무를 확인할 수 있다.
물론 그 파일이 존재한다 하더라도 깨어진 심볼릭 링크라면 없는 파일로 나온다.
.. 당연한건가?

$ cat broken_link.sh
#/bin/sh
if [ -f test ]
then
        echo test exist
else
        echo test not exist
fi

$ ls -al
total 60
-r-xr-xr-x 1 morpheuz dev   71 Nov 18 15:37 broken_link.sh
lrwxrwxrwx 1 morpheuz dev    2 Nov 18 15:36 test -> tt

$ ./broken_link.sh
test not exist

$ touch tt
$ ls -al
total 60
-r-xr-xr-x 1 morpheuz dev   71 Nov 18 15:37 broken_link.sh
lrwxrwxrwx 1 morpheuz dev    2 Nov 18 15:36 test -> tt
-rw-rw-r-- 1 morpheuz dev    0 Nov 18 15:40 tt

$ ./broken_link.sh
test exist

[링크 : http://freeos.com/guides/lsst/ch03sec02.html]

'Linux' 카테고리의 다른 글

ps - Process Status  (2) 2009.11.20
pidfile family - pidfile_open, pidfile_remove, pidfile_write, pidfile_close  (0) 2009.11.20
리눅스 셸스크립트 튜토리얼  (2) 2009.11.17
Fedora Core 12  (0) 2009.11.17
UVC - USB Video Class  (0) 2009.11.17
Posted by 구차니
Linux2009. 11. 17. 18:15
원본은 링크가 깨진듯 하고, 어딘가에 pdf 버전이 돌아다니길 기원하며
좀 더 찾아봐야겠다 ㅠ.ㅠ

[링크 : http://freeos.com/guides/lsst/index.html]

'Linux' 카테고리의 다른 글

pidfile family - pidfile_open, pidfile_remove, pidfile_write, pidfile_close  (0) 2009.11.20
쉘 스크립트에서 파일 존재유무 확인하기  (0) 2009.11.18
Fedora Core 12  (0) 2009.11.17
UVC - USB Video Class  (0) 2009.11.17
tree  (0) 2009.11.16
Posted by 구차니
Linux2009. 11. 17. 09:32

2009년 11월 18일에 나올 예정이라는데
벌써 FC12 라니 ㄱ-

간만에 FC11 받을려다가.. 내일 FC12 나오면 내일 받아야겠다 -ㅁ-


[링크 : http://fedoraproject.org/ko/index]

'Linux' 카테고리의 다른 글

쉘 스크립트에서 파일 존재유무 확인하기  (0) 2009.11.18
리눅스 셸스크립트 튜토리얼  (2) 2009.11.17
UVC - USB Video Class  (0) 2009.11.17
tree  (0) 2009.11.16
설치하지 않은 rpm에 포함된 파일의 내용 보기  (0) 2009.11.04
Posted by 구차니