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

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

16 hours ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

16 hours ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

2 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

2 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 months 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