.\" -*- coding: UTF-8 -*- '\" t .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk .\" .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH pthread_getcpuclockid 3 "31 октября 2023 г." "Linux man\-pages 6.06" .SH ИМЯ pthread_getcpuclockid \- возвращает ID таймера времени ЦП у нити .SH LIBRARY POSIX threads library (\fIlibpthread\fP, \fI\-lpthread\fP) .SH СИНТАКСИС .nf \fB#include \fP \fB#include \fP .P \fBint pthread_getcpuclockid(pthread_t \fP\fIthread\fP\fB, clockid_t *\fP\fIclockid\fP\fB);\fP .fi .SH ОПИСАНИЕ .\" The clockid is constructed as follows: .\" *clockid = CLOCK_THREAD_CPUTIME_ID | (pd->tid << CLOCK_IDFIELD_SIZE) .\" where CLOCK_IDFIELD_SIZE is 3. The \fBpthread_getcpuclockid\fP() function obtains the ID of the CPU\-time clock of the thread whose ID is given in \fIthread\fP, and returns it in the location pointed to by \fIclockid\fP. .SH "ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ" При успешном выполнении функция возвращает 0; при ошибке возвращается ненулевой номер ошибки. .SH ОШИБКИ .TP \fBENOENT\fP .\" CLOCK_THREAD_CPUTIME_ID not defined .\" .\" Looking at nptl/pthread_getcpuclockid.c an ERANGE error would .\" be possible if kernel thread IDs took more than 29 bits (which .\" they currently cannot). В системе не поддерживаются выделенные таймеры времени ЦП для каждой нити. .TP \fBESRCH\fP Нить с идентификатором \fIthread\fP не найдена. .SH АТРИБУТЫ Описание терминов данного раздела смотрите в \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. Интерфейс Атрибут Значение T{ .na .nh \fBpthread_getcpuclockid\fP() T} Безвредность в нитях MT\-Safe .TE .SH СТАНДАРТЫ POSIX.1\-2008. .SH ИСТОРИЯ glibc 2.2. POSIX.1\-2001. .SH ЗАМЕЧАНИЯ Если \fIthread\fP указывает на вызвавшую нить, то функция возвращает идентификатор, указывающий на таймер, управляемый \fBclock_gettime\fP(2) и \fBclock_settime\fP(2), если ID таймера равно \fBCLOCK_THREAD_CPUTIME_ID\fP. .SH ПРИМЕРЫ Программа, показанная далее, создаёт нить и используя \fBclock_gettime\fP(2) показывает общее время ЦП и время ЦП, затраченное на работу нитей по отдельности. Пример сеанса работы: .P .in +4n .EX $ \fB./a.out\fP Главная нить спит Вторая нить входит в бесконечный цикл Главная нить использует немного времени ЦП… Общее время ЦП для процесса: 1.368 Время ЦП для главной нити: 0.376 Время ЦП для второй нити: 0.992 .EE .in .SS "Исходный код программы" .\" SRC BEGIN (pthread_getcpuclockid.c) \& .EX /* Link with "\-lrt" */ \& #include #include #include #include #include #include #include #include \& #define handle_error(msg) \e do { perror(msg); exit(EXIT_FAILURE); } while (0) \& #define handle_error_en(en, msg) \e do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) \& static void * thread_start(void *arg) { printf("Subthread starting infinite loop\en"); 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("%4jd.%03ld\en", (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000); } \& int main(void) { pthread_t thread; clockid_t cid; int s; \& s = pthread_create(&thread, NULL, thread_start, NULL); if (s != 0) handle_error_en(s, "pthread_create"); \& printf("Main thread sleeping\en"); sleep(1); \& printf("Main thread consuming some CPU time...\en"); for (unsigned int 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); \& /* The preceding 4 lines of code could have been replaced by: 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); /* Terminates both threads */ } .EE .\" SRC END .SH "СМ. ТАКЖЕ" \fBclock_gettime\fP(2), \fBclock_settime\fP(2), \fBtimer_create\fP(2), \fBclock_getcpuclockid\fP(3), \fBpthread_self\fP(3), \fBpthreads\fP(7), \fBtime\fP(7) .PP .SH ПЕРЕВОД Русский перевод этой страницы руководства был сделан Alexey, Azamat Hackimov , kogamatranslator49 , Kogan, Max Is , Yuri Kozlov и Иван Павлов . .PP Этот перевод является бесплатной документацией; прочитайте .UR https://www.gnu.org/licenses/gpl-3.0.html Стандартную общественную лицензию GNU версии 3 .UE или более позднюю, чтобы узнать об условиях авторского права. Мы не несем НИКАКОЙ ОТВЕТСТВЕННОСТИ. .PP Если вы обнаружите ошибки в переводе этой страницы руководства, пожалуйста, отправьте электронное письмо на .MT man-pages-ru-talks@lists.sourceforge.net .ME .