#include #include #include #include #include #include #include #include int main(int, char **argv) { sched_param param; sched_getparam( 0, ¶m ); param.sched_priority = 2; if ( 0 != sched_setscheduler( 0, SCHED_FIFO, ¶m ) ) { perror( "1. fail" ); } const pid_t pid = fork(); if ( pid == 0 ) { // I'm the child // make the child realtime prio, but less than the parent sched_param param2; sched_getparam( 0, ¶m2 ); param2.sched_priority = 1; if ( 0 != sched_setscheduler( 0, SCHED_FIFO, ¶m2 ) ) { perror( "2. fail" ); } // drop privileges if ( geteuid() != getuid() ) { seteuid( getuid() ); if ( geteuid() != getuid() ) { return -1; } argv[0] = strdup( "./CA" ); execv( "./CA", argv ); perror( "./CA" ); return -1; } } timeval timeout; for ( int i = 0; i < 600; ++i ) { timeout.tv_sec = 1; timeout.tv_usec = 0; select( 0, 0, 0, 0, &timeout ); if ( pid == waitpid( pid, 0, WNOHANG ) ) { return 0; } } kill( pid, SIGKILL ); return 0; }