JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

signals in c++ language in hindi , SIGABRT , SIGFPE , SIGILL , SIGINT , SIGSEGV , SIGTERM

SIGABRT , SIGFPE , SIGILL , SIGINT , SIGSEGV , SIGTERM , signals in c++ language in hindi :-
इससे पहले के article मे , namespace ,exception handeling , template और class को discuss किया अब इस article मे , Signals को discuss करेगे |
Signals एक code है जो की किसी सॉफ्टवेर के execution को interrupts करता है | सॉफ्टवेर एक code होता है जो की प्रोसेस को किसी operating system तक पहुचता है | Signals को ओसके से डायरेक्ट ही generate किया जाता है | OS की तरह से Signals को तब ही generate किया जा सकता हगी जब OS मे कोई error condition आ जाती है | प्रोग्रामर की Ctrl+C का use करते है किसी सॉफ्टवेर को execution को interrupt करने के लिए के लिए | अतः इस article मे , हम c++ language के कुछ defualt Signals को discuss करेगे | और इनके उदाहरन को भी discuss करेगे |
c++ language मे कुछ Signals होते है जिसे प्रोग्राम मे कभी भी catch नहीं किया जा सकता है | इस article मे निन्म Signals को discuss किया गया है | इसके लिए csignal को header portion मे हमेशा  include किया गया है
1. SIGABRT :
इस Signal का use किसी प्रोग्राम को Abnormal terminate करने के लिए use किया जाता है | इसके लिए call और abort function को use किया जाता है |abort () function SIGABRT signal को generate करता है जिससे सॉफ्टवेर या प्रोग्राम का execution interrupt हो जाता है | इसके लिए निन्म उदाहरन है :-
/* abort example */
#include <stdio.h>      /* fopen, fputs, fclose, stderr */
#include <stdlib.h>     /* abort, NULL */
int main ()
{
FILE * pFile;
pFile= fopen (“myfile.txt”,”r”);
if (pFile == NULL)
{
fputs (“error opening file\n”,stderr);
abort();
}
/* regular process here */
fclose (pFile);
return 0;
}
इस प्रोग्राम मे , जब abort() call किया जाता है तब प्रोग्राम मे SIGABRT generate होता है |
2. SIGFPE :
इस signal का use तब किया जाता है जब erroneous arithmetic operation perform किया जाता है | जैसे किसी non zero value को zero से divide करने पर ये signal generate होता है जो की प्रोग्राम को terminate कर देता है |
Example :
#include <stdio.h>
#include <signal.h>
int main() {
error(getpid(), SIGFPE);
cout<<“erroneous arithmetic operation occur”;
getch();
}
3. SIGILL :
इस signal का use किसी illegal instruction को detect करने के लिए किया जाता है | जब किसी प्रोग्राम मे ,  illegal instruction को occur होता है तब SIGILL generate होता है | जो की  प्रोग्राम को terminate कर देता है |
#include <stdio.h>
#include <signal.h>
int main() {
int a , b ;
a=10;
b=20;
a-b;
getch();
}
इस code मे जब a-b; perform होता है तब इस प्रकार का signal generate होता है |
SIGINT :
इस signal का use किसी interactive program interrupt signal को generate करने के लिए किया जाता है | इसके लिए निन्म code को उए किया जाता ही |
उदाहरन :
#include <stdio.h>
#include <signal.h>
int main() {
int a , b ;
a=10;
b=20;
call SIGINT ;
getch();
}
SIGSEGV :
इस signal का use , किसी storage के invalid access को डिटेक्ट करने के लिए किया जाता है |
#include <signal.h>
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
char *buf;
int flag=0;
static void handler(int sig, siginfo_t *si, void *unused)
{
printf(“Got SIGSEGV at address: 0x%lx\n”,(long) si->si_addr);
printf(“Implements the handler only\n”);
flag=1;
//exit(EXIT_FAILURE);
}
int main(int argc, char *argv[])
{
char *p; char a;
int size;
struct sigaction sa;
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = handler;
if (sigaction(SIGSEGV, &sa, NULL) == -1)
handle_error(“sigaction”);
size=4096;
/* Allocate a buf aligned on a page boundary;
initial protection is PROT_READ | PROT_WRITE */
buf = memalign(size, 4 * size);
if (buf == NULL)
handle_error(“memalign”);
printf(“Start of region:        0x%lx\n”, (long) buf);
printf(“Start of region:        0x%lx\n”, (long) buf+size);
printf(“Start of region:        0x%lx\n”, (long) buf+2*size);
printf(“Start of region:        0x%lx\n”, (long) buf+3*size);
//if (mprotect(buf + size * 0, size,PROT_NONE) == -1)
if (mprotect(buf + size * 0, size,PROT_NONE) == -1)
handle_error(“mprotect”);
//for (p = buf ; ; )
if(flag==0)
{
p = buf+size/2;
printf(“It comes here before reading memory\n”);
a = *p; //trying to read the memory
printf(“It comes here after reading memory\n”);
}
else
{
if (mprotect(buf + size * 0, size,PROT_READ) == -1)
handle_error(“mprotect”);
a = *p;
printf(“Now i can read the memory\n”);
}
for (p = buf;p<=buf+4*size ;p++ )
{
//a = *(p);
*(p) = ‘a’;
printf(“Writing at address %p\n”,p);
}
printf(“Loop completed\n”);     /* Should never happen */
exit(EXIT_SUCCESS);
}
इस code को c language मे लिखा गया क्योकि c++ language मे signal को generate करने के लिए code की length काफी बाद जाती है |
SIGTERM :
इस signal का use किसी प्रोग्राम को terminate करने के लिए request को generate करता है | इसके लिए किसी signal को short टर्म के लिए generate कोइय जाता है जिसका use किसी प्रोग्राम को short period के लिए  terminate करने के लिए किया जाता है |SIGHUP: Hang-up (POSIX),
इस signal का use , किसी user’s terminal  को disconnect करने के लिए किया जाता है |इस signal का use किसी controlling process के terminate करने के लिए किया जाता है |
Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now