.\" -*- coding: UTF-8 -*- .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it) .\" and Copyright (C) 2020 Michael Kerrisk .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\" Modified Tue Oct 22 17:54:56 1996 by Eric S. Raymond .\" Modified 1 Jan 2002, Martin Schulze .\" Modified 4 Jan 2002, Michael Kerrisk .\" Modified, 27 May 2004, Michael Kerrisk .\" Added notes on capability requirements .\" Modified, 11 Nov 2004, Michael Kerrisk .\" Language and formatting clean-ups .\" Added notes on /proc files .\" Rewrote BUGS note about semget()'s failure to initialize .\" semaphore values .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH semget 2 "3 maja 2023 r." "Linux man\-pages 6.05.01" .SH NAZWA semget \- pobranie identyfikatora zestawu semaforów Systemu V .SH BIBLIOTEKA Standardowa biblioteka C (\fIlibc\fP, \fI\-lc\fP) .SH SKŁADNIA .nf \fB#include \fP .fi .PP \fBint semget(key_t \fP\fIkey\fP\fB,\fP \fBint \fP\fInsems\fP\fB,\fP \fBint \fP\fIsemflg\fP\fB);\fP .SH OPIS The \fBsemget\fP() system call returns the System\ V semaphore set identifier associated with the argument \fIkey\fP. It may be used either to obtain the identifier of a previously created semaphore set (when \fIsemflg\fP is zero and \fIkey\fP does not have the value \fBIPC_PRIVATE\fP), or to create a new set. .PP Nowy zestaw składający się z \fInsems\fP semaforów zostanie utworzony, jeśli parametr \fIkey\fP będzie mieć wartość \fBIPC_PRIVATE\fP lub gdy zestaw semaforów skojarzony z \fIkey\fP nie istnieje, a w parametrze \fIsemflg\fP zostanie przekazany znacznik \fBIPC_CREAT\fP. .PP Jeśli w parametrze \fIsemflg\fP podano zarówno \fBIPC_CREAT\fP, jak i \fBIPC_EXCL\fP oraz już istnieje zestaw semaforów o kluczu \fIkey\fP, to \fBsemget\fP() kończy się błędem, ustawiając \fIerrno\fP na wartość \fBEEXIST\fP. (Działa to analogicznie do \fBO_CREAT | O_EXCL\fP w \fBopen\fP(2)). .PP Upon creation, the least significant 9 bits of the argument \fIsemflg\fP define the permissions (for owner, group, and others) for the semaphore set. These bits have the same format, and the same meaning, as the \fImode\fP argument of \fBopen\fP(2) (though the execute permissions are not meaningful for semaphores, and write permissions mean permission to alter semaphore values). .PP Podczas tworzenia nowego zestawu semaforów \fBsemget\fP() inicjuje związaną z zestawem semaforów strukturę \fIsemid_ds\fP (patrz \fBsemctl\fP(2)) w następujący sposób: .IP \[bu] 3 \fIsem_perm.cuid\fP i \fIsem_perm.uid\fP przyjmują wartość efektywnego identyfikatora właściciela procesu wywołującego. .IP \[bu] \fIsem_perm.cgid\fP i \fIsem_perm.gid\fP przyjmują wartość efektywnego identyfikatora grupy procesu wywołującego. .IP \[bu] 9 najmniej znaczących bitów pola \fIsem_perm.mode\fP jest kopiowanych z 9 najmniej znaczących bitów \fIsemflg\fP. .IP \[bu] \fIsem_nsems\fP jest ustawiane na wartość \fInsems\fP. .IP \[bu] \fIsem_otime\fP przyjmie wartość 0. .IP \[bu] \fIsem_ctime\fP przypisywany jest bieżący czas. .PP Parametr \fInsems\fP może mieć wartość 0 (nie jest brany pod uwagę), jeśli nie będzie tworzony zestaw semaforów. W przeciwnym przypadku parametr \fInsems\fP musi być większy od 0 i mniejszy lub równy maksymalnej liczbie semaforów w zestawie (\fBSEMMSL\fP). .PP .\" and a check is made to see if it is marked for destruction. Jeżeli zestaw semaforów już istnieje, to weryfikowane są uprawnienia. .SH "WARTOŚĆ ZWRACANA" On success, \fBsemget\fP() returns the semaphore set identifier (a nonnegative integer). On failure, \-1 is returned, and \fIerrno\fP is set to indicate the error. .SH BŁĘDY .TP \fBEACCES\fP A semaphore set exists for \fIkey\fP, but the calling process does not have permission to access the set, and does not have the \fBCAP_IPC_OWNER\fP capability in the user namespace that governs its IPC namespace. .TP \fBEEXIST\fP .\" .TP .\" .B EIDRM .\" The semaphore set is marked to be deleted. \fBIPC_CREAT\fP i \fBIPC_EXCL\fP określono w \fIsemflg\fP, lecz zestaw semaforów dla \fIkey\fP już istnieje. .TP \fBEINVAL\fP \fInsems\fP jest mniejsze niż 0 lub większe niż ograniczenie liczby semaforów w zestawie (\fBSEMMSL\fP) .TP \fBEINVAL\fP Zestaw semaforów, do którego odnosi się \fIkey\fP już istnieje, lecz \fInsems\fP jest większe niż liczba semaforów w tym zestawie. .TP \fBENOENT\fP Nie ma zestawu semaforów o identyfikatorze \fIkey\fP i znacznik \fBIPC_CREAT\fP nie został przekazany w parametrze \fIsemflg\fP. .TP \fBENOMEM\fP Zestaw semaforów powinien zostać utworzony, ale w systemie brak jest pamięci na utworzenie nowej struktury danych. .TP \fBENOSPC\fP Nastąpiła próba przekroczenia ograniczenia liczby zestawów (\fBSEMMNI\fP) lub łącznej liczby semaforów w systemie (\fBSEMMNS\fP). .SH STANDARDY POSIX.1\-2008. .SH HISTORIA .\" SVr4 documents additional error conditions EFBIG, E2BIG, EAGAIN, .\" ERANGE, EFAULT. SVr4, POSIX.1\-2001. .SH UWAGI .\" \fBIPC_PRIVATE\fP nie jest znacznikiem, ale szczególną wartością typu \fIkey_t\fP. Jeśli wartość ta zostanie użyta jako parametr \fIkey\fP, to system uwzględni jedynie 9 najniższych bitów parametru \fImsgflg\fP i (w razie powodzenia) utworzy nowy zestaw semaforów. .SS "Inicjowanie semaforów" .\" In truth, every one of the many implementations that I've tested sets .\" the values to zero, but I suppose there is/was some obscure .\" implementation out there that does not. Wartości semaforów w nowo utworzonym zestawie są nieokreślone (POSIX.1\-2001 jasno o tym mówi, choć POSIX.1\-2008 określa, że przyszła wersja tego standardu może wymagać implementacji inicjującej semafory z wartością 0). Mimo że Linux, tak jak i wiele innych implementacji, nadaje im wartość początkową równą 0, to przenośne aplikacje nie powinny zależeć od tego zachowania i zamiast tego powinny wyraźnie inicjować semafory żądanymi wartościami. .PP .\" Aby zainicjować semafory, należy na zestawie semaforów użyć operacji \fBSETVAL\fP lub \fBSETALL\fP wywołania \fBsemctl\fP(2). W sytuacji gdy wiele procesów nie wie, który pierwszy zainicjuje zestaw semaforów, to aby uniknąć sytuacji wyścigu, można sprawdzić, czy pole \fIsem_otime\fP powiązanej struktury danych zwracanej przez operację \fBIPC_STAT\fP wywołania \fBsemctl\fP(2) ma wartość niezerową. .SS "Limity semaforów" Wywołania \fBsemget\fP() dotyczą następujące ograniczenia zasobów związanych z zestawami semaforów: .TP \fBSEMMNI\fP .\" commit e843e7d2c88b7db107a86bd2c7145dc715c058f4 .\" This /proc file is not available in Linux 2.2 and earlier -- MTK System\-wide limit on the number of semaphore sets. Before Linux 3.19, the default value for this limit was 128. Since Linux 3.19, the default value is 32,000. On Linux, this limit can be read and modified via the fourth field of \fI/proc/sys/kernel/sem\fP. .TP \fBSEMMSL\fP .\" commit e843e7d2c88b7db107a86bd2c7145dc715c058f4 Maximum number of semaphores per semaphore ID. Before Linux 3.19, the default value for this limit was 250. Since Linux 3.19, the default value is 32,000. On Linux, this limit can be read and modified via the first field of \fI/proc/sys/kernel/sem\fP. .TP \fBSEMMNS\fP Limit liczby semaforów w systemie: wartość zależna od lokalnych ustawień (pod Linuksem to ograniczenie można odczytać i zmienić, używając drugiego pola pliku \fI/proc/sys/kernel/sem\fP). Proszę zauważyć, że systemowa liczba semaforów jest również ograniczona przez iloczyn \fBSEMMSL\fP i \fBSEMMNI\fP. .SH USTERKI Nazwa \fBIPC_PRIVATE\fP prawdopodobnie nie jest najszczęśliwsza. \fBIPC_NEW\fP w sposób bardziej przejrzysty odzwierciedlałoby rolę tej wartości. .SH PRZYKŁADY The program shown below uses \fBsemget\fP() to create a new semaphore set or retrieve the ID of an existing set. It generates the \fIkey\fP for \fBsemget\fP() using \fBftok\fP(3). The first two command\-line arguments are used as the \fIpathname\fP and \fIproj_id\fP arguments for \fBftok\fP(3). The third command\-line argument is an integer that specifies the \fInsems\fP argument for \fBsemget\fP(). Command\-line options can be used to specify the \fBIPC_CREAT\fP (\fI\-c\fP) and \fBIPC_EXCL\fP (\fI\-x\fP) flags for the call to \fBsemget\fP(). The usage of this program is demonstrated below. .PP We first create two files that will be used to generate keys using \fBftok\fP(3), create two semaphore sets using those files, and then list the sets using \fBipcs\fP(1): .PP .in +4n .EX $ \fBtouch mykey mykey2\fP $ \fB./t_semget \-c mykey p 1\fP ID = 9 $ \fB./t_semget \-c mykey2 p 2\fP ID = 10 $ \fBipcs \-s\fP \& \-\-\-\-\-\- Semaphore Arrays \-\-\-\-\-\-\-\- key semid owner perms nsems 0x7004136d 9 mtk 600 1 0x70041368 10 mtk 600 2 .EE .in .PP Next, we demonstrate that when \fBsemctl\fP(2) is given the same \fIkey\fP (as generated by the same arguments to \fBftok\fP(3)), it returns the ID of the already existing semaphore set: .PP .in +4n .EX $ \fB./t_semget \-c mykey p 1\fP ID = 9 .EE .in .PP Finally, we demonstrate the kind of collision that can occur when \fBftok\fP(3) is given different \fIpathname\fP arguments that have the same inode number: .PP .in +4n .EX $ \fBln mykey link\fP $ \fBls \-i1 link mykey\fP 2233197 link 2233197 mykey $ \fB./t_semget link p 1\fP # Generates same key as \[aq]mykey\[aq] ID = 9 .EE .in .SS "Kod źródłowy programu" .\" SRC BEGIN (t_semget.c) \& .EX /* t_semget.c \& Licensed under GNU General Public License v2 or later. */ #include #include #include #include #include \& static void usage(const char *pname) { fprintf(stderr, "Usage: %s [\-cx] pathname proj\-id num\-sems\en", pname); fprintf(stderr, " \-c Use IPC_CREAT flag\en"); fprintf(stderr, " \-x Use IPC_EXCL flag\en"); exit(EXIT_FAILURE); } \& int main(int argc, char *argv[]) { int semid, nsems, flags, opt; key_t key; \& flags = 0; while ((opt = getopt(argc, argv, "cx")) != \-1) { switch (opt) { case \[aq]c\[aq]: flags |= IPC_CREAT; break; case \[aq]x\[aq]: flags |= IPC_EXCL; break; default: usage(argv[0]); } } \& if (argc != optind + 3) usage(argv[0]); \& key = ftok(argv[optind], argv[optind + 1][0]); if (key == \-1) { perror("ftok"); exit(EXIT_FAILURE); } \& nsems = atoi(argv[optind + 2]); \& semid = semget(key, nsems, flags | 0600); if (semid == \-1) { perror("semget"); exit(EXIT_FAILURE); } \& printf("ID = %d\en", semid); \& exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "ZOBACZ TAKŻE" \fBsemctl\fP(2), \fBsemop\fP(2), \fBftok\fP(3), \fBcapabilities\fP(7), \fBsem_overview\fP(7), \fBsysvipc\fP(7) .PP .SH TŁUMACZENIE Autorami polskiego tłumaczenia niniejszej strony podręcznika są: Rafał Lewczuk , Andrzej Krzysztofowicz , Robert Luberda i Michał Kułach . .PP Niniejsze tłumaczenie jest wolną dokumentacją. Bliższe informacje o warunkach licencji można uzyskać zapoznając się z .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License w wersji 3 .UE lub nowszej. Nie przyjmuje się ŻADNEJ ODPOWIEDZIALNOŚCI. .PP Błędy w tłumaczeniu strony podręcznika prosimy zgłaszać na adres listy dyskusyjnej .MT manpages-pl-list@lists.sourceforge.net .ME .