Linux under C programming: Raise

Source: Internet
Author: User
Tags printf linux

The key to sending a signal is to let the system know which process to send the signal and what signal to send. It should be noted that the ability to send a particular signal to a process is closely related to the user's permissions. For example, only a system administrator can send a sigkill signal to terminate a process.

A system call used to send a signal.

#include <sys/types.h>     
         
#include <signal.h>     
         
#include <unistd.h>     
         
#include <sys/ time.h>     
         
int Kill (pid_t pid,int signumber);     
         
int raise (int signumber);     
         
unsigned int alarm (unsigned intseconds);     
         
int setitimer (int which,const structitimerval *value,struct itimerval *oldvalue);

Raise: Used to send a signal to the process itself. Successfully returns 0, failure returns-1.

#include <stdio.h>     
#include <signal.h>     
void func ();     
void Main ()     
{     
     charbuffer[100];     
     if (sig_err== signal (SIGINT,&FUNC))     
     {     
         printf ("signalerror!! \ n ");     
         Exit ( -1);     
     }     
     for (;;)     
     {     
         fgets (buffer,sizeof (buffer), stdin);     
         if (strcmp (buffer, "sigint\n") = = 0)     
              raise (SIGINT);     
         else 
              printf ("nocampare\n");     
     }     
         
void func ()     
{     
     printf ("hellofunc\n");     
}

View a full set of articles: Http://www.bianceng.cn/Programming/C/201212/34807.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.