728x90

#include <stdio.h>

int fflush (FILE *stream);


return value : 

success : 0

fail : EOF


user buffer에 있는 내용을 kernel buffer에 write한다.

fwrite대신 강제로 write를 하는 것과 비슷함.
실제로 file-system에 기록되는지는 보장하지 못함.

그래서 보통 fflush() 다음에 fsync()를 같이 사용한다.




#include <stdio.h>

int fileno (FILE *stream);


return value : 

success : fd

fail : -1(EBADF)


728x90

'Programming > linux왕초보' 카테고리의 다른 글

Caching your GitHub password in Git  (0) 2016.01.08
Serial ports usage on Linux  (0) 2016.01.08
process 종료  (0) 2015.05.28
fork  (0) 2015.05.26
Linux SSD 최적화  (0) 2015.04.17
[Linux] stream write  (0) 2015.03.26
linux filesystem 사용 용량 확인  (0) 2015.03.18
[Linux] Select and Poll  (0) 2015.01.27
Example syntax for Secure Copy (scp) : scp사용법  (0) 2014.04.02
tar 분할압축/풀기  (0) 2014.03.20
728x90












728x90

'Programming > linux왕초보' 카테고리의 다른 글

Serial ports usage on Linux  (0) 2016.01.08
process 종료  (0) 2015.05.28
fork  (0) 2015.05.26
Linux SSD 최적화  (0) 2015.04.17
fflush, fileno  (0) 2015.04.07
linux filesystem 사용 용량 확인  (0) 2015.03.18
[Linux] Select and Poll  (0) 2015.01.27
Example syntax for Secure Copy (scp) : scp사용법  (0) 2014.04.02
tar 분할압축/풀기  (0) 2014.03.20
slang_rs_export_foreach.cpp Error: ParamName  (0) 2014.02.26
728x90

df / du


df : block별 사용량 확인


df -lh

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda2       909G  222G  641G  26% /

none            4.0K     0  4.0K   0% /sys/fs/cgroup

udev            3.9G  4.0K  3.9G   1% /dev

tmpfs           790M  7.5M  783M   1% /run

none            5.0M     0  5.0M   0% /run/lock

none            3.9G  152K  3.9G   1% /run/shm

none            100M   48K  100M   1% /run/user

/dev/sda1       511M  7.3M  504M   2% /boot/efi


Mandatory arguments to long options are mandatory for short options too.
  -a, --all             include dummy file systems
  -B, --block-size=SIZE  scale sizes by SIZE before printing them.  E.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes.
                           See SIZE format below.
      --total           produce a grand total
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
  -H, --si              likewise, but use powers of 1000 not 1024
  -i, --inodes          list inode information instead of block usage
  -k                    like --block-size=1K
  -l, --local           limit listing to local file systems
      --no-sync         do not invoke sync before getting usage info (default)
      --output[=FIELD_LIST]  use the output format defined by FIELD_LIST,
                               or print all fields if FIELD_LIST is omitted.
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
  -t, --type=TYPE       limit listing to file systems of type TYPE
  -T, --print-type      print file system type
  -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
  -v                    (ignored)
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

FIELD_LIST is a comma-separated list of columns to be included.  Valid
field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
'size', 'used', 'avail', 'pcent' and 'target' (see info page).


du : directory별 사용량 확인

du -sh ./*
8.0K    ./AndroidManifest_test.xml
32K     ./AndroidManifest.xml
4.0K    ./Android.mk
4.0K    ./CleanSpec.mk
656K    ./jni
76K     ./lib
2.5M    ./res
4.4M    ./src
68K     ./tests


Mandatory arguments to long options are mandatory for short options too.
  -0, --null            end each output line with 0 byte rather than newline
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes, rather than disk usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in ('sparse') files, internal
                          fragmentation, indirect blocks, and the like
  -B, --block-size=SIZE  scale sizes by SIZE before printing them.  E.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes.
                           See SIZE format below.
  -b, --bytes           equivalent to '--apparent-size --block-size=1'
  -c, --total           produce a grand total
  -D, --dereference-args  dereference only symlinks that are listed on the
                          command line
  -d, --max-depth=N     print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as
                          --summarize
      --files0-from=F   summarize disk usage of the NUL-terminated file
                          names specified in file F;
                          If F is - then read names from standard input
  -H                    equivalent to --dereference-args (-D)
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
  -k                    like --block-size=1K
  -L, --dereference     dereference all symbolic links
  -l, --count-links     count sizes many times if hard linked
  -m                    like --block-size=1M
  -P, --no-dereference  don't follow any symbolic links (this is the default)
  -S, --separate-dirs   do not include size of subdirectories
      --si              like -h, but use powers of 1000 not 1024
  -s, --summarize       display only a total for each argument
  -t, --threshold=SIZE  exclude entries smaller than SIZE if positive,
                          or entries greater than SIZE if negative
      --time            show time of the last modification of any file in the
                          directory, or any of its subdirectories
      --time=WORD       show time as WORD instead of modification time:
                          atime, access, use, ctime or status
      --time-style=STYLE  show times using style STYLE:
                          full-iso, long-iso, iso, +FORMAT
                          FORMAT is interpreted like 'date'
  -X, --exclude-from=FILE  exclude files that match any pattern in FILE
      --exclude=PATTERN    exclude files that match PATTERN
  -x, --one-file-system    skip directories on different file systems
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).





728x90

'Programming > linux왕초보' 카테고리의 다른 글

process 종료  (0) 2015.05.28
fork  (0) 2015.05.26
Linux SSD 최적화  (0) 2015.04.17
fflush, fileno  (0) 2015.04.07
[Linux] stream write  (0) 2015.03.26
[Linux] Select and Poll  (0) 2015.01.27
Example syntax for Secure Copy (scp) : scp사용법  (0) 2014.04.02
tar 분할압축/풀기  (0) 2014.03.20
slang_rs_export_foreach.cpp Error: ParamName  (0) 2014.02.26
printk : kernel log 설정  (0) 2013.11.19
728x90

IPC : pipe, named pipe, semaphore, message queue, shared memory, futex, socket


Futex : fast userspace mutex(Spinlock 방식)

- 장점 : 빠름 (sleep 대신 while), 

            lock이 user space에 있기 때문에 접근성이 좋음(공유 메모리나 Thread 및           Process간 공유 가능)

- 단점 : 기본적으로 loop를 계속 돌고 있기 때문에 core수가 뒷받침되어야 한다. 

           (single core에서는 소용 없음.)


pthread mutex vs pthread spinlock

Pasted from <http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock> 



Pselect()

int pselect(int nfds, fd_set *readfds, fd_set *writefds,

           fd_set *exceptfds, const struct timespec *timeout,

           const sigset_t *sigmask);

• pselect는 struct timespec 구조체 사용한다. timespec 구조체를 사용함으로써        나노초까지 세밀하게 조정할 수 있게 되었다.


struct timespec {

    long    tv_sec;         /* seconds */

    long    tv_nsec;        /* nanoseconds */

};

• pselect 는 Linux(:12) 커널 2.6.16에 추가되었다. 이전에는 glibc에서 애뮬레이트한
          함수가 제공되었으나 버그를 가지고 있었다.

• sigmask를 사용해서 시그널을 블럭시킬 수 있다. select의 경우 수행되는 도중에         시그널에 의한 인터럽트가 발생하게 되면, race condition 혹은 무한 블록킹         상태에 놓일 수 있었다. pselect를 사용하면 이러한 문제를 제거할 수 있다. 


Pasted from <http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/2/select> 

Pselect가 select와 다른 점

- Nano sec단위로 사용하므로 이론적으로는 타이머 해상도가 정밀하나 실전에서는
        micro sec단위도 안정적으로 제공하지 못한다.

- Timeout parameter를 변경하지 않는다. 사용할 때마다 timeout을 다시 설정할
        필요가 없음

- Signal parameter가 추가됨(sigmask) : signal 을 차단함.




Select() : 동기식 다중 입출력 제공
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

Int select (int n,
                  fd_set *readfds,
                   fd_set *writefds,
                   fd_set *execptfds,
                   struct timeval *timeout);

FD_CLR(int fd, fd_set *set);       /* delete FD */
FD_ISSET(int fd, fd_set *set);    /* select의 결과에 해당 fd가 있는지 */
FD_SET(int fd, fd_set *set);      /* add FD*/
FD_ZERO(fd_set *set);


#include <sys/time.h>
Struct timeval {
             long tv_sec;    /* sec */
             long tv_usec;  /* micro sec */
};

Poll() : select를 보완 (fd set을 하나로 통일)
#include <sys/poll.h>
Int poll (struct pollfd *fds, unsigned int nfds, int timeout);

#include <sys/poll.h>
Struct pollfd {
            int fd;
            short events;   /* 감시 대상 요청 */
            short revents; /* returned event */
}

Events:
POLLIN : Data other than high-priority data may be read without blocking.
POLLRDNORM : Normal data may be read without blocking.
POLLRDBAND : Priority data may be read without blocking.
POLLPRI : High-priority data may be read without blocking.
POLLOUT : Normal data may be written without blocking.
POLLWRNORM : Equivalent to POLLOUT.
POLLWRBAND : Priority data may be written.
POLLERR : An error has occurred on the device or stream. This flag is only valid in the revents bitmask; it shall be ignored in the events member.
POLLHUP : The device has been disconnected. This event and POLLOUT are mutually-exclusive; a stream can never be writable if a hangup has occurred. However, this event and POLLIN, POLLRDNORM, POLLRDBAND, or POLLPRI are not mutually-exclusive. This flag is only valid in the revents bitmask; it shall be ignored in the events member.
POLLNVAL : The specified fd value is invalid. This flag is only valid in the revents member; it shall ignored in the events member.

Ppoll() : pselect 처럼 만든 것, 나노초 단위, sigmask 제공, linux 전용
#define _GNU_SOURCE
#include <sys/poll.h>
Int ppoll (struct pollfd *fds,
                  nfds_t nfds,
                  const struct timespec *timeout,
                  const sigset_t *sigmask);

Poll과 select 비교

oll 

select 

매개변수에 +1(fd+1)이 필요없다 

 

fd의 숫자가 큰 경우 select보다 효율적 

fd_set값이 크면 비효율적이다. bitmask를 모두 검사하며 특히 bit가 분산된 경우 더욱 비효율적이다 

 

 매번 set을 초기화해야 한다.(FD_ZERO)

 

 이식성을 높이기 위해 timeout parameter(timeval)를 매번 초기화 해야함

Pselect() 사용할 경우 초기화 안해도

 몇몇 UNIX에서는 poll을 지원하지 않는다

 이식성이 높다

 

 microsecond단위까지는 timeout resolution이 더 좋다

Pasted from <http://bluelimn.tistory.com/entry/2-epoll-select-poll>

 





728x90

'Programming > linux왕초보' 카테고리의 다른 글

fork  (0) 2015.05.26
Linux SSD 최적화  (0) 2015.04.17
fflush, fileno  (0) 2015.04.07
[Linux] stream write  (0) 2015.03.26
linux filesystem 사용 용량 확인  (0) 2015.03.18
Example syntax for Secure Copy (scp) : scp사용법  (0) 2014.04.02
tar 분할압축/풀기  (0) 2014.03.20
slang_rs_export_foreach.cpp Error: ParamName  (0) 2014.02.26
printk : kernel log 설정  (0) 2013.11.19
[Linux] Top 명령어 사용법  (0) 2013.11.08

+ Recent posts