{"id":96138,"date":"2020-10-08T19:42:26","date_gmt":"2020-10-08T17:42:26","guid":{"rendered":"https:\/\/prohoster.info\/blog\/administrirovanie\/znakomimsya-s-semaforami-v-linux"},"modified":"2020-10-08T19:42:26","modified_gmt":"2020-10-08T17:42:26","slug":"znakomimsya-s-semaforami-v-linux","status":"publish","type":"post","link":"https:\/\/prohoster.info\/es\/blog\/administrirovanie\/znakomimsya-s-semaforami-v-linux","title":{"rendered":"Conociendo los sem\u00e1foros en Linux","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p><b><i>La traducci\u00f3n del art\u00edculo ha sido preparada en la v\u00edspera del inicio del curso <noindex><a rel=\"nofollow\" href=\"https:\/\/otus.pw\/kRX0\/\">\u00abAdministrador Linux.Basic\u00bb<\/a><\/noindex>.<\/p>\n<p><img decoding=\"async\" alt=\"Conociendo los sem\u00e1foros en Linux\" src=\"\/wp-content\/uploads\/2020\/10\/93604a8804db099834e873de072cbfc9.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\n<\/i><\/b><\/p>\n<p>Un sem\u00e1foro es un mecanismo que permite a los procesos y hilos en competencia trabajar con recursos compartidos y ayuda a resolver diversos problemas de sincronizaci\u00f3n como condiciones de carrera, bloqueos mutuos y comportamientos incorrectos de hilos.<\/p>\n<p>Para abordar estos problemas, el n\u00facleo cuenta con herramientas como mutexes, sem\u00e1foros, se\u00f1ales y barreras.<\/p>\n<p>Existen tres tipos de sem\u00e1foros:<\/p>\n<ol>\n<li>Sem\u00e1foros binarios (binary semaphore)<\/li>\n<li>Sem\u00e1foros contadores (counting semaphore)<\/li>\n<li>Conjuntos de sem\u00e1foros (semaphore set)<\/li>\n<\/ol>\n<p><noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<h3>Ver el estado de IPC<\/h3>\n<p>\nCon los comandos que se indican a continuaci\u00f3n, se puede obtener informaci\u00f3n sobre el estado actual de los medios de comunicaci\u00f3n entre procesos (inter-process communication, IPC).<\/p>\n<pre><code class=\"bash\"># ipcs\n------ Shared Memory Segments --------\nkey shmid owner perms bytes nattch status\n0x00000000 65536 root 600 393216 2 dest\n0x00000000 98305 root 600 393216 2 dest\n0x00000000 131074 root 600 393216 2 dest\n0x00000000 163843 root 600 393216 2 dest\n0x00000000 196612 root 600 393216 2 dest\n0x00000000 229381 root 600 393216 2 dest\n0x00000000 262150 root 600 393216 2 dest\n0x00000000 294919 root 600 393216 2 dest\n0x00000000 327688 root 600 393216 2 dest\n------ Semaphore Arrays --------\n\nkey semid owner perms nsems\n\n------ Message Queues --------\nkey msqid owner perms used-bytes messages<\/code><\/pre>\n<p><\/p>\n<h3>Conjuntos de sem\u00e1foros activos<\/h3>\n<p>\nMuestra informaci\u00f3n sobre los conjuntos de sem\u00e1foros activos.<\/p>\n<pre><code class=\"bash\"># ipcs -s\n------ Semaphore Arrays --------\nkey semid owner perms nsems<\/code><\/pre>\n<p><\/p>\n<h3>Segmentos de memoria compartida<\/h3>\n<p>\nVer informaci\u00f3n sobre los segmentos activos de memoria compartida.<\/p>\n<pre><code class=\"bash\"># ipcs -m\n------ Shared Memory Segments --------\nkey shmid owner perms bytes nattch status\n0x00000000 65536 root 600 393216 2 dest\n0x00000000 98305 root 600 393216 2 dest<\/code><\/pre>\n<p><\/p>\n<h3>L\u00edmites<\/h3>\n<p>\nComando <code>ipcs -l<\/code> muestra los l\u00edmites de memoria compartida, sem\u00e1foros y mensajes.<\/p>\n<pre><code class=\"bash\"># ipcs -l\n------ Shared Memory Limits --------\nmax number of segments = 4096\nmax seg size (kbytes) = 4194303\nmax total shared memory (kbytes) = 1073741824\nmin seg size (bytes) = 1\n\n------ Semaphore Limits --------\nmax number of arrays = 128\nmax semaphores per array = 250\nmax semaphores system wide = 32000\nmax ops per semop call = 32\nsemaphore max value = 32767\n\n------ Messages: Limits --------\nmax queues system wide = 16\nmax size of message (bytes) = 65536\ndefault max size of queue (bytes) = 65536<\/code><\/pre>\n<p><\/p>\n<h3>Memoria compartida<\/h3>\n<p>\nEl siguiente comando muestra la memoria compartida.<\/p>\n<pre><code class=\"bash\"># ipcs -m\n------ Shared Memory Segments --------\nkey shmid owner perms bytes nattch status\n0x00000000 65536 root 600 393216 2 dest\n0x00000000 98305 root 600 393216 2 dest\n0x00000000 131074 root 600 393216 2 dest\n0x00000000 163843 root 600 393216 2 dest\n0x00000000 196612 root 600 393216 2 dest\n0x00000000 229381 root 600 393216 2 dest\n0x00000000 262150 root 600 393216 2 dest\n0x00000000 294919 root 600 393216 2 dest\n0x00000000 327688 root 600 393216 2 dest<\/code><\/pre>\n<p><\/p>\n<h3>Creadores de recursos<\/h3>\n<p>\nEl comando muestra el usuario y el grupo del propietario y creador del recurso.<\/p>\n<pre><code class=\"bash\"># ipcs -m -c\n\n------ Shared Memory Segment Creators\/Owners --------\nshmid perms cuid cgid uid gid\n65536 600 root root root root\n98305 600 root root root root\n131074 600 root root root root\n163843 600 root root root root\n196612 600 root root root root\n229381 600 root root root root\n262150 600 root root root root\n294919 600 root root root root\n327688 600 root root root root<\/code><\/pre>\n<p><\/p>\n<h3>Uso de los medios de IPC<\/h3>\n<p>\nEn el ejemplo que se presenta a continuaci\u00f3n, el par\u00e1metro <code>-u<\/code> muestra un resumen sobre el uso de todos los medios de IPC.<\/p>\n<pre><code class=\"bash\"># ipcs -u\n\n------ Shared Memory Status --------\nsegments allocated 9\npages allocated 864\npages resident 477\npages swapped 0\nSwap performance: 0 attempts 0 successes\n\n------ Semaphore Status --------\nused arrays = 0\nallocated semaphores = 0\n\n------ Messages: Status --------\nallocated queues = 0\nused headers = 0\nused space = 0 bytes<\/code><\/pre>\n<p>\nAl detener los servicios, los sem\u00e1foros y los segmentos de memoria compartida tambi\u00e9n deben ser eliminados. Si no se eliminan, se puede hacer usando el comando ipcrm, pasando el identificador del objeto IPC.<\/p>\n<pre><code class=\"bash\"># ipcs -a\n# ipcrm -s &lt; sem id&gt;<\/code><\/pre>\n<p>\nTambi\u00e9n se pueden modificar los l\u00edmites de los sem\u00e1foros usando <code>sysctl<\/code>.<\/p>\n<pre><code class=\"bash\"># \/sbin\/sysctl -w kernel.sem=250\n<\/code><\/pre>\n<p>\n<noindex><a rel=\"nofollow\" href=\"https:\/\/otus.pw\/kRX0\/\"><img decoding=\"async\" alt=\"Conociendo los sem\u00e1foros en Linux\" src=\"\/wp-content\/uploads\/2020\/10\/e9f6606dbef02ed0dd83662ed9b40015.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/a><\/noindex><br \/>\n<br \/>Fuente: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/522418\/\">habr.com<\/a> <\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 \u00abAdministrator Linux.Basic\u00bb. \u0421\u0435\u043c\u0430\u0444\u043e\u0440 \u2013 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043d\u043a\u0443\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c \u0438 \u043f\u043e\u0442\u043e\u043a\u0430\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043e\u0431\u0449\u0438\u043c\u0438 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0433\u043e\u043d\u043a\u0438, \u0434\u0435\u0434\u043b\u043e\u043a\u0438 (\u0432\u0437\u0430\u0438\u043c\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438) \u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u044f\u0434\u0440\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u043a\u0430\u043a \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b, \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u044b, \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u0438 \u0431\u0430\u0440\u044c\u0435\u0440\u044b. [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":96139,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-96138","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.2 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 \u00abAdministrator Linux.Basic\u00bb.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/es\/blog\/administrirovanie\/znakomimsya-s-semaforami-v-linux\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.2\" \/>\n\t\t<meta property=\"og:locale\" content=\"es_ES\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0417\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430\u043c\u0438 \u0432 Linux | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 \u00abAdministrator Linux.Basic\u00bb.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/es\/blog\/administrirovanie\/znakomimsya-s-semaforami-v-linux\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2020-10-08T17:42:26+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-10-08T17:42:26+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Conociendo los sem\u00e1foros en Linux | ProHoster","description":"La traducci\u00f3n del art\u00edculo fue preparada en anticipaci\u00f3n al inicio del curso \u00abAdministrador Linux.Basic\u00bb.","canonical_url":"https:\/\/prohoster.info\/es\/blog\/administrirovanie\/znakomimsya-s-semaforami-v-linux","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"es_ES","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0417\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430\u043c\u0438 \u0432 Linux | ProHoster","og:description":"\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 \u00abAdministrator Linux.Basic\u00bb.","og:url":"https:\/\/prohoster.info\/es\/blog\/administrirovanie\/znakomimsya-s-semaforami-v-linux","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2020-10-08T17:42:26+00:00","article:modified_time":"2020-10-08T17:42:26+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"96138","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":null,"breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 10:51:01","updated":"2022-09-29 07:52:31","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/es\/wp-json\/wp\/v2\/posts\/96138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/es\/wp-json\/wp\/v2\/comments?post=96138"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/es\/wp-json\/wp\/v2\/posts\/96138\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/es\/wp-json\/wp\/v2\/media\/96139"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/es\/wp-json\/wp\/v2\/media?parent=96138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/es\/wp-json\/wp\/v2\/categories?post=96138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/es\/wp-json\/wp\/v2\/tags?post=96138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}