clock_getcpuclockid(3) | Library Functions Manual | clock_getcpuclockid(3) |
NOM
clock_getcpuclockid - Obtenir l'identifiant de l'horloge CPU d'un processus
BIBLIOTHÈQUE
Bibliothèque C standard (libc, -lc), depuis la glibc 2.17
Avant la glibc 2.17, bibliothèque de temps réel (librt, -lrt)
SYNOPSIS
#include <time.h>
int clock_getcpuclockid(pid_t pid, clockid_t *clockid);
clock_getcpuclockid() :
_POSIX_C_SOURCE >= 200112L
DESCRIPTION
The clock_getcpuclockid() function obtains the ID of the CPU-time clock of the process whose ID is pid, and returns it in the location pointed to by clockid. If pid is zero, then the clock ID of the CPU-time clock of the calling process is returned.
VALEUR RENVOYÉE
En cas de réussite, clock_getcpuclockid() renvoie 0. En cas d'erreur, elle renvoie un numéro d'erreur positif listé dans ERRORS.
ERREURS
- ENOSYS
- Le noyau ne permet pas d'obtenir l'horloge CPU d'un autre processus et pid ne correspond pas au processus appelant.
- EPERM
- The caller does not have permission to access the CPU-time clock of the process specified by pid. (Specified in POSIX.1-2001; does not occur on Linux unless the kernel does not support obtaining the per-process CPU-time clock of another process.)
- ESRCH
- Il n'y a pas de processus ayant pour identifiant pid
VERSIONS
The clock_getcpuclockid() function is available since glibc 2.2.
ATTRIBUTS
Pour une explication des termes utilisés dans cette section, consulter attributes(7).
Interface | Attribut | Valeur |
clock_getcpuclockid() | Sécurité des threads | MT-Safe |
STANDARDS
POSIX.1-2001, POSIX.1-2008.
NOTES
Un appel à clock_gettime(2) avec l'identifiant d'horloge obtenu par un appel à clock_getcpuclockid() avec un pid de 0 revient à utiliser l'identifiant d'horloge CLOCK_PROCESS_CPUTIME_ID.
EXEMPLES
Le programme d'exemple ci-dessous obtient l'identifiant de l'horloge CPU du processus dont l'identifiant est fourni sur la ligne de commande, puis utilise clock_gettime(2) pour obtenir l'heure de cette horloge. Un exemple d'exécution suit :
$ ./a.out 1 # Show CPU clock of init process CPU-time clock for PID 1 is 2.213466748 seconds
Source du programme
#define _XOPEN_SOURCE 600 #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> int main(int argc, char *argv[]) {
clockid_t clockid;
struct timespec ts;
if (argc != 2) {
fprintf(stderr, "%s <process-ID>\n", argv[0]);
exit(EXIT_FAILURE);
}
if (clock_getcpuclockid(atoi(argv[1]), &clockid) != 0) {
perror("clock_getcpuclockid");
exit(EXIT_FAILURE);
}
if (clock_gettime(clockid, &ts) == -1) {
perror("clock_gettime");
exit(EXIT_FAILURE);
}
printf("CPU-time clock for PID %s is %jd.%09ld seconds\n",
argv[1], (intmax_t) ts.tv_sec, ts.tv_nsec);
exit(EXIT_SUCCESS); }
VOIR AUSSI
clock_getres(2), timer_create(2), pthread_getcpuclockid(3), time(7)
TRADUCTION
La traduction française de cette page de manuel a été créée par Christophe Blaess https://www.blaess.fr/christophe/, Stéphan Rafin <stephan.rafin@laposte.net>, Thierry Vignaud <tvignaud@mandriva.com>, François Micaux, Alain Portal <aportal@univ-montp2.fr>, Jean-Philippe Guérard <fevrier@tigreraye.org>, Jean-Luc Coulon (f5ibh) <jean-luc.coulon@wanadoo.fr>, Julien Cristau <jcristau@debian.org>, Thomas Huriaux <thomas.huriaux@gmail.com>, Nicolas François <nicolas.francois@centraliens.net>, Florentin Duneau <fduneau@gmail.com>, Simon Paillard <simon.paillard@resel.enst-bretagne.fr>, Denis Barbier <barbier@debian.org> et David Prévot <david@tilapin.org>
Cette traduction est une documentation libre ; veuillez vous reporter à la GNU General Public License version 3 concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE.
Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à debian-l10n-french@lists.debian.org.
15 décembre 2022 | Pages du manuel de Linux 6.03 |