Скачиваний:
29
Добавлен:
01.05.2014
Размер:
4.32 Кб
Скачать
/*kill page 275*/ 
	#include <iostream.h>
	#include <stdio.h>
	#include <unistd.h>
	#include <string.h>
	#include <signal.h> 
	int main( int argc, char** argv)  
	{ 		
	int pid, sig = SIGTERM;
	if (argc==3) 
			{
				if (sscanf(argv[1],"%d",&sig)!=1) 
				{					/* get signal number */
					cerr << "Invalid signal: " << argv[1] << endl;
					return -1;
				}
				argv++, argc--;
			}
			while (--argc > 0)
				if (sscanf(*++argv,"%d",&pid)==1) 
				{					/* get process ID */
					if (kill (pid, sig)==-1) 
						perror("kill");
				} 		
				else cerr << "Invalid pid: " << argv[0] << endl;
			return 0;
	}
/*page 263*/
/*sigaction page 268*/
	#include <iostream.h>
	#include <stdio.h>
	#include <unistd.h>
	#include <signal.h>

	void callme() 
	{ 
			cout << "catch signal" << endl; 
	}

	int main() 


			sigset_t  sigmask;
			struct sigaction  action, old_action;
			sigemptyset(&sigmask);
			if (sigaddset( &sigmask, SIGTERM)==-1 || 
					sigprocmask(SIG_SETMASK, &sigmask, 0)==-1)
				perror("set signal mask");
			sigemptyset(&action.sa_mask);
			sigaddset(&action.sa_mask,SIGSEGV);
			action.sa_handler = callme;
			action.sa_flags = 0;
			if (sigaction(SIGILL,&action,&old_action)==-1) 
				perror( "sigaction");
			pause();	/* wait for signal interruption */
			return 0;
	}

/*timer page 278
		#include <stdio.h>
		#include <unistd.h>
		#include <signal.h>
		#define   INTERVAL   5

		void callme( int sig_no ) 
		{ 
					alarm( INTERVAL );
					/* do scheduled tasks */
		}

		int main()
		{
				struct sigaction  action;
				sigemptyset(&action.sa_mask);
				action.sa_handler = (void (*)())callme;
				action.sa_flags = SA_RESTART;
				if ( sigaction( SIGALRM,&action,0 )==-1 ) 				{
					perror( "sigaction");
					return 1;
				}
				if (alarm( INTERVAL ) == -1)
					perror("alarm" );
				else while( 1 ) 			{
					/* do normal operation */
				}
				return 0;

			}

ВКЛЮЧАЕМЫЕ ФАЙЛЫ 
	
signal.h


#ifndef __INCsignalh
#define __INCsignalh
#ifndef	_ASMLANGUAGE
#include "sigevent.h"

struct timespec;
#endif	/* _ASMLANGUAGE */

#define SIGEV_NONE	0
#define SIGEV_SIGNAL	1

/*
 * Signal Numbers:
 * 	Required .1 signals	 1-13
 * 	Job Control signals	14-19 (Не выполненный но должен быть определен not implemented but must be defined)
 * 	Realtime signals	20-27
 */
#define	SIGHUP	1	/* Зависание hangup */
#define	SIGINT	2	/* Прерывание interrupt */
#define	SIGQUIT	3	/* Выход quit */
#define	SIGILL	4	/* Запрещенная команда (не сброс когда захвачено) illegal instruction (not reset when caught) */
#define	SIGTRAP	5	/* Ловушка следа (не сброс когда захвачено) trace trap (not reset when caught) */
#define	SIGABRT 6	/* Использованный аварийным прекращением работы, замените SIGIOT в будущем used by abort, replace SIGIOT in the future */
#define	SIGEMT	7	/* EMT instruction */
#define	SIGFPE	8	/* floating point exception */
#define	SIGKILL	9	/* Kill (не может быть захвачен или игнорироваться) kill (cannot be caught or ignored) */
#define	SIGBUS	10	/* Ошибка шины bus error */
#define	SIGSEGV	11	/* Нарушение сегментации segmentation violation */
#define SIGFMT	12	/* ОШИБКА ФОРМАТА СТЕКА (не posix) STACK FORMAT ERROR (not posix) */
#define	SIGPIPE	13	/* Запишите на конвейере без одного, чтобы читать это write on a pipe with no one to read it */
#define	SIGALRM	14	/* alarm clock */
#define	SIGTERM	15	/* Окончание программного обеспечения сообщает от kill software termination signal from kill */

#define	SIGSTOP	17	/* Sendable останавливаются сигнал не из телетайпа sendable stop signal not from tty */
#define	SIGTSTP	18	/* Остановитесь сигнал из телетайпа stop signal from tty */
#define	SIGCONT	19	/* Продолжите остановленный процесс continue a stopped process */
#define	SIGCHLD	20	/* Родителю на дочернем останове или выходе to parent on child stop or exit */
#define	SIGTTIN	21	/* На читателей pgrp после фонового чтения телетайпа to readers pgrp upon background tty read */
#define	SIGTTOU	22	/* like TTIN for output if (tp->t_local&LTOSTOP) */

#define	SIGUSR1 30	/* user defined signal 1 */
#define	SIGUSR2 31	/* user defined signal 2 */

#define SIGRTMIN	23	/* Realtime signal min */
#define SIGRTMAX	29	/* Realtime signal max */
#define _NSIGS		31
Соседние файлы в папке lab1
  • #
    01.05.20148.18 Кб23lab_sr
  • #
    01.05.20148.5 Кб23lab_sr2
  • #
    01.05.20148 Кб23lab_sr3
  • #
    01.05.2014259 б23out
  • #
    01.05.20142 б24out~
  • #
    01.05.20144.32 Кб29srv.txt