Читаем Linux программирование в примерах полностью

_Exit()fpathconf()raise()sigqueue()
_exit()fstat()read()sigset()
accept()fsync()readlink()sigsuspend()
access()ftruncate()recv()sleep()
aio_error()getegid()recvfrom()socket()
aio_return()geteuid()recvmsg()socketpair()
aio_suspend()getgid()rename()stat()
alarm()getgroups()rmdir()sysmlink()
bind()getpeername()select()sysconf()
cfgetispeed()getpgrp()sem_post()tcdrain()
cfgetospeed()getpid()send()tcflow()
cfsetispeed()getppid()sendmsg()tcflush()
cfsetospeed()getsockname()sendto()tcgetattr()
chdir()getsockopt()setgid()tcgetpgrp()
chmod()getuid()setpgid()tcsendbreak()
chown()kill()setsid()tcsetattr()
clock_gettime()link()setsockopt()tcsetpgrp()
close()listen()setuid()time()
connect()lseek()shutdown()timer_getoverrun()
creat()lstat()sigaction()timer_gettime()
dup()mkdir()sigaddset()timer_settime()
dup2()mkfifo()sigdelset()times()
execle()open()sigemptyset()umask()
execve()pathconf()sigfillset()uname()
fchmod()pause()sigismember()unlink()
fchown()pipe()signal()utime()
fcntl()poll()sigpause()wait()
fdatasync()posix_trace_event()sigpending()waitpid()
fork()pselect()sigprocmask()write()

10.4.7. Наша история до настоящего времени, эпизод 1

Сигналы являются сложной темой, и она становится еще более сбивающей с толку. Поэтому давайте на время сделаем остановку, сделаем шаг назад и подведем итог обсужденному до сих пор:

• Сигналы являются указанием того, что произошло некоторое внешнее событие.

• raise() является функцией ISO С для отправки сигнала текущему процессу. Как отправлять сигналы другим процессам, нам еще предстоит описать.

• signal() контролирует диспозицию сигнала, т.е. реакцию процесса на сигнал, когда он появляется. Сигнал можно оставить системе для обработки по умолчанию, проигнорировать или перехватить.

• Когда сигнал перехватывается, вызывается функция-обработчик. Вот где сложность начинает поднимать свою безобразную голову:

 • ISO С не определяет, восстанавливается ли диспозиция сигнала по умолчанию до вызова обработчика или она остается на месте. Первое является поведением V7 и современных систем System V, таких, как Solaris. Последнее является поведением BSD, используемым также в GNU/Linux. (Для форсирования поведения BSD может использоваться функция POSIX bsd_signal().)

• То, что случается при прерывании сигналом системного вызова, также различается в традиционной и BSD линейках. Традиционные системы возвращают -1 с errno, установленным в EINTR. BSD системы повторно запускают системный вызов после возвращения из обработчика. Макрос GLIBC TEMP_FAILURE_RETRY() может помочь вам написать код для обработки системных вызовов, возвращающих -1 с errno, установленным в EINTR.

POSIX требует, чтобы частично выполненный системный вызов возвращал успешное завершение, указав, сколько работы было выполнено. Системный вызов, который еще не начал выполняться, вызывается повторно.

• Механизм signal() предоставляет плодотворную почву для появления условий гонки. В этой ситуации помогает тип данных ISO С sig_atomic_t, но он не решает проблему, и определенный таким способом механизм не может обезопасить от проявления условий гонки.

• Применяется ряд дополнительных предостережений, и в частности, из обработчика сигнала безопасно может вызываться лишь часть стандартных библиотечных функций.

Несмотря на эти проблемы интерфейса signal() для простых программ достаточно, и он все еще широко используется.

10.5. API сигналов System V Release 3: sigset() и др.

Перейти на страницу:

Похожие книги

C++ Primer Plus
C++ Primer Plus

C++ Primer Plus is a carefully crafted, complete tutorial on one of the most significant and widely used programming languages today. An accessible and easy-to-use self-study guide, this book is appropriate for both serious students of programming as well as developers already proficient in other languages.The sixth edition of C++ Primer Plus has been updated and expanded to cover the latest developments in C++, including a detailed look at the new C++11 standard.Author and educator Stephen Prata has created an introduction to C++ that is instructive, clear, and insightful. Fundamental programming concepts are explained along with details of the C++ language. Many short, practical examples illustrate just one or two concepts at a time, encouraging readers to master new topics by immediately putting them to use.Review questions and programming exercises at the end of each chapter help readers zero in on the most critical information and digest the most difficult concepts.In C++ Primer Plus, you'll find depth, breadth, and a variety of teaching techniques and tools to enhance your learning:• A new detailed chapter on the changes and additional capabilities introduced in the C++11 standard• Complete, integrated discussion of both basic C language and additional C++ features• Clear guidance about when and why to use a feature• Hands-on learning with concise and simple examples that develop your understanding a concept or two at a time• Hundreds of practical sample programs• Review questions and programming exercises at the end of each chapter to test your understanding• Coverage of generic C++ gives you the greatest possible flexibility• Teaches the ISO standard, including discussions of templates, the Standard Template Library, the string class, exceptions, RTTI, and namespaces

Стивен Прата

Программирование, программы, базы данных