LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-11-2013, 11:37 AM   #1
pro_learner
LQ Newbie
 
Registered: Mar 2013
Posts: 10

Rep: Reputation: Disabled
sigcont handler is not getting called


m lunching acroread in child process...in command line when m doing sigcont the handler is nt getting called why?

Code:
#include<sys/types.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#include <signal.h> 

sigset_t set1,set2;

struct sigaction act1,act2;

void sig_hdl4(int signo)  
                         // for SIGCONT
{
  printf("a dummy signal handler1\n");//not printing after the application wake up!!!
  kill(getpid(),SIGCONT);
	exit(0); 

}  

int main()
{

   int ret,status=0,flag=0,flag1=0;

   int i=0,s=0;
		

 while(i++<1)
  { 
   
        ret = fork();
   		
   	if(ret<0)
	{

          
           perror("error in fork\n"); 
          
          
           exit(1); 
	}

	if(ret>0)
	{
		 printf("xx parent is %d, child is %d \n",getppid(),getpid());
			printf("i=%d\n",i);
			continue;
	}

  	 
        if(ret==0)
 	{ 

           printf("child is %d, parent is %d \n",getpid(),getppid());
			if(i==1)
			{
				
				printf("1 child\n");
				ret=execl("/usr/bin/acroread","acroread",NULL);
				
				
				if(ret<0)
				{
				perror("error in execl");
				exit(2);
				}
			}
		
		
	}
  }

if(ret>0)
 {
  	 while(1)
	 { 
   		ret = waitpid(-1,&status,0);
    		if(ret>0)
		{

    			if(WIFEXITED(status))    
    			{
      				 if(WEXITSTATUS(status) == 0)
				 { 
					printf("normal success\n");
      				 }
       				else
				{
					flag=1;
					printf("not successful \n");

       				}
    			}
		}
    		else
		{ 
        	if(WIFSIGNALED(status))
        	{
           		 flag1=1;
			 printf("signal that terminated is %d\n",WTERMSIG(status));
        	}

   		}
		

    		if(ret<0)
	 	{
			if(flag==1 || flag1==1)
			{
			exit(0);
			}
   	 		else
			  break;
		} 
	 }
}
return 0;
}

Last edited by pro_learner; 03-13-2013 at 01:12 PM.
 
Old 03-12-2013, 02:40 AM   #2
rigor
Member
 
Registered: Sep 2011
Posts: 249

Rep: Reputation: Disabled
pro_learner,

If at the bottom of the area where you type your text to write a comment on linuxquestions.org, you would press the button marked "Go Advanced" you will see additional controls become available just above the area where you type the text. The control labeled with the # symbol can be used to put "code" tags around your code to maintain the formatting of it, and allow it to scroll, so it takes much less vertical area on the page. Please consider using that next time. If you just press that control in an empty text area you'll see that it puts a beginning and ending code tag, the ending code tag has a / in it. You can paste your code between the code tags. Code tags look like this in the text area:

[CODE]Your program goes here, in between the code tags.[/CODE]

As to the program you have in your question, you have defined a signal handler, and variables for use with the signal handler, but you haven't told Linux what to do with your signal handler.

If you put a phrase like linux signal handling tutorial into an Internet search engine, you will see links to plenty of tutorials that will show you what your program is missing.

In fact, if you have access to a Linux system with the info command, then just typing:

Code:
info signal handling
at a command prompt, should show you documentation on Linux signal handling that you can browse through and see what your program is missing.

I hope that helps you.

Last edited by rigor; 03-12-2013 at 02:57 AM.
 
Old 03-13-2013, 12:59 PM   #3
pro_learner
LQ Newbie
 
Registered: Mar 2013
Posts: 10

Original Poster
Rep: Reputation: Disabled
while accessing the second data of shared memory region...am getting garbage value
Code:
#include<unistd.h>
#include<sys/types.h>
#include<sys/shm.h>
#include<sys/sem.h>
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<string.h>
#include<sys/wait.h>

#define KEY1 1235
struct shm_area {
  //unsigned short rd_index;
  //unsigned short wr_index;
  //unsigned short buf_size_max;
  int buf_area[1024]; 
  //unsigned int used_slot_count;

  //char my_straread[50][256];  
};

int main()
{

  //char value[]="I am in shared memory\n";
  int ret,ret2,status, shm_id1,sem_id2,i=0;
  
struct shm_area *shma ;
printf("the address that faults is %x\n", shma); 

shm_id1 = shmget(KEY1,3*getpagesize(),IPC_CREAT|0600);
printf("page size=%d key=%d\n",getpagesize(),shm_id1);
  if(shm_id1<0 && errno != EEXIST)
 	{ 
          perror("error in creating the shared memory"); 
	  exit(1);
	}
 shma = shmat(shm_id1,0,0);
//printf("the my straread is %d\n", shma->my_straread[50][256]);

 printf("the attached address is 0x%x\n", shma);
 printf("the attached address is 0x%x\n", shma+1);
printf("the attached address is 0x%x\n", shma+2);

  printf("the amount of shm memory used is %d\n", \
	  sizeof(struct shm_area));

 shma->buf_area[0]=19;
(shma+1)->buf_area[0]=20;
(shma+2)->buf_area[0]=21;

printf("in parent %d\n",*shma);
printf("in parent %d\n",*(shma+1));
printf("in parent %d\n",*(shma+2));


ret=fork();
	if(ret<0)
	{
		perror("error in creating child");
		printf("error in creating child");
	exit(1);
	}
	if(ret>0)
	{
		printf("i m in parent context\n");
		printf("parent id is %ld,pid is %ld\n", getppid(),getpid());
	exit(0);
	}
	if(ret==0)
	{
		printf("i m in child context\n");
		printf("parent id is %ld,pid is %ld\n", getppid(),getpid());
		printf("%d\n",*shma);
                printf("%d\n",*(shma+1));
                printf("%d\n",*(shma+2));

		//reading from a reg. file
               /*if(ret2<0) { 
               perror("error in reading from datafile");       
               exit(6); //can be somethingelse
               }
               if(ret2 == 0) break;*/


}
if(ret>0)
 {
   while(1){ 

    ret = waitpid(-1,&status,0);
    if(ret>0){

    if(WIFEXITED(status))     //normal termination of the process
    {
       if(WEXITSTATUS(status) == 0){ //normal and successfull
       }
       else{//normal, but not successfull
          
       }
    }
    else{ //abnormal (did not succeed)
        
    }
   } 
    if(ret<0) { 

           //printf("final value of shared counter is %d\n", shma->count); 
           exit(0); 

    } 
   } //second while 
  }//if after while loop 


}
o/p-
19
garbage value
21

Last edited by pro_learner; 03-13-2013 at 01:03 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] D&D motion event handler called only once. [gtkmm 3 && goocanvasmm (irrelevant)] Amonith Programming 1 01-06-2012 09:54 AM
How to replace the default handler with user defined handler in Linux kernel ? vl chowdary Linux - Kernel 4 04-27-2011 02:09 PM
SIGSEGV handler (segmentation fauld handler) myp Programming 8 03-08-2011 02:17 PM
using SIGSTOP and SIGCONT Wazzz Programming 0 12-12-2006 01:50 AM
howto know whether a function is called in signal handler snowing Programming 1 11-07-2005 09:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration