Соглашение | Публикация статей

Красивые рольшторы - roll-service.by

The signals under UNIX
Категория: English version

Consider the interaction between processes through the reception-transmission signals. We have said that the UNIX system can be built mechanism to interrupt the analogy of certain events that may occur when you work processes.
These developments, as well as the interruption, clearly defined for a specific version of OS, that is set of signals determined. The emergence signals almost as well as the emergence of interruptions may occur for the following reasons:
• some events within the program, for example, division by zero or overflow;
• developments related to the arrival of some information from the device, for example, an event associated with the transfer of the keyboard combination "Ctrl + C";
• developments related to the impact of one another, for example, "SIG_KILL".

The system has a fixed set of events that may occur. Each event has its own unique name and these names are usually common to all versions of UNIX. Such names are called signals.
The list of signals is in the include-ôàéëå "signal.h".
There are signals that are present in virtually all UNIX, but there are also signals that are specific only to a specific version of UNIX (FreeBSD, SCO UNIX, Linux, ...) For example, the version of BSD is a signal the suspension of the process, which is a reaction to the freezing process But there is a signal to unfreeze the process. This signal FreeBSD version.

A prototype of signal processing functions:
void (* signal (sig, fun)) ()
int sig;
void (* fun) ();

When a signal we send:
sig - the name of the signal;
fun - pointer to a function that will handle an event associated with the emergence of this signal. The function of signal returns a pointer to the previous processing of the signal.
We talked about that event associated with the emergence of a signal can be processed in three ways:
1. SIG_DEF - the standard response to the signal, which provides system;
2. SIG_IGN - ignoring the signal (it should be noted that not all signals can be ignored, for example, SIG_KILL);
3. Some user function signal processing.

Accordingly, indicating either the names of predefined constants, a pointer to a function that we want to determine how the function signal processor, you can preempt the response to a signal. Installation of signal processing happens once, it means that if we set some treatment, then under this rule will be processed only one event associated with the emergence of the signal. And at the entrance of the function processor sets a standard response to the signal. Return of the functions processor occurs at the point of interruption.
Here is an example of the "Alarm clock". OS means we will "start" alarm. The function initializes the alarm signal the emergence of SIG_ALRM.

main ()
char s [80];
signal (SIG_ALRM, alrm); / * set connection with the event SIG_ALRM function alrm * /
alarm (5); / * factory alarm clock * /
printf ( "Enter the name \ n");
for (;;)
printf ( "Name:");
if (gets (s, 80)! = NULL) break;
printf ( "OK! \ n");

alrm ()
printf ( "\ n waiting for the name \ n");
alarm (5);
signal (SIG_ALRM, alrm);

At the beginning of the program, we set the response to a signal SIG_ALRM - function alrm, we continue to plant an alarm clock, ask "Type a name and look forward to input character string. If the input line is delayed, it will call alrm, which reminded that the program "is waiting for the name", again zavedet alarm clock and put ourselves in the signal processing SIG_ALRM again. And so will be as long as there is no type.
There is a nuance: if the point system call occurs developments relating to the signal, the system stops the execution of the system call and returns a response equal to «-1». We can also examine the role of errno.
It should be noted that in one set only "their" handlers. Default handler or neglect of multiple sets, that is, it is not necessary every time to confirm after signal processing.

Two other functions that require us to organize the interaction between processes:. ...
1) int kill (int pid, sig) - a feature signal transfer process. It works as follows: the process is carried out with a number pid attempt signal which is the same sig. Accordingly, the signal can be transmitted through the processes belonging to one group. Response code: -1 if the signal is transmitted could not be explained, again, can be found in errno. The function kill can be used to verify the existence of the process with the specified ID. If the function is performed with sig = 0, this is a test message, which specifies: possible or not to transmit the signal process, if possible, the response code kill different from «-1». If pid = 0, then raised the signal is transmitted to all processes within the group.
2) int wait (int * wait_ret) - wait for developments in the filial process. If there is no filial process, the administration comes back immediately with a code of the response «-1» and decryption in errno. If in-son event occurred, then analyzed under the age of 16 bits in the sense wait_ret:
a) If the son suspended (trace or a signal), whereas older 8-bit wait_ret - êîä ñèãíàëà, êîòîðûé ïîëó ÷ èë ïðîöåññ-ñûí, a junior contain code 0177.
b) If the sons are done through an appeal to function exit. Then junior 8 bits equal to zero, a senior 8-bit code are determined by the function exit.
c) If the son ended because of the emergence of his neobrabatyvaemogo signal, the senior 8 bits equal to zero, a junior - the number of signal, which completed the process.

Feature wait returns process ID, if implemented, and «-1» otherwise. If one of these events occurred prior to a function, the result is returned immediately, then there is no expectation does not happen, it is said that information about events in the process is not irretrievably lost.

Let's look at another example. Our alarm clock is already mnogoprotsessny.

alr ()
printf ( "\ n Hurry!!! \ n");
signal (SIG_ALRM, alr);

main ()
char s [80]; int pid;
signal (SIG_ALRM, alr);
if (pid = fork ()) for (;;)
sleep (5); / * stop the process for 5 seconds * /
kill (pid, SIG_ALRM); / * send a signal SIG_ALRM process-son * /
print ( "name");
for (;;)
printf ( "name");
if gets (s, 80)! = NULL) break;
printf ( "OK! \ n");
kill (getpid (), SIG_KILL); / * kill the father loop * /

It should be noted that various versions of UNIX names signals may vary.
Our program is implemented in two processes.
As in the previous example, there is a function of response to a signal alr (), which displays the inscription and reinstalls the function of the response to the signal again for themselves. The main program, we also point out alr () as a reaction to SIG_ALRM. Then we start the process of filial and paternal process (endless loop), sleeps for 5 units of time, after which the filial process will be sent a signal SIG_ALRM. All that is below the cycle will be performed in-son: we look forward to entering the string if input implemented, it happens slaughter father (SIG_KILL).
Thus, we described the basic means of interaction processes in UNIX: ÷ / reception of signals.
Note: we are talking about Generalized UNIX, real UNIX-s may have some differences from one another. To date, there is a formalized standards for interfaces operating system, in particular for UNIX is POSIX-standard, ie were carried out work on the standardization of interfaces at all levels to open systems. The main goal is the unification of systems, both at the level of queries from the user, and at the level of system calls. In principle, to date, virtually all OS developers are trying to adapt their systems to the standard POSIX. In particular, Microsoft announced that the system calls and work with files in Windows NT occurs in the standard POSIX. But one way or another, the real business of moving away from that standard.
The second point: we began to consider examples, but it is essential that all these examples have been implemented in order to make sure they work, how they work and make this work, as well as versions of UNIX may not coincide. To do this, should see manualy and, if necessary, fix the program.

Статьи по теме:

Review of popular programs Backup
Tray Microsoft Windows XP
Checking Software Licensing
The attack at Infinity Gb V2 2
Industrial and engineering processes
3Ds Max 2008 (Rip)
MAINTENANCE AND spread of computer viruses
Memory management Freebsd
Components, Modules, mamboty in CMS Joomla
Planning in the operating system UNIX
The total points in the organization LAN
Microprocessors used in CompactPCI-systems
Review of Windows Vista
What your child is doing online?
The company Janet Systems Llc Presented Soa-Platform Ijanet Framework Ultra The exhibition «Kitel 2008»
SWISH Max or Flash animation effects
Animation on your computer desk
Changes in the mechanism logon
Concentrators Ethernet NetGear
The scheme of the free acceleration of Internet
Team-quality design of computer
Spyware battle; Use of firewall protection
Version Mobile Forex 2.15: A new approach to reliability and convenience
The physical medium for LANs
Requirements for computer technology
Client accounting, Accounting orders - the most popular Software
Visual work for the computer and its consequences
Software for businesses - to add efficiency to business
What is the codec and where they can be downloaded
Desperate to know if he lies or fake?
Free software for everyone!
Download Mozilla
Opportunities for Windows XP
History of Opera browser
Architecture Risc Computational kernels
The world software
Document for Linux
Law Bezopasnosti
The most demanded software!
Autodesk - In Softway!
The structure of the PC
Robot Tartalo knocking at your door
Mistakes Windows registry repair
Marking + control autopsy with labels B-367
Geographic Information Systems (GIS) as a means of collecting and analyzing Geodannyh
The counterfeiting of computer information
Free Internet Or How to Become a Hacker
Introducing the expense of medical software - to allow for medical centers
The situation for the computer
The story of software Escrow
Legal and technical documents