Dear Linuxquestion,
Problem statement:
i have a program using fork(), Parent/Child to activate a signal by kill() function. In order to execute the process, my child function required to give a sleep() function and quit after my signal() process is done. Here is the code:
Code:
/*main*/
pid_t ret;
int status;
int role = -1;
ret = fork();
if (ret >0) /*parent content*/
{
printf( " Parent Process: Arm Operating (pid %d)\n", getpid() );
signal( SIGUSR1, RWCArmWash );
role = 0;
pause();
ret = wait( &status );
}
else if (ret == 0) {
usleep (100);
role = 1;
kill( getppid(), SIGUSR1 );
sleep (55);
}
Code:
/*signal function*/
void RWCArmWash ( int sig_num )
{
int arm=0;
int status=4;
libInit();
usleep(100);
printf( "Parent (%d) got the SIGUSR1\n", getpid() );
arm = ARMconnectToRobot();
arm = ARMinitializeAndCalibrate ();
arm = ARMreturnHomePosition ();
arm = ARMdoWash (100, 10, true, 1);
printf("\nArm Operating, Return Code = %d\n",arm);
usleep(100);
libClose();
}
The code can be debug and can be executed,
-----------------------------------------------------------------
My Question:
1. Due to the ARMdoWash () function required a period of time to perform, The Sleep() function is safe to use ? does it give any trouble ?
2. Because of the ARMdoWash () function can be various of time period (depend on the work cycle of the robot arm), to always adjust the sleep () time does not giving the best idea. Can it have a better way to replace this technique ?
-----------------------------------------------------------------
Thanks for the time, would appreciated for the help
Terry