{"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\/et\/blog\/administrirovanie\/znakomimsya-s-semaforami-v-linux","title":{"rendered":"Tutvume semaforidega Linuxis","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p><b><i>Artikli t\u00f5lge on koostatud kursuse alguse eel\u00f5htul <noindex><a rel=\"nofollow\" href=\"https:\/\/otus.pw\/kRX0\/\">\u00abAdministrator Linux.Basic\u00bb<\/a><\/noindex>.<\/p>\n<p><img decoding=\"async\" alt=\"Tutvume semaforidega Linuxis\" src=\"\/wp-content\/uploads\/2020\/10\/93604a8804db099834e873de072cbfc9.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\n<\/i><\/b><\/p>\n<p>Semafor on mehhanism, mis v\u00f5imaldab konkureerivatel protsessidel ja voogudel kasutada \u00fchiseid ressursse ning aitab lahendada erinevaid s\u00fcnkroniseerimise probleeme, nagu v\u00f5idujooksud, deadlockid (vastastikused lukustused) ja voogude vale k\u00e4itumine.<\/p>\n<p>Nende probleemide lahendamiseks on tuumas olemas sellised vahendid nagu muteksid, semaforid, signaalid ja t\u00f5kked.<\/p>\n<p>On kolm t\u00fc\u00fcpi semafore:<\/p>\n<ol>\n<li>Binaarsed semaforid (binary semaphore)<\/li>\n<li>Semafori-loendurid (counting semaphore)<\/li>\n<li>Semaforide massiivid (semaphore set)<\/li>\n<\/ol>\n<p><noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<h3>IPC oleku vaatamine<\/h3>\n<p>\nAllpool toodud k\u00e4skude abil on v\u00f5imalik saada teavet praeguse oleku kohta interprotsesside suhtluse (inter-process communication, IPC) vahenditest.<\/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>Aktiivsed semaforide massiivid<\/h3>\n<p>\nTeabe kuvamine aktiivsete semaforide massiivide kohta.<\/p>\n<pre><code class=\"bash\"># ipcs -s\n------ Semaphore Arrays --------\nkey semid owner perms nsems<\/code><\/pre>\n<p><\/p>\n<h3>Jagatud m\u00e4lusegmendid<\/h3>\n<p>\nAktiivsete jagatud m\u00e4lu segmentide teabe vaatamine.<\/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>Piirangud<\/h3>\n<p>\nMeeskond <code>ipcs -l<\/code> kuvatakse jagatud m\u00e4lu, semaforite ja s\u00f5numite piirangud.<\/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>Jagatud m\u00e4lu<\/h3>\n<p>\nAllpool olev k\u00e4sk kuvab jagatud m\u00e4lu.<\/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>Ressursside looja<\/h3>\n<p>\nK\u00e4sk kuvab ressursi omaniku ja looja kasutaja ja grupi.<\/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>IPC vahendite kasutamine<\/h3>\n<p>\nAllpool toodud n\u00e4ites on parameeter <code>-u<\/code> kuvatakse kokkuv\u00f5te k\u00f5igi IPC vahendite kasutamisest.<\/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>\nTeenuste peatamisel tuleks ka semaforid ja jagatud m\u00e4lu segmendid eemaldada. Kui neid ei eemaldata, saab seda teha k\u00e4suga ipcrm, edastades IPC-objekti identifikaatori.<\/p>\n<pre><code class=\"bash\"># ipcs -a\n# ipcrm -s &lt; sem id&gt;<\/code><\/pre>\n<p>\nSamuti saab semaforide piiranguid muuta, kasutades <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=\"Tutvume semaforidega Linuxis\" src=\"\/wp-content\/uploads\/2020\/10\/e9f6606dbef02ed0dd83662ed9b40015.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/a><\/noindex><br \/>\n<br \/>Allikas: <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.1.1 - 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\/et\/blog\/administrirovanie\/znakomimsya-s-semaforami-v-linux\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"et_EE\" \/>\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\/et\/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\udd47Tutvume semaforidega Linuxis | ProHoster","description":"Artikli t\u00f5lge on koostatud kursuse \u00abAdministrator Linux.Basic\u00bb alguse eel.","canonical_url":"https:\/\/prohoster.info\/et\/blog\/administrirovanie\/znakomimsya-s-semaforami-v-linux","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"et_EE","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\/et\/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\/et\/wp-json\/wp\/v2\/posts\/96138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/et\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/et\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/et\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/et\/wp-json\/wp\/v2\/comments?post=96138"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/et\/wp-json\/wp\/v2\/posts\/96138\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/et\/wp-json\/wp\/v2\/media\/96139"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/et\/wp-json\/wp\/v2\/media?parent=96138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/et\/wp-json\/wp\/v2\/categories?post=96138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/et\/wp-json\/wp\/v2\/tags?post=96138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}