Linux2009. 12. 9. 17:15

#include <time.h>

time_t time(time_t *t);
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);

char *asctime(const struct tm *tm);
char *asctime_r(const struct tm *tm, char *buf);
char *ctime(const time_t *timep);
char *ctime_r(const time_t *timep, char *buf);
struct tm *gmtime(const time_t *timep);
struct tm *gmtime_r(const time_t *timep, struct tm *result);
struct tm *localtime(const time_t *timep);
struct tm *localtime_r(const time_t *timep, struct tm *result);
time_t mktime(struct tm *tm);

struct tm
{
    int tm_hour;//     hour (0 - 23)
    int tm_isdst;//     Daylight saving time enabled (> 0), disabled (= 0), or unknown (< 0)
    int tm_mday;//     day of the month (1 - 31)
    int tm_min;//     minutes (0 - 59)
    int tm_mon;//     month (0 - 11, 0 = January)
    int tm_sec;//     seconds (0 - 59)
    int tm_wday;//     day of the week (0 - 6, 0 = Sunday)
    int tm_yday;//     day of the year (0 - 365)
    int tm_year;//     year since 1900
}

[링크 : http://en.wikipedia.org/wiki/Time.h] Time_t 구조체 내용
[링크 : http://en.wikipedia.org/wiki/Time_t]  Time_t 구조체 사용방법

[링크 : http://linux.die.net/man/3/strftime]
[링크 : http://linux.die.net/man/3/localtime]
[링크 : http://linux.die.net/man/3/mktime]

struct tm과 time_t 라는 타입은 시간에 사용된다.
mktime() 은 struct tm의 값으로 timt_t 형의 시간을 만들어 주고, time()은 현재의 시간을 반환해준다.(time_t *t = NULL)
localtime() 으로 time_t 형의 값으로 변환해준다.
strftime()은 sprintf와 비슷하게 time_t 형의 값을 받아 문자열로 시간을 나타내준다.

복잡하게 보이지만, 간단하게 예를 들자면,
int main(void)
{
    time_t     now;
    struct tm  tmtm;
    struct tm  *ts;
    char       buf[80];

    /* Get the current time */
    //now = time(NULL);
    tmtm.tm_year = 102;
    tmtm.tm_mon = 1;
    tmtm.tm_mday = 23;
    tmtm.tm_hour = 10;
    tmtm.tm_min = 12;
    tmtm.tm_sec = 51;
    now = mktime(&tmtm);

    /* Format and print the time, "ddd yyyy-mm-dd hh:mm:ss zzz" */
    ts = localtime(&now);
    strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", ts);
    printf("%s\n", buf);

    return 0;
}
결과는 아래와 같다.
 Sat 2002-02-23 10:12:51 KST
mktime()으로 원하는 시간과 날자를 넣고, (만약 주석된 time()을 풀면 현재 시간이 나온다)
localtime()을 통해서 time_t 형으로 변환하고
strftime()을 통해서 문자열로 출력을 한다.
만약에 요일이 궁금하다면 날자를 넣고, localtime() 한뒤 리턴되는 struct tm 의 값중 tm_wday 을 읽으면 된다.

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/3/mktime]
Posted by 구차니
Linux2009. 12. 9. 16:11
이름은 모르겠지만, 위와 같이 사용하려면 아래의 항목을 Enable 해주면 된다.

모든 작업공간상의 프로그램을 순환하려면 Alt-win-Tab 으로 하면된다.
(기본값임)
Posted by 구차니
Linux/Ubuntu2009. 12. 9. 14:50
apt-get 서버의 목록중 캐노니컬 관리 / 커뮤니티 관리 이런식으로 분리를 해놓는 바람에
많은 프로그램들이 기본 설치목록에 빠져있기 때문이다.

System - Administration - Software Sources 를 선택한다.

Communitu-maintained Open Source software (universe)
항목을 선택하고 Close 한뒤, refresh 해주면 서버에서 프로그램 목록을 가져온다.

compiz 모드에서 찍은 스샷이라.. 제목표시줄이 가출.. (먼산)
아무튼 위의 항목을 선택 해주지 않으면, 위와 같이 캐노니컬에서 한게 아니라 Install 버튼이 생기지 않는다

하지만 항목을 선택하고 나면 위와 같이 캐노니컬에서 하지 않지만 Install 버튼이 생긴다.

'Linux > Ubuntu' 카테고리의 다른 글

TC1100에 우분투 설치 관련 문서  (6) 2009.12.10
Xournal + CellWriter  (4) 2009.12.10
Ubuntu 9.10 만세  (4) 2009.12.09
9.10 kalmic 업그레이드 / 맛배기  (0) 2009.11.02
gnome panel에 온도 정보 넣기  (0) 2009.11.02
Posted by 구차니
Linux2009. 12. 9. 11:56
음.. 아직은 윈도우에서 편하게 하는 방법은 없는듯 하다.

>> create new persistent file
dd if=/dev/zero of=casper-rw bs=1M count=1024
mkfs.ext3 -F casper-rw

>> resize persistent file
dd if=/dev/zero bs=1M count=1024 >> casper-rw
resize2fs casper-rw

[링크 : http://supertechnews.com/software/create-a-larger-casper-rw-loop-file-for-your-live-usb-from-linux/]

resize는 1024MB가 추가되는 것으로 보인다.(기존에 128MB 였다면 1GB+128MB가 되는식)






아래는 colinux에서 codb 파일 용량 늘리는 방법(windows)
[링크 : http://minimonk.tistory.com/784]


귀찮으면 그냥, 다시 LiveUSB 설치 고고싱(어짜피 10분이면 됨!)
Posted by 구차니
Linux/Ubuntu2009. 12. 9. 10:38
어제 바람이 불어서(응?) Ubuntu 9.10 을 LiveUSB로 구동했다.
각설하고 대충 살펴보자면

장점 :
- 이전 버전의 불만이었던 GIMP / OpenOffice가 포함되었다!!! (이거 하나면 포토샾에 오피스 한방에 떡실신)
- TC1100 타블렛에서 타블렛 기본 인식!!
- Geforce4 420Go 지원으로 간편한 Compiz-Beryl 가동
- Live임에도 불구하고 매우 빠르고 안정적인 환경(2분 정도의 빠른 부팅속도)

단점 :
- 기본값으로 한글 입력 불가 / 터미널에서 한글 입력 오류
- wireless network manager의 오작동
- 여전히 Firefox에 Abode flash plugin 기본설치 되어 있지 않음(라이센스 문제?)
- 타블렛을 위한 프로그램은 전무
- Beryl 을 위한 설정 프로그램 존재하지 않음

아무튼, 9.04 에서 9.10으로 업그레이드 하는것보다 몇배 나은것 같다.
어짜피 한글은 그리많이 쓰지 않으니 -ㅁ-

CCSM(CompizConfig Setting Manager)
[링크 : http://www.ubuntugeek.com/how-to-install-and-configure-compiz-fusion-in-ubuntu-9-10karmic.html]


'Linux > Ubuntu' 카테고리의 다른 글

Xournal + CellWriter  (4) 2009.12.10
Ubuntu 9.10 에서 프로그램 설치가 안될경우  (0) 2009.12.09
9.10 kalmic 업그레이드 / 맛배기  (0) 2009.11.02
gnome panel에 온도 정보 넣기  (0) 2009.11.02
apt-cache 패키지 검색 하기  (0) 2009.09.01
Posted by 구차니
Linux2009. 12. 9. 01:16


Linux Live USB Creator (이하 LiLi)는 UI도 깔끔하고,
Virtual box를 이용하여 colinux 처럼 윈도우에서 마치 리눅스를 돌리는 듯한 느낌을 준다.
설명에 따르면 persistent 공간은 virtual box나 usb나 양쪽으로 사용할 수 있다고 한다.(와우!)
그리고 Virtual Box 구동시간은 로그인 화면까지 대략 3분 정도 걸렸다.
설치도 liveusb creator에 비해서 빠른느낌이다. (자주 값이 변하므로 체감이 짧다)
이 녀석은 설치후에 이런 페이지를 띄운다. [링크 : http://www.linuxliveusb.com/using-lili.html]

장점 : Virtual Box 지원
         깔끔한 디자인
         설치 속도가 빠른편 (410MB의 persistence 용량과 Virtual Box를 7분에 완료함)
         프로그램의 크기가 작음(1.4MB -> 3.2MB)

단점 : 세로로 길어서, 저해상도에서는 사용하기 불편
         Virtual Box는 네트워크로 다운로드 받아야 함
         LiveUSB Creator는 integrity check를 설치시에 하는데, LiLi는 ISO 선택시에 하는 관계로 불편하다(취소불가)
         LiLi 실행중/종료후에 방향키가 듣지않는 현상이 있다.

[링크 : http://www.linuxliveusb.com/]






3.9 버전은, installer로 변경되었다. (기존에는 바로 실행)
일단 설치 프로그램의 크기가 7.9M로 상당히 큰편이다.
그리고 여전히 ISO 파일로 설치시에 약간의 문제가 있는 것으로 보인다.
(아무튼 C:\Program Files\LiveUSB Creator 로 iso 파일을 옮기면 이상없이 작동한다.. 뭥미?)
여전히 한글경로나 드라이브 이름은 해결되지 않았다.
세번정도 시도했는데 Persistent 를 생성하다가 죽는다.
아무튼, 압축해제 소요시간만 따지면, 3분 40초로 LiLi와 비슷한 수준이다.

장점 : UI가 단순하고 세로로 짧아서 저해상도에서 사용하기 편함

단점 : 딱히 장점이 없다.
         한글 경로나 , 한글 드라이브 출력 문제
         설치 프로그램 용량이 큼(약 8MB)

[링크 : https://fedorahosted.org/liveusb-creator/]



결론
LiLi가 일단은 안정적이고 Virtual Box라는 장점이 있으므로,
한동안은 LiveUSB Creator 보다 LiLi를 애용해야겠다.



2010.05.05 추가
netbsd의 경우에는 호환성 리스트에 존재하지 않아 아래와 같은 경고가 뜨며,
실제로 usb로 생성하고 부팅하면 부팅이 되지 않는 문제가 있다.



Posted by 구차니
Linux2009. 12. 8. 20:05
도대체 달력소스는 왜케 찾기가 힘들지 ㄱ-
일단 분석을 해서 어떻게 그리는지 알아봐야겠다 ㅠ.ㅠ


[링크 : http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/calendar/]
Posted by 구차니
Linux2009. 12. 8. 17:53
How redirect stderr to /dev/null in c program(language) on linux

if (replace_stderr && freopen("/dev/null", "w", stderr) == NULL) {
    ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s_main,
        "unable to replace stderr with /dev/null");
}

[링크 : http://www.codase.com/search/call?name=freopen]

#include <stdio.h>

FILE *fopen(const char *path, const char *mode);
FILE *fdopen(int fildes, const char *mode);
FILE *freopen(const char *path, const char *mode, FILE *stream);

[링크 : http://linux.die.net/man/3/freopen]

freopen 은 파일 디스크립터를 다시 열어주는 역활을 한다.
위의 예제대로
freopen("/dev/null", "w", stderr);
를 실행하면 /dev/null 을 stderr로 열어주므로, 모든 stderr 메시지가 사라진다.

$ cat redirection.c
#include <stdio.h>
#include <unistd.h>

void main()
{
        fprintf(stdout,"test output message\n");
        fprintf(stderr,"test error message\n");
}

$ gcc -o a.out redirection.c

$ ./a.out
test output message
test error message
$ ./a.out > /dev/null
test error message
$ ./a.out 2> /dev/null
test output message

$ cat redirection_2.c
#include <stdio.h>
#include <unistd.h>

void main()
{
        freopen("/dev/null", "w", stderr);

        fprintf(stdout,"test output message\n");
        fprintf(stderr,"test error message\n");
}

$ gcc -o b.out redirection_2.c

$ ./b.out
test error message
$ ./b.out > /dev/null
$ ./b.out 2> /dev/null
test output message

위의 예제 두개를 비교해보면 알 수 있겠지만,
freopen 으로 인해 아래의 예제는 stderr이 출력되지 않는다.
Posted by 구차니
Linux2009. 12. 7. 18:04

# mount
rootfs on / type rootfs (rw)
/dev/root on / type cramfs (ro,noatime)
proc on /proc type proc (rw)
usbfs on /proc/bus/usb type usbfs (rw)
sysfs on /sys type sysfs (rw)
/dev/mtdblock3 on /root/apps type cramfs (ro)
/dev/mtdblock4 on /root/apps/data type jffs2 (rw)
/dev/sda1 on /root/sda1 type vfat (rw,fmask=0022,dmask=0022,codepage=cp437,iocharset=iso8859-1)

...
FAT: Filesystem panic (dev sda1)
    fat_get_cluster: invalid cluster chain (i_pos 125316)
    File system has been set read-only
...

# mount
rootfs on / type rootfs (rw)
/dev/root on / type cramfs (ro,noatime)
proc on /proc type proc (rw)
usbfs on /proc/bus/usb type usbfs (rw)
sysfs on /sys type sysfs (rw)
/dev/mtdblock3 on /root/apps type cramfs (ro)
/dev/mtdblock4 on /root/apps/data type jffs2 (rw)
/dev/sda1 on /root/sda1 type vfat (ro,fmask=0022,dmask=0022,codepage=cp437,iocharset=iso8859-1)




fsck 그것은 진리인가?

fsck.msdos with -a

[링크 : http://southerns.wordpress.com/2007/06/22/fat-filesystem-panic-dev-xxx/]

Posted by 구차니
Linux2009. 12. 7. 17:17

umount: cannot umount [mount poiunt] "Device or resource busy"

요런 에러를 발생해서 상콤하게 검색 고고싱,

-f
    Force unmount (in case of an unreachable NFS system). (Requires kernel 2.1.116 or later.)
-l
    Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.)

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

Linux 2.1.116 added the umount2() system call, which, like umount(), unmounts a target, but allows additional flags controlling the behaviour of the operation:

MNT_FORCE
(since Linux 2.1.116)
    Force unmount even if busy. (Only for NFS mounts.)

MNT_DETACH (since Linux 2.4.11)
    Perform a lazy unmount: make the mount point unavailable for new accesses, and actually perform the unmount when the mount point ceases to be busy.

MNT_EXPIRE (since Linux 2.6.8)
    Mark the mount point as expired. If a mount point is not currently in use, then an initial call to umount2() with this flag fails with the error EAGAIN, but marks the mount point as expi2red. The mount point remains expired as long as it isn't accessed by any process. A second umount2() call specifying MNT_EXPIRE unmounts an expired mount point. This flag cannot be specified with either MNT_FORCE or MNT_DETACH.

[링크 : http://linux.die.net/man/2/umount] - umount()

원인이야, 이미 열린 파일이 있을 경우이지만,
커널 2.4.11 이후부터는 lazy umount를 지원해서 깔끔하게 에러없이 마운트를 해제할 수 있다.
(어떤 문제점이 부가적으로 생길지는..)

2010.02.05 추가
# umount -fl 로 실행하면 묻지도 따지지도 않고 언마운트시킨다.


2014.09.03 추가
ssh로 로그인 중이었는데 fuser로 하니 사용자가 튕기면서 unmount가 된다 ㄷㄷ
그 이후에 많이 엉기니 사용시 주의가 필요한듯

# fuser -km /mountpoint
[링크 : http://www.cyberciti.biz/tips/how-do-i-forcefully-unmount-a-disk-partition.html]


Posted by 구차니