pthread_getcpuclockid(3) - wariua/manpages-ko GitHub Wiki

NAME

pthread_getcpuclockid - μŠ€λ ˆλ“œμ˜ CPU μ‹œκ°„ 클럭의 ID μ–»κΈ°

SYNOPSIS

#include <pthread.h>
#include <time.h>

int pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id);

-pthread둜 컴파일 및 링크.

DESCRIPTION

pthread_getcpuclockid() ν•¨μˆ˜λŠ” μŠ€λ ˆλ“œ thread의 CPU μ‹œκ°„ ν΄λŸ­μ— λŒ€ν•œ 클럭 IDλ₯Ό λ°˜ν™˜ν•œλ‹€.

RETURN VALUE

성곡 μ‹œ 이 ν•¨μˆ˜λŠ” 0을 λ°˜ν™˜ν•œλ‹€. 였λ₯˜ μ‹œ 0 μ•„λ‹Œ 였λ₯˜ 번호λ₯Ό λ°˜ν™˜ν•œλ‹€.

ERRORS

ENOENT
μ‹œμŠ€ν…œμ—μ„œ μŠ€λ ˆλ“œλ³„ CPU μ‹œκ°„ ν΄λŸ­μ„ μ§€μ›ν•˜μ§€ μ•ŠλŠ”λ‹€.
ESRCH
threadλΌλŠ” IDλ₯Ό κ°€μ§„ μŠ€λ ˆλ“œλ₯Ό 찾을 수 μ—†λ‹€.

VERSIONS

glibc 버전 2.2λΆ€ν„° 이 ν•¨μˆ˜κ°€ μ‚¬μš© κ°€λŠ₯ν•˜λ‹€.

ATTRIBUTES

이 μ ˆμ—μ„œ μ‚¬μš©ν•˜λŠ” μš©μ–΄λ“€μ— λŒ€ν•œ μ„€λͺ…은 attributes(7)λ₯Ό 보라.

μΈν„°νŽ˜μ΄μŠ€ 속성 κ°’
pthread_getcpuclockid() μŠ€λ ˆλ“œ μ•ˆμ „μ„± MT-Safe

CONFORMING TO

POSIX.1-2001, POSIX.1-2008.

NOTES

threadκ°€ 호좜 μŠ€λ ˆλ“œλ₯Ό 가리킬 λ•Œ 이 ν•¨μˆ˜κ°€ λ°˜ν™˜ν•˜λŠ” μ‹λ³„μžκ°€ κ°€λ¦¬ν‚€λŠ” ν΄λŸ­μ€ 클럭 ID둜 CLOCK_THREAD_CPUTIME_IDλ₯Ό μ£Όμ–΄ clock_gettime(2) 및 clock_settime(2)으둜 μ‘°μž‘ν•˜λŠ” 것과 같은 ν΄λŸ­μ΄λ‹€.

EXAMPLE

μ•„λž˜ ν”„λ‘œκ·Έλž¨μ€ μŠ€λ ˆλ“œλ₯Ό μƒμ„±ν•œ λ‹€μŒ clock_gettime(2)을 μ¨μ„œ 총 ν”„λ‘œμ„ΈμŠ€ CPU μ‹œκ°„μ„ μ–»κ³ μ„œ 두 μŠ€λ ˆλ“œκ°€ μ†Œλͺ¨ν•œ μŠ€λ ˆλ“œλ³„ CPU μ‹œκ°„μ„ μ–»λŠ”λ‹€. λ‹€μŒ μ…Έ μ„Έμ…˜μ΄ μ‹€ν–‰ 예λ₯Ό 보여 μ€€λ‹€.

$ ./a.out
Main thread sleeping
Subthread starting infinite loop
Main thread consuming some CPU time...
Process total CPU time:    1.368
Main thread CPU time:      0.376
Subthread CPU time:        0.992

ν”„λ‘œκ·Έλž¨ μ†ŒμŠ€

/* "-lrt"둜 링크 */

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>

#define handle_error(msg) \
        do { perror(msg); exit(EXIT_FAILURE); } while (0)

#define handle_error_en(en, msg) \
        do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)

static void *
thread_start(void *arg)
{
    printf("Subthread starting infinite loop\n");
    for (;;)
        continue;
}

static void
pclock(char *msg, clockid_t cid)
{
    struct timespec ts;

    printf("%s", msg);
    if (clock_gettime(cid, &ts) == -1)
        handle_error("clock_gettime");
    printf("%4ld.%03ld\n", ts.tv_sec, ts.tv_nsec / 1000000);
}

int
main(int argc, char *argv[])
{
    pthread_t thread;
    clockid_t cid;
    int j, s;

    s = pthread_create(&thread, NULL, thread_start, NULL);
    if (s != 0)
        handle_error_en(s, "pthread_create");

    printf("Main thread sleeping\n");
    sleep(1);

    printf("Main thread consuming some CPU time...\n");
    for (j = 0; j < 2000000; j++)
        getppid();

    pclock("Process total CPU time: ", CLOCK_PROCESS_CPUTIME_ID);

    s = pthread_getcpuclockid(pthread_self(), &cid);
    if (s != 0)
        handle_error_en(s, "pthread_getcpuclockid");
    pclock("Main thread CPU time:   ", cid);

    /* μ•žμ˜ μ½”λ“œ 4쀄을 λ‹€μŒμœΌλ‘œ λŒ€μ²΄ν•  μˆ˜λ„ 있음:
       pclock("Main thread CPU time:   ", CLOCK_THREAD_CPUTIME_ID); */

    s = pthread_getcpuclockid(thread, &cid);
    if (s != 0)
        handle_error_en(s, "pthread_getcpuclockid");
    pclock("Subthread CPU time: 1    ", cid);

    exit(EXIT_SUCCESS);         /* 두 μŠ€λ ˆλ“œ λͺ¨λ‘ μ’…λ£Œ */
}

SEE ALSO

clock_gettime(2), clock_settime(2), timer_create(2), clock_getcpuclockid(3), pthread_self(3), pthreads(7), time(7)


2019-03-06

⚠️ **GitHub.com Fallback** ⚠️