From: Denis Ovsienko <pilot@dgtu.donetsk.ua> To: devel@altlinux.ru Subject: [devel] IPC и сборка мусора Date: Sun, 7 Sep 2003 13:31:35 +0300 (EEST) Message-ID: <20030907132023.G96874@elefant.dgtu.donetsk.ua> (raw) Целью данного письма является показать, что можно программировать IPC так, чтобы не оставлять мусор, причём это не особенности замшелых ядер, описанные в устаревших книжках. Вот текст программы: #include <string.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #define SIZE 1024 int main (int argc, char * argv[]) { key_t key = ftok (argv[0], 1); int shmid = shmget (key, SIZE, IPC_CREAT | 0600); void * memory = NULL; if (shmid == -1) return 1; memory = shmat (shmid, NULL, 0); if (argc >= 2 && !strcmp (argv[1], "rm")) shmctl (shmid, IPC_RMID, NULL); return 0; } Вот 3 последовательных запуска. Прошу обратить внимание на уже существующий до запуска сегмент: nattch=2, status=dest. После двух shmdt() либо после простого завершения 2-х подсоединённых процессов сегмент будет удалён. Но вернёмся к тесту: [pilot@m46 devel]$ ipcs ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000000 27131910 pilot 777 393216 2 dest ------ Semaphore Arrays -------- key semid owner perms nsems ------ Message Queues -------- key msqid owner perms used-bytes messages [pilot@m46 devel]$ ./IPCtest rm [pilot@m46 devel]$ ipcs ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000000 27131910 pilot 777 393216 2 dest ------ Semaphore Arrays -------- key semid owner perms nsems ------ Message Queues -------- key msqid owner perms used-bytes messages [pilot@m46 devel]$ ./IPCtest [pilot@m46 devel]$ ipcs ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x0102be47 53968897 pilot 600 1024 0 0x00000000 27131910 pilot 777 393216 2 dest ------ Semaphore Arrays -------- key semid owner perms nsems ------ Message Queues -------- key msqid owner perms used-bytes messages [pilot@m46 devel]$ ./IPCtest rm [pilot@m46 devel]$ ipcs ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000000 27131910 pilot 777 393216 2 dest ------ Semaphore Arrays -------- key semid owner perms nsems ------ Message Queues -------- key msqid owner perms used-bytes messages [pilot@m46 devel]$ uname -a Linux m46.pilot 2.4.20-alt5-pim #1 Tue Apr 22 22:09:54 EEST 2003 i686 unknown unknown GNU/Linux Вот и всё, и не нужно говорить, что это не работает. Точно такое же поведение можно ожидать и на других POSIX-системах. ALTLinux Master 2.2, ядро 2.4.20-alt5-up с включенным IGMP+PIM. -- DO4-UANIC
next reply other threads:[~2003-09-07 10:31 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-09-07 10:31 Denis Ovsienko [this message] 2003-09-07 13:19 ` Dmitry V. Levin 2003-09-07 15:01 ` Denis Ovsienko 2003-09-07 15:26 ` Dmitry V. Levin 2003-09-08 9:35 ` Denis Ovsienko 2003-09-08 10:17 ` Dmitry V. Levin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20030907132023.G96874@elefant.dgtu.donetsk.ua \ --to=pilot@dgtu.donetsk.ua \ --cc=devel@altlinux.ru \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
ALT Linux Team development discussions This inbox may be cloned and mirrored by anyone: git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \ devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru public-inbox-index devel Example config snippet for mirrors. Newsgroup available over NNTP: nntp://lore.altlinux.org/org.altlinux.lists.devel AGPL code for this site: git clone https://public-inbox.org/public-inbox.git