반응형
#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>

int main() {
    pid_t pid;

    switch (pid = fork()){
        case -1 :
            perror("fork");
            exit(1);
            break;
        case 0:
            printf("Childe Process - My PID:%d, My Parent's PID:%d\n", (int)getpid(), (int)getppid());
            break;
        default :
            printf("Parent process - My PID:%d, My Parent's PID:%d, My Child's PID:%d\n", (int)getpid(), (int)getppid(), (int)pid);
            break;
    }

    printf("End of fork\n");
    return 0;
}
반응형
반응형
#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h>

int main() {

    int i;
    time_t t;
    struct tms mytms;
    clock_t t1, t2;

    if((t1 = times(&mytms)) == -1){
        perror("times 1");
        exit(1);
    }

    for(i = 0; i< 99999999; i++)
        time(&t);

    if((t2 = times(&mytms)) == -1){
        perror("times 2");
        exit(1);
    }

    printf("Real time : %.1f sec\n", (double)(t2- t1)/ CLK_TCK);
    printf("User time : %.1f sec\n", (double)mytms.tms_utime / CLK_TCK);
    printf("System time : %.1f sec\n", (double)mytms.tms_stime/ CLK_TCK);


    return 0;
}

 

--output--

Real time : 5.3 sec
User time : 5.2 sec
System time : 0.0 sec
반응형
반응형
#include <stdio.h>
#include <time.h>

int main() {
    struct tm *tm;
    time_t t;

    time(&t);
    printf("Time(sec) : %d\n", (int)t);

    tm = gmtime(&t);
    printf("GMTIME=Y:%d ", tm->tm_year);
    printf("M:%d ", tm->tm_mon);
    printf("D:%d ", tm->tm_mday);
    printf("H:%d ", tm->tm_hour);
    printf("M:%d ", tm->tm_min);
    printf("S:%d\n", tm->tm_sec);

    tm = localtime(&t);
    printf("LOCALTIME=Y:%d ", tm->tm_year);
    printf("M:%d ", tm->tm_mon);
    printf("D:%d ", tm->tm_mday);
    printf("H:%d ", tm->tm_hour);
    printf("M:%d ", tm->tm_min);
    printf("S:%d\n", tm->tm_sec);
    
    return 0;
}

 

--output--

Time(sec) : 1664801617
GMTIME=Y:122 M:9 D:3 H:12 M:53 S:37
LOCALTIME=Y:122 M:9 D:3 H:21 M:53 S:37

Year은 1900년부터 시작이므로 1900 + 122 = 2022년이고,

M은 month로 0부터 읽기 때문에 9면 10월이다

반응형
반응형

도커 라이프 사이클

 

반응형
반응형

Operating System은 컴퓨터의 하드웨어를 관리하는 소프트웨어이다.

컴퓨터의 하드웨어는 CPU, 메모리 , IO device를 의미한다.

 

 

반응형

+ Recent posts