• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ psignal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中psignal函数的典型用法代码示例。如果您正苦于以下问题:C++ psignal函数的具体用法?C++ psignal怎么用?C++ psignal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了psignal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: waitfg

/* 
 * waitfg - block until FG job pid terminates or stops.
 */
void waitfg(pid_t pid)
{
    int status;
    
    /* wait for FG job to stop (WUNTRACED) or terminate */
    if (waitpid(pid, &status, WUNTRACED) < 0)
	unix_error("waitfg: waitpid error");
    
    /* FG job has stopped. Change its state in jobs list */
    if (WIFSTOPPED(status)) {
	sprintf(sbuf, "Job %d stopped by signal", pid);
	psignal(WSTOPSIG(status), sbuf); 
	updatejob(jobs, pid, ST);
    }
    
    /* FG job has terminated. Remove it from job list */
    else {
	/* check if job was terminated by an uncaught signal */
	if (WIFSIGNALED(status)) { 
	    sprintf(sbuf, "Job %d terminated by signal", pid);
	    psignal(WTERMSIG(status), sbuf); 
	}
	deletejob(jobs, pid);
	if (verbose)
	    printf("waitfg: job %d deleted\n", pid);
    }
}
开发者ID:447327642,项目名称:CSAPP2e,代码行数:30,代码来源:shell.c


示例2: main

int main(int argc, char **argv)
{
    sigset_t block, pending;
    int sig, flag;

    /* 设置信号的handler */
    signal(MYSIGNAL, sig_handler);

    /* 屏蔽此信号 */
    sigemptyset(&block);
    sigaddset(&block, MYSIGNAL);
    printf("block signal\n");
    sigprocmask(SIG_BLOCK, &block, NULL);

    /* 发两次信号, 看信号将会被触发多少次 */
    printf("---> send a signal --->\n");
    kill(getpid(), MYSIGNAL);
    printf("---> send a signal --->\n");
    kill(getpid(), MYSIGNAL);

    /* 检查当前的未决信号 */
    flag = 0;
    sigpending(&pending);
    for (sig = 1; sig < NSIG; sig++) {
        if (sigismember(&pending, sig)) {
            flag = 1;
            psignal(sig, "this signal is pending");
        } 
    }
    if (flag == 0) {
        printf("no pending signal\n");
    }

    /* 解除此信号的屏蔽, 未决信号将被递送 */
    printf("unblock signal\n");
    sigprocmask(SIG_UNBLOCK, &block, NULL);

    /* 再次检查未决信号 */
    flag = 0;
    sigpending(&pending);
    for (sig = 1; sig < NSIG; sig++) {
        if (sigismember(&pending, sig)) {
            flag = 1;
            psignal(sig, "a pending signal");
        } 
    }
    if (flag == 0) {
        printf("no pending signal\n");
    }

    return 0;
}
开发者ID:pugwoo,项目名称:c,代码行数:52,代码来源:sig_test_3.c


示例3: sigchld_handler

void sigchld_handler(int sig) {
	pid_t pid;
	int status;
	struct job *p;
	if ((pid = waitpid(-1, &status, WUNTRACED)) > 0) {
		if (WIFEXITED(status)) {
			deletejob(pid);
			if (pid == forepid) {
				forepid = 0;
				setpgid(pid, pid);
				fprintf(stderr, "foreground job %d terminated normally with exit status=%d\n",
						pid, WEXITSTATUS(status));
				siglongjmp(env, 1);
			}
			else
				fprintf(stderr, "job %d terminated normally with exit status=%d\n",
						pid, WEXITSTATUS(status));
		}
		else if (WIFSTOPPED(status)) {
			p = selectjob(pid);
			p->state = 0;
			if (pid == forepid) {
				forepid = 0;
				setpgid(pid, pid);
				fprintf(stderr, "foreground job [%d] %d stopped by signal: Stopped\n",
						p->jid, pid);
				siglongjmp(env, 1);
			}
			else
				fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n",
						p->jid, pid);
		}
		else if (WIFSIGNALED(status)) {
			deletejob(pid);
			if (pid == forepid) {
				forepid = 0;
				setpgid(pid, pid);
				fprintf(stderr, "foreground job %d terminated by ", pid);
				psignal(WTERMSIG(status), "signal");
				siglongjmp(env, 1);
			}
			else
			fprintf(stderr, "job %d terminated by ", pid);
			psignal(WTERMSIG(status), "signal");
		}
	}
	else if (errno != ECHILD)
		fprintf(stderr, "waitpid error: %s\n", strerror(errno));
	printf("handler reaped pid=%d, ready to return right now.\n", pid);
	return;
}
开发者ID:Logic2soul,项目名称:csapp2E,代码行数:51,代码来源:myshell_bug2.c


示例4: fg_waitpid

void fg_waitpid(pid_t pid) {
	int status;
	pid_t r_pid;
	struct job *p;

	if ((r_pid = waitpid(pid, &status, 0)) > 0) {
		printf("fg_waitpid in, forepid=%d, r_pid=%d\n", forepid, r_pid);
		forepid = 0;
		if (WIFEXITED(status)) {
			deletejob(r_pid);
			fprintf(stderr, "job %d terminated normally with exit status=%d\n",
					r_pid, WEXITSTATUS(status));
		}
		else	if (WIFSTOPPED(status)) {
			p = selectjob(r_pid);
			p->state = 0;
			fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n", 
					p->jid, r_pid);
		}
		else	if (WIFSIGNALED(status)) {
			deletejob(r_pid);
			fprintf(stderr, "job %d terminated by ", r_pid);
			psignal(WTERMSIG(status), "signal");
		}
	}
	else	if (errno != ECHILD)
		fprintf(stderr, "waitpid error: %s\n", 
				strerror(errno));
	printf("foreground reaped pid=%d, ready to return\n", r_pid);
	return;
}
开发者ID:Logic2soul,项目名称:csapp2E,代码行数:31,代码来源:myshell_bug2.c


示例5: MySAR_signal_handler

void MySAR_signal_handler(int signal)
{
	psignal(signal, "FATAL: MySAR Received Signal: ");

	if (signal==SIGINT || signal==SIGTERM)
	{
		// rollback last operation
		MySAR_db_rollback();
		MySAR_free_mysql_statements();

		if (!config->logfile.compressed)
		{
			// write last file position, prevent duplicationg records
			MySAR_update_config(record.stamp, "lastTimestamp");
			MySAR_update_config_long(ftell(input), "lastLogOffset");
		}

		// close db
		MySAR_db_shutdown();

		// dont forget to remove the lock...
		MySAR_unlock_host();

		exit(EXIT_FAILURE);
	}
}
开发者ID:coffnix,项目名称:mysar-ng,代码行数:26,代码来源:mysar.c


示例6: scheduler_signal_handler

static int scheduler_signal_handler(int sig){
    /*quit listening upon signal and do clean up.*/
    psignal(sig, "scheduler");
    if(sig!=15) print_backtrace();
    quit_listen=1;
    return 1;
}
开发者ID:bitursa,项目名称:maos,代码行数:7,代码来源:sock.c


示例7: proc_apply_resource_actions

int
proc_apply_resource_actions(void * bsdinfo, __unused int type, int action)
{
	proc_t p = (proc_t)bsdinfo;

	switch(action) {
		case PROC_POLICY_RSRCACT_THROTTLE:
			/* no need to do anything */
			break;

		case PROC_POLICY_RSRCACT_SUSPEND:
			task_suspend(p->task);
			break;

		case PROC_POLICY_RSRCACT_TERMINATE:
			psignal(p, SIGKILL);
			break;

		case PROC_POLICY_RSRCACT_NOTIFY_KQ:
			/* not implemented */
			break;
		
		case PROC_POLICY_RSRCACT_NOTIFY_EXC:
			panic("shouldn't be applying exception notification to process!");
			break;
	}

	return(0);
}
开发者ID:argp,项目名称:xnu,代码行数:29,代码来源:process_policy.c


示例8: power_intr

int
power_intr(void *arg)
{
	extern int kbd_reset;
	int status;

	status = (int8_t)_reg_read_1(LANDISK_BTNSTAT);
	if (status == -1) {
		return (0);
	}

	status = ~status;
	if (status & BTN_POWER_BIT) {
#ifdef DEBUG
		printf("%s switched\n", sc->sc_dev.dv_xname);
		Debugger();
#endif
		_reg_write_1(LANDISK_PWRSW_INTCLR, 1);
		if (kbd_reset == 1) {
			kbd_reset = 0;
			psignal(initproc, SIGUSR1);
		}
		return (1);
	}
	return (0);
}
开发者ID:alenichev,项目名称:openbsd-kernel,代码行数:26,代码来源:power.c


示例9: pledge_fail

int
pledge_fail(struct proc *p, int error, uint64_t code)
{
	char *codes = "";
	int i;
	struct sigaction sa;

	/* Print first matching pledge */
	for (i = 0; code && pledgenames[i].bits != 0; i++)
		if (pledgenames[i].bits & code) {
			codes = pledgenames[i].name;
			break;
		}
	printf("%s(%d): syscall %d \"%s\"\n", p->p_comm, p->p_pid,
	    p->p_pledge_syscall, codes);
#ifdef KTRACE
	if (KTRPOINT(p, KTR_PLEDGE))
		ktrpledge(p, error, code, p->p_pledge_syscall);
#endif
	/* Send uncatchable SIGABRT for coredump */
	memset(&sa, 0, sizeof sa);
	sa.sa_handler = SIG_DFL;
	setsigvec(p, SIGABRT, &sa);
	psignal(p, SIGABRT);

	p->p_p->ps_pledge = 0;		/* Disable all PLEDGE_ flags */
	return (error);
}
开发者ID:mosconi,项目名称:openbsd,代码行数:28,代码来源:kern_pledge.c


示例10: sigchld_handler

void sigchld_handler(int sig) {
	pid_t pid;
	int status;
	struct job *p;
	if ((pid = waitpid(-1, &status, WUNTRACED)) > 0) {
		if (pid == forepid) 
			forepid = 0;
		if (WIFEXITED(status))
			deletejob(pid);
		else if (WIFSTOPPED(status)) {
			p = selectjob(pid);
			p->state = 0;
			fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n",
					p->jid, pid);
		}
		else if (WIFSIGNALED(status)) {
			deletejob(pid);
			fprintf(stderr, "job %d terminated by ", pid);
			psignal(WTERMSIG(status), "signal");
		}
	}
	else if (errno != ECHILD)
		fprintf(stderr, "\nwaitpid error: %s\n", strerror(errno));
	return;
}
开发者ID:Logic2soul,项目名称:csapp2E,代码行数:25,代码来源:myshell_release.c


示例11: pipeSigHandler

    void pipeSigHandler( int signal ) {
#ifdef psignal
        psignal( signal, "Signal Received : ");
#else
        cout << "got pipe signal:" << signal << endl;
#endif
    }
开发者ID:gilles,项目名称:mongo,代码行数:7,代码来源:db.cpp


示例12: signal_handler

static void signal_handler(int sig)
{
#if defined(SIGPIPE)
    if (sig == (int) SIGPIPE) {
      psignal(sig, "Csound ignoring SIGPIPE");
      return;
    }
#endif
    psignal(sig, "\ncsound command");
    if ((sig == (int) SIGINT || sig == (int) SIGTERM)) {
      if(_csound) csoundStop(_csound);
      _result = -1;
      return;
    }
    exit(1);
}
开发者ID:BlakeJarvis,项目名称:csound,代码行数:16,代码来源:csound_main.c


示例13: psignal_cmd

static TACommandVerdict psignal_cmd(TAThread thread,TAInputStream stream)
{
    int    sig           = readInt   ( & stream );
    char * s             = readString( & stream );
    char * fileForStderr = readString( & stream );
    FILE * stderrAsFile;
    FILE * oldStderr;
    // psignal( sig, s );
    stderrAsFile = fopen( fileForStderr, "w" );
    assertion( stderrAsFile != NULL, "psignal_cmd : stderrAsFile is NULL\n" );
    oldStderr = stderr;
    stderr = stderrAsFile;
    // ta_debug_printf( "psignal_cmd : sig           is %d\n"    , sig           );   fflush( stdout );
    // ta_debug_printf( "psignal_cmd : s             is \"%s\"\n", s             );   fflush( stdout );
    // ta_debug_printf( "psignal_cmd : fileForStderr is \"%s\"\n", fileForStderr );   fflush( stdout );
    START_TARGET_OPERATION( thread );
    // ta_debug_printf( "psignal_cmd : before psignal\n" );   fflush( stdout );
    psignal( sig, s );
    // ta_debug_printf( "psignal_cmd : after  psignal\n" );   fflush( stdout );
    END_TARGET_OPERATION( thread );
    stderr = oldStderr;
    // ta_debug_printf( "psignal_cmd : 1\n" );   fflush( stdout );
    fclose( stderrAsFile );
    // ta_debug_printf( "psignal_cmd : 2\n" );   fflush( stdout );
    writeString( thread, "Ok" );
    // ta_debug_printf( "psignal_cmd : 3\n" );   fflush( stdout );
    sendResponse( thread );
    // ta_debug_printf( "psignal_cmd : return\n" );   fflush( stdout );
    return taDefaultVerdict;
}
开发者ID:levenkov,项目名称:olver,代码行数:30,代码来源:sigstr_agent.c


示例14: main

int main(){

  char *cmd = (char *)"/opt/vpnserver execsvc";
  sigset_t mask;
  int sig;

  if(!(fp = (FILE *)popen(cmd, "re"))){

    printf("popen failed\n");
    exit(-1);

  }else{

    signal(SIGINT, quit);
    signal(SIGTERM, quit);

    sigfillset(&mask);
    sigwait(&mask, &sig);

    psignal(sig, "");
    printf("Caught signal, closing\n");

    pclose((FILE *)fp);
 
  }

}
开发者ID:billpku,项目名称:VPN,代码行数:27,代码来源:run.c


示例15: Mono_Posix_Syscall_psignal

int
Mono_Posix_Syscall_psignal (int sig, const char* s)
{
	errno = 0;
	psignal (sig, s);
	return errno == 0 ? 0 : -1;
}
开发者ID:ANahr,项目名称:mono,代码行数:7,代码来源:signal.c


示例16: fg_waitpid

void fg_waitpid(pid_t pid) {
	int status;
	pid_t r_pid = 0;
	struct job *p = NULL;

	if ((r_pid = waitpid(pid, &status, 0)) > 0) {
		forepid = 0;
		if (WIFEXITED(status)) 
			deletejob(r_pid);
		else	if (WIFSTOPPED(status)) {
			p = selectjob(r_pid);
			p->state = 0;
			fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n", 
					p->jid, r_pid);
		}
		else	if (WIFSIGNALED(status)) {
			deletejob(r_pid);
			fprintf(stderr, "job %d terminated by ", r_pid);
			psignal(WTERMSIG(status), "signal");
		}
	}
	else if (errno != ECHILD)
		fprintf(stderr, "waitpid error: %s\n", 
				strerror(errno));
	return;
}
开发者ID:Logic2soul,项目名称:csapp2E,代码行数:26,代码来源:myshell_release.c


示例17: sd_callback2

static int  
sd_callback2(proc_t p, void * args)
{
	struct sd_iterargs * sd = (struct sd_iterargs *)args;
	int signo = sd->signo;
	int setsdstate = sd->setsdstate;
	int countproc = sd->countproc;

	proc_lock(p);
	p->p_shutdownstate = setsdstate;
	if (p->p_stat != SZOMB) {
		proc_unlock(p);
		if (countproc !=  0) {
			proc_list_lock();
			p->p_listflag |= P_LIST_EXITCOUNT;
			proc_shutdown_exitcount++;
			proc_list_unlock();
		}
		psignal(p, signo);
		if (countproc !=  0)
			sd->activecount++;
	} else
		proc_unlock(p);

	return(PROC_RETURNED);

}
开发者ID:Algozjb,项目名称:xnu,代码行数:27,代码来源:kern_shutdown.c


示例18: signal

/*
 * Send the specified signal to
 * all processes with 'tp' as its
 * controlling teletype.
 * Called by tty.c for quits and
 * interrupts.
 */
signal(tp, sig)
{
	register struct proc *p;
 
	for(p = &proc[0]; p < &proc[NPROC]; p++)
		if(p->p_ttyp == tp)
			psignal(p, sig);
}
开发者ID:sunofly,项目名称:unix,代码行数:15,代码来源:sig.c


示例19: spigintr

/*
 * Interrupt procedure.
 * Just call a user level interrupt routine.
 */
void
spigintr(int unit)
{
struct	spigot_softc	*ss = (struct spigot_softc *)&spigot_softc[unit];

	if(ss->p && ss->signal_num)
		psignal(ss->p, ss->signal_num);
}
开发者ID:metacore,项目名称:spin,代码行数:12,代码来源:spigot.c


示例20: main

main ( )
{
	int i ;
	char *s;
	
	for ( i = 1; i < 10; i++ ) 
		psignal ( i, "error" ) ;
}
开发者ID:m-varadhan,项目名称:CUnixProgramming,代码行数:8,代码来源:psignal.c



注:本文中的psignal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pskb_expand_head函数代码示例发布时间:2022-05-30
下一篇:
C++ psi函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap