.


:




:

































 

 

 

 





signal()

 

#include <signal.h>.

static void sig_hndl(int signo) //

{

signal (SIGINT, sig_hndl); // ,

printf(This is new handler for SIGINT\n); //

}

main()

{

signal(SIGINT, sig_hndl); //

signal(SIGUSR1, SIG_DFL);

signal(SIGUSR2, SIG_IGN);

while(1)

pause();

}

 

$ a.out & -

5050 - pid

$ kill SIGINT 5050

This is new handler for SIGINT

$ kill SIGUSR2 5050 -

$ kill SIGUSR1 5050 - ( ).

 

POSIX

sigaction(2)

sigset_t (32 32 ). .

sigaction ( , ).

#include <signal.h>

int sigaction (int sig, const struct sigaction *act, const struct sigaction *oldact)

sigaction:

- void (*sa_handler) ()

- void (*sa_sigaction) (int, siginfo_t*, void*)

- sigset_t sa_mask; //

- int sa_flags; //

 

sa_handler <> 0 sa_sigaction <> 0, sa_mask , . , . . . . sa_flags .

siginfo_t - .

 

#include <siginfo_t.h>

struct siginfo_t{

int sig_no; //

int sig_errno; //

int sig_code; //

};

 

sigaction()

#include <signal.h>

sigemptyset(sig_set_t *set); // ,

sigfillset(sig_set_t *set); //

sigaddset(sig_set_t *set, int signo); // 1

sigdelset(sig_set_t *set, int signo); // 1

sigismemberset(sig_set_t *set, int signo); //

 

- .

.

- , , . : .

.

 

#include <signal.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <unistd.h>

 

void (*oursignal (int signo, void (*hndlr)(int)) (int) //

{

struct sigaction act, oldact;

act.sa_handler = hndlr;

sigemptyset(&act.sa_mask);

act.sa_flags = 0;

if (signo!= SIGALARM) act.sa_flags |= SA_RESTART;

if (sigaction (signo, &act, &oldact) < 0) return (SIG_ERR);

return (oldact.sa_hndlr);

}

 

static void sig_hndlr (int signo);

{

printf(We are int handler\n); //

}

 

main()

{

oursignal(SIGINT, sig_hndl); //

oursignal(SIGUSR1, SIG_DFL);

oursignal(SIGUSR2, SIG_IGN);

while(1)

pause();

}

 

.

IPC. . .

POSIX <= .

.

send msg .

[send receive reply]

.

( ).

:

- send-

- receive-

- .

 

WinNT

. C. ( .. , ). -> . . .

- ( + )

- ( )

- (, )

- .

 

, .

. ( + ).

.

-> IPC. .

 

API .

-

-

( -).

 

- . . .

 

.

, . , .

. . . ( ), , .

, , . .

ID
,
, -
V / , , .
/ , /
. ,

 

. . NT.

 

: , , , .

- .

ID
,
,
( APC)
(SUID)

 

16-31 ( ) .

 





:


: 2016-11-02; !; : 438 |


:

:

,
==> ...

1729 - | 1671 -


© 2015-2024 lektsii.org - -

: 0.018 .