examples/PIPS/posixsignals/asyncSignal/src/sigusr2.c

00001 // sigusr2.c
00002 //
00003 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 // All rights reserved.
00005 // This component and the accompanying materials are made available
00006 // under the terms of "Eclipse Public License v1.0"
00007 // which accompanies this distribution, and is available
00008 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00009 //
00010 // Initial Contributors:
00011 // Nokia Corporation - initial contribution.
00012 //
00013 // Contributors:
00014 //
00015 // Description: The source file for sigusr2 process.
00016 //
00017 
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 #include <signal.h>
00021 #include <unistd.h>
00022 #include <e32def.h>
00023 
00027 int gVal = TRUE;
00028 
00033 void SIGUSR2_handler(int signum)
00034     {
00035     if(signum == SIGUSR2)
00036         {
00037         printf("Received the SIGUSR2 signal from the sigusr1 process after reading the file.\n");
00038         gVal = FALSE;
00039         }
00040     }
00041 
00049 int main(int argc,char **argv)
00050     {
00051     pid_t asyProcsID;
00052     char ch;
00053     int ret;
00054     if(argc < 2)
00055         {
00056         printf("Please pass the correct arguments\n");
00057         return EXIT_FAILURE;
00058         }
00059     asyProcsID = atoi(argv[1]);  //The variable holding the sigusr1 process PID.
00060     // Setup the custom handler for SIGUSR2.
00061     signal(SIGUSR2, SIGUSR2_handler);
00062     printf("******************** In the sigusr2 process ********************\n");
00063     
00064     printf("\nPress the Enter key to send the SIGUSR1 signal to the sigusr1 process\n");
00065     getchar();
00066     ret = kill(asyProcsID,SIGUSR1);
00067     if(ret)
00068         {
00069         printf("kill() failed to send signal, errno=%d\n",errno);
00070         gVal = FALSE;
00071         }
00072     
00073     /* 
00074      Waiting until a SIGUSR2 signal is obtained from the sigusr1 process.
00075      This signal is sent after the aynscFile.txt file has been
00076      read and its content written to the console.
00077     */
00078     while(gVal)
00079         {
00080         sleep(0);   //Initiates signal handling.
00081         }
00082     printf("\nPress 'e'+Enter to exit from the sigusr2 process\n");
00083     while((ch = getchar())!= 'e')
00084         {
00085         if(ch == '\n')
00086             continue;
00087         else
00088             printf("The wrong option was selected, please try again!!!\n");
00089         }
00090     return EXIT_SUCCESS;
00091     }

Generated by  doxygen 1.6.2