From: Mikhail Efremov <sem@altlinux.ru> To: ALT Linux Sisyphus discussions <sisyphus@lists.altlinux.org> Subject: Re: [sisyphus] Q: Очень непростой вопрос на тему select() и сигналов Date: Fri, 10 Apr 2009 03:49:37 +0400 Message-ID: <200904100349.37693.sem@altlinux.ru> (raw) In-Reply-To: <m3iqldh29p.fsf@blard.localdomain> On Friday 10 April 2009 02:48:34 Michael Pozhidaev wrote: > Схематически код выглядит так: > > int there_was_sigchld = 0; Насколько я помню, единственный тип, который POSIX разрешает использовать для этого - sig_atomic_t. Да, это скорее всего typedef int, но если уж говорить об аккуратности... > > void main_loop() > { > while(1) > { > block_sigchld(); > check_sigchld(); > pselect(required_fds, and_signal_mask_with_enabled_sigchld); > check_data_from_fds_if_there_was_any(); > } > } Да, что-то вроде if (pselect(required_fds, and_signal_mask_with_enabled_sigchld) <0) if(errno == EINTR) check_sigchld(); > Если должно быть так, то что произойдёт, если sigchld пришёл в тот > краткий момент, когда он был заблокирован? pselect() увидит, что пока > сигнал был заблокирован, он приходил, и нужно сразу прекратить ожидание, > вызвать его обработчик и дать программе его обработать? Если нет, то > тогда мы вообще теряем получение SIGCHLD. Ещё есть интересная функция > sigpending(), но уместна ли она здесь, вот это непонятно. Блокировка сигнала != игнорирование сигнала. Блокированный сигнал не потеряется, просто не будет вызван обработчик пока его не разблокируют, что и делает pselect. А sigpending() думаю тут не нужен. По поводу реализации pselect в Linux не знаю, тут видимо надо сам его код смотреть, но man подсказывает альтернативное решение: On systems that lack pselect(), reliable (and more portable) signal trapping can be achieved using the self-pipe trick (where a signal handler writes a byte to a pipe whose other end is monitored by select() in the main program.) -- WBR, Mikhail Efremov
next prev parent reply other threads:[~2009-04-09 23:49 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-04-09 22:48 Michael Pozhidaev 2009-04-09 23:49 ` Mikhail Efremov [this message] 2009-04-10 1:50 ` Michael Pozhidaev 2009-04-10 9:40 ` Mikhail Efremov 2009-04-10 12:36 ` Sergey Vlasov 2009-04-10 16:00 ` Michael Pozhidaev 2009-04-10 16:22 ` Mikhail Efremov
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=200904100349.37693.sem@altlinux.ru \ --to=sem@altlinux.ru \ --cc=sisyphus@lists.altlinux.org \ /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 Sisyphus discussions This inbox may be cloned and mirrored by anyone: git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/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 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \ sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru public-inbox-index sisyphus Example config snippet for mirrors. Newsgroup available over NNTP: nntp://lore.altlinux.org/org.altlinux.lists.sisyphus AGPL code for this site: git clone https://public-inbox.org/public-inbox.git