// main ... int main() { /* Handle SIGCHLD by calling clean_up_child_process. */ struct sigaction sigchld_action; memset (&sigchld_action, 0, sizeof (sigchld_action)); sigchld_action.sa_handler = &clean_up_child_process; sigaction (SIGCHLD, &sigchld_action, NULL); int waitreturn; int launch_status = 0; launch_status = launch_item( dirs[0] ); // check conditions ... launch_status = launch_item( dirs[1] ); // check conditions ... launch_status = launch_item( dirs[2] ); // check conditions ... /* Check whether main is parent or child */ printf("Main PID: %d\n", getpid()); /* check for ended child processes */ int n = 0; int rc; while(n < 7) { errno = 0; waitreturn = waitpid(-1, &rc, WNOHANG); //printf("\nrc (status): %d\n", rc); if (-1 == waitreturn) { //syslog(LOG_ERR, "error waiting for child process! (%d:%s)", errno, strerror(errno)); //printf("error waiting for child process!: (%d:%s) \n", errno, strerror(errno)); } else if (0 < waitreturn) { printf("pid of child whose state has changed: %d\n", waitreturn); n++; } else if (0 == waitreturn) { //printf("processes are still running\n"); } if (0 != WEXITSTATUS(rc)) { //syslog(LOG_ERR, "command failed to execute correctly! (%d)", WEXITSTATUS(rc)); printf("command failed to execute correctly!: (%d) \n" , WEXITSTATUS(rc)); } //n++; //sleep(0.25); } // keep the program from ending before the child processes //sleep(21); }
int main (int argc, char **argv) { char *file; gboolean launch = FALSE; if (argc < 2 || argc > 3) { fprintf (stderr, "Usage: test-ditem path [LAUNCH]\n"); exit (1); } if (argc == 3 && strcmp (argv[2], "LAUNCH") == 0) launch = TRUE; file = g_strdup (argv[1]); gtk_init (&argc, &argv); if (launch) launch_item (file); else test_ditem (file); /* test_ditem_edit (file); */ return 0; }
// main ... int32_t main() { int32_t launch_status = 0; int32_t dir_index = 0; int32_t i = 0; // get number of elements in dirs ... int32_t dirs_array_size = 0; while( '\0' != dirs[++dirs_array_size] ); // launch items in each dirs directory. If directory empty, do nothing. for (dir_index = 0; dir_index < dirs_array_size; dir_index++) { printf("OPEN DIRECTORY: %s \n", dirs[dir_index] ); //launch_status = launch_item(dirs[dir_index] , first_node, nth_node ); launch_status = launch_item( dirs[dir_index] ); if (1 == launch_status) { printf("DIRECTORY %s IS EMPTY! NOTHING LAUNCHED! \n\n", dirs[dir_index]); } else { printf("ITEMS IN %s LAUNCHED! \n", dirs[dir_index] ); printf("CLOSE DIRECTORY: %s \n\n", dirs[dir_index] ); } } for ( i = 0; i < pid_list_cnt; i++ ) { printf( "PID LIST: %d \n" , child_pid_list[ i ] ); } return 0; }
// main ... int main() { printf("Parent pid: %d\n", getpid()); int waitreturn; int launch_status = 0; launch_status = launch_item( dirs[0] ); // check conditions ... launch_status = launch_item( dirs[1] ); // check conditions ... launch_status = launch_item( dirs[2] ); // check conditions ... /* check for ended child processes */ int n = 0; int rc; while(n < 7) { errno = 0; waitreturn = waitpid(-1, &rc, WNOHANG); //printf("\nrc (status): %d\n", rc); if (-1 == waitreturn) { //syslog(LOG_ERR, "error waiting for child process! (%d:%s)", errno, strerror(errno)); printf("error waiting for child process!: (%d:%s) \n", errno, strerror(errno)); } else if (0 < waitreturn) { printf("pid of child whose state has changed: %d\n", waitreturn); n++; } else if (0 == waitreturn) { //printf("processes are still running\n"); } if (0 != WEXITSTATUS(rc)) { //syslog(LOG_ERR, "command failed to execute correctly! (%d)", WEXITSTATUS(rc)); printf("command failed to execute correctly!: (%d) \n" , WEXITSTATUS(rc)); } } }
// main ... int main() { // create linked list ... child_pid_list *first_node = (child_pid_list *)malloc(sizeof(child_pid_list)); if (first_node != NULL) { printf("GOOD malloc \n"); first_node->next = NULL; nth_node = first_node; printf("FIRST NODE: %p \n" , first_node ); printf("NEXT NODE: %p \n" , first_node->next ); } else { printf("BAD malloc \n"); } // end create linked list ... int launch_status = 0; int dir_index = 0; // get number of elements in dirs ... int dirs_array_size = 0; while(dirs[++dirs_array_size]!='\0'); // launch items in each dirs directory. If directory empty, do nothing. for (dir_index = 0; dir_index < dirs_array_size; dir_index++) { printf("OPEN DIRECTORY: %s \n", dirs[dir_index] ); //launch_status = launch_item(dirs[dir_index] , first_node, nth_node ); launch_status = launch_item( dirs[dir_index] ); if (1 == launch_status) { printf("DIRECTORY %s IS EMPTY! NOTHING LAUNCHED! \n\n", dirs[dir_index]); } else { printf("ITEMS IN %s LAUNCHED! \n", dirs[dir_index] ); printf("CLOSE DIRECTORY: %s \n\n", dirs[dir_index] ); } } // all done, so last node is NULL nth_node->next = NULL; // print list ... similiar usage to traverse and check pids ... nth_node = first_node; while( nth_node->next != NULL) { printf( "PID: %d \n" , nth_node->child_pid ); printf( "DIR: %s \n" , nth_node->dir ); printf( "NAME: %s \n\n" , nth_node->item_name ); nth_node = nth_node->next; } return 0; }