Соглашение | Публикация статей
Красивые рольшторы - roll-service.by / Ремонт в Минске tvoi-master.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.

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

Routers NetGear
Autodesk - In Softway!
Checking Software Licensing
Review converters for video
Law Bezopasnosti
Geographic Information Systems (GIS) as a means of collecting and analyzing Geodannyh
Increases user rights
Architecture Risc Computational kernels
Review of popular programs Backup
The program 1S Accounting Enterprise 8
1C Program Office Trade 8
Corporate Information System (Crm, Erp, mobile commerce)
Optimal cache lifetime for Joomla CMS
"Trojan horse"
The funds protect your computer and maximum security
Systemic and local bus
Spam and how to cope with it
Mobile Commerce, Mobile Commerce System
Print Manager
Crm, software
Aptitude CompactPCI-products of rapid obsolescence
Fresh version of Mobile Forex 2.16: Quick Mobile Trading
Split Access database
Development and dissemination of computer viruses
Potential voltage stabilizers for the protection of the personal computer
Software can be downloaded from Vareznyh Sites or whether Buy for sale online
The history of personal computers
Microprocessors used in CompactPCI-systems
Robot Tartalo knocking at your door
Lock down the personal information on your computer
Windows 7 - Window to the Future
Time to create protection
The processes in the operating system UNIX
The program to automate Beauty Shop - Business tool or waste of money?
Legal and technical documents
Technology Platform 1C: Enterprise 8 - Areas Development
On Legalization. Price Errors!
How Stress Editor In Word 2007
Concentrators Ethernet NetGear
3Ds Max 2008 (Rip)
Icons in the design. Stages and stage of development of computer
Implementation Crm Systems Quick Sales 2 The Company «Epos»
ABOUT personal characteristics COMPUTER CRIMINALS
The attack at Infinity Gb V2 2
ATM technology
Advantages of Mobile Commerce
MAINTENANCE AND spread of computer viruses
Varieties of computer crime
Software for businesses - to add efficiency to business
PC Peripherals
Installing Windows Xp on a network without the use of Ris
Loss of information - whether it can be avoided?