Intermec ck1 Guia De Referência

Página de 390
Chapter 2 — Configuring the CK1 System 
CK1 SDK Programmer’s Reference Manual 
59 
 * Behavior of this sample code 
 * ---------------------------- 
 * When APM tried to enter Slow/Suspend mode, it will send a signal (SIGUSR1) 
 * to all user space applications. We demonstrate how the user space  
 * application registers the handler of this signal and how user space  
 * application deals with this signal here. 
 *  
 * After receive the SIGUSR1 signal, this application will copy /bin/busybox  
 * to /home/bb for a backup and APM will wait for this application to finish  
 * its copy and then enter Slow/Suspend mode. 
 * 
 * ----------------------- 
 * How to Use this Program 
 * ----------------------- 
 * (1) Put this program to device with SDK. 
 * (2) Do not execute this program by SDK. In SDK's Terminal, use this  
 *     command "/home/sigtest &" to make this program run forever in  
 *     the background. 
 * (3) Type "echo slow > /proc/apm" in Terminal to force the device to  
 *     enter Slow mode and you'll see how the program deal with APM's  
 *     signal. 
 * (4) Press any key on the keypad to let the device enter Normal mode. 
 * 
 * ----------------------------- 
 * How to Terminate this Program 
 * ----------------------------- 
 * (1) In SDK's Terminal, use this command "ps" to get the PID (process ID)  
 *     of this program, for example, if the PID of this program is 90. 
 * (2) In SDK's Terminal, use this command "kill 90" to 
terminate
 the program. 
***************************************************************************/ 
 
#include <stdio.h> 
#include <signal.h> 
 
/* for signal handling */ 
#include <eslib_apm.h>   
/* for use the APM Driver API */ 
 
static void usr1_sighlr( int signo ) 

 
printf("sigtest: received SIGUSR1 signal !!\n"); 
 remove("/home/bb"); 
 devApmFileCopy("/bin/busybox", 
"/home/bb"); 

 
int main( void ) 

 
if( signal( SIGUSR1, usr1_sighlr) == SIG_ERR ) { 
 
 
printf("Unable to register the signal handler\n"); 
  return 
-1; 
 } 
 
 while(1){ 
  sleep(10); 
 } 
 
 return 
0;