.\" -*- coding: UTF-8 -*- .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH getpid 2 "30 марта 2023 г." "Linux man\-pages 6.05.01" .SH ИМЯ getpid, getppid \- получение идентификатора процесса .SH LIBRARY Standard C library (\fIlibc\fP, \fI\-lc\fP) .SH СИНТАКСИС .nf \fB#include \fP .PP \fBpid_t getpid(void);\fP \fBpid_t getppid(void);\fP .fi .SH ОПИСАНИЕ Вызов \fBgetpid\fP() возвращает идентификатор (PID) вызвавшего процесса (часто используется функциями, которые генерируют уникальные имена временных файлов). .PP Вызов \fBgetppid\fP() возвращает идентификатор процесса, являющегося родительским по отношению к вызвавшему процессу. Результат равен идентификатору процесса, который создал этот процесс с помощью \fBfork\fP(), или идентификатору процесса, который заместил родителя (или \fBinit\fP(1), или процесс «сборщик», определённый с помощью операции \fBPR_SET_CHILD_SUBREAPER\fP вызовом \fBprctl\fP(2)), если этот процесс уже завершён. .SH ОШИБКИ Функции всегда завершаются успешно. .SH ВЕРСИИ На Alpha вместо пары системных вызовов \fBgetpid\fP() и \fBgetppid\fP() предоставляется один \fBgetxpid\fP(), который возвращает пару PID и родительский PID. Обёрточные функции glibc \fBgetpid\fP() и \fBgetppid\fP() скрывают это. Подробности об отображении регистров смотрите в \fBsyscall\fP(2). .SH СТАНДАРТЫ POSIX.1\-2008. .SH ИСТОРИЯ POSIX.1\-2001, 4.3BSD, SVr4. .SS "Отличия между библиотекой C и ядром" .\" The following program demonstrates this "feature": .\" .\" #define _GNU_SOURCE .\" #include .\" #include .\" #include .\" #include .\" #include .\" #include .\" .\" int .\" main(int argc, char *argv[]) .\" { .\" /* The following statement fills the getpid() cache */ .\" .\" printf("parent PID = %ld\n", (intmax_t) getpid()); .\" .\" if (syscall(SYS_fork) == 0) { .\" if (getpid() != syscall(SYS_getpid)) .\" printf("child getpid() mismatch: getpid()=%jd; " .\" "syscall(SYS_getpid)=%ld\n", .\" (intmax_t) getpid(), (long) syscall(SYS_getpid)); .\" exit(EXIT_SUCCESS); .\" } .\" wait(NULL); .\"} From glibc 2.3.4 up to and including glibc 2.24, the glibc wrapper function for \fBgetpid\fP() cached PIDs, with the goal of avoiding additional system calls when a process calls \fBgetpid\fP() repeatedly. Normally this caching was invisible, but its correct operation relied on support in the wrapper functions for \fBfork\fP(2), \fBvfork\fP(2), and \fBclone\fP(2): if an application bypassed the glibc wrappers for these system calls by using \fBsyscall\fP(2), then a call to \fBgetpid\fP() in the child would return the wrong value (to be precise: it would return the PID of the parent process). In addition, there were cases where \fBgetpid\fP() could return the wrong value even when invoking \fBclone\fP(2) via the glibc wrapper function. (For a discussion of one such case, see BUGS in \fBclone\fP(2).) Furthermore, the complexity of the caching code had been the source of a few bugs within glibc over the years. .PP .\" commit c579f48edba88380635ab98cb612030e3ed8691e .\" https://sourceware.org/glibc/wiki/Release/2.25#pid_cache_removal .\" FIXME . .\" Review progress of https://bugzilla.redhat.com/show_bug.cgi?id=1469757 Because of the aforementioned problems, since glibc 2.25, the PID cache is removed: calls to \fBgetpid\fP() always invoke the actual system call, rather than returning a cached value. .SH ЗАМЕЧАНИЯ Если родитель вызывающего находит в другом пространстве имён PID (смотрите \fBpid_namespaces\fP(7)), то \fBgetppid\fP() возвращает 0. .PP Со стороны ядра PID (одинаков у всех нитей в многонитевом процессе) иногда называют идентификатором группы нитей (TGID). Он отличается от идентификатора нити (TID), который является уникальным для каждой нити. Подробней смотрите в \fBgettid\fP(2) и описание флага \fBCLONE_THREAD\fP в \fBclone\fP(2). .SH "СМ. ТАКЖЕ" \fBclone\fP(2), \fBfork\fP(2), \fBgettid\fP(2), \fBkill\fP(2), \fBexec\fP(3), \fBmkstemp\fP(3), \fBtempnam\fP(3), \fBtmpfile\fP(3), \fBtmpnam\fP(3), \fBcredentials\fP(7), \fBpid_namespaces\fP(7) .PP .SH ПЕРЕВОД Русский перевод этой страницы руководства был сделан Azamat Hackimov , Dmitry Bolkhovskikh , Vladislav , 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 .