void pid_all()
{
	printf("List of all processes spawned from this shell:\n");
	int i;
	for(i=0;i<num_proc;i++)
		print_process(i);
}
void pid_current()
{
	printf("List of currently executing processes spawned from this shell:\n");
	int i;
	for(i=0;i<num_proc;i++)
		if(proc[i].proc_run)
			print_process(i);
}
void print_stack(struct stack *head)
{
	while(head)
	{
		print_process(head->proc);
		head = head->next;
	}
}
Example #4
0
void print_all_processes(WINDOW* wnd) {
    wprintf(wnd, "State                    Active Priority Name\n");
    wprintf(wnd, "---------------------------------------------\n");
    int i;
    for(i = 0; i < MAX_PROCS; i++) {
        if(pcb[i].used) {
            print_process(wnd, &pcb[i]);
        }
    }
}
void print_queue(struct queue *head)
{
	printf("Queue: ");
	while(head)
	{
		print_process(head->proc);
		head = head->next;
	}
	printf("\n");
}
void helper_print_preorder(struct process *root)
{
	// Recursively prints a binary tree using preorder traversal
	// PRE: none
	// POST: none
	if(root)
	{
		print_process(root);
		helper_print_preorder(root->left);
		helper_print_preorder(root->right);
	}
}
/***************************************************************************
 * Affichage sur STDERR du contenu du tableau de processus (DEBUG)
 */
inline void print_processes(global_table_t global_table) {
        unsigned int i;
       
        _BIANCA_monitor_fprintf(stderr,"=== GLOBAL =======================\n");
        _BIANCA_monitor_fprintf(stderr,"Size : %d\n",global_table.size);
        _BIANCA_monitor_fprintf(stderr,"Max-Size : %d\n",global_table.maxsize);
        _BIANCA_monitor_fprintf(stderr,"Processes : \n");
        for (i=0 ; i<global_table.size; i++) {
                _BIANCA_monitor_fprintf(stderr,"\n  Proc ID --> %d\n",global_table.processes[i]->id);
                print_process(*(global_table.processes[i]));
        }
        _BIANCA_monitor_fprintf(stderr,"\n================================\n");
}
Example #8
0
void
refresh_list(){
	//List all the process
	DIR  *p;
	struct dirent *dirp;
	DIR  *p2;
	struct dirent *dirp2;
  	if ((p = opendir("/proc")) == NULL)
  	{
		printf("cannot open proc");
		return;
  	}

	int th=0;

	int x,y;

  	while( (dirp = readdir(p)) != NULL)
		if(dirp -> d_name[0] >='0' && dirp -> d_name[0] <='9'){
			//if(++th>32)break;

			struct process_t pp;
			open_process(dirp -> d_name,&pp);

			if(strstr(pp.comm+1,pfilter)!=pp.comm+1)continue;

			char buf[30];
			sprintf(buf,"/proc/%s/task",dirp -> d_name);
			if ((p2 = opendir(buf)) != NULL)
  			{
				while( (dirp2= readdir(p2)) != NULL){
					struct process_t p;

					p.processor=-1;
					open_process(dirp2 -> d_name,&p);
					if(p.processor==-1)continue;

					x=th%48;
					y=(th/48)*32;
					move(x+1,y);

					print_process(&p);
					th++;
				}
  			}


		}

  	closedir(p);
}
Example #9
0
void print_all_processes(WINDOW* wnd)
{
   //Print out header
   kprintf("%s %15s %s %s %s\n", "State", " ", "Active", "Prio", "Name");

   //Print border
   char border[] = "-------------------------------------------------------\n";
   output_string(wnd, border);

   int i;
   for(i = 0; i < MAX_PROCS; i++){
      if(pcb[i].used == TRUE){
         print_process(wnd, &pcb[i]);
      }
   }
}
Example #10
0
void print_job_list(job* job_list) {
    int      index;
    job*     jb;
    process* pr;

    for(index = 0, jb = job_list; jb != NULL; jb = jb->next, ++index) {
        printf("id %d [ %s ]\n", index,
               jb->mode == FOREGROUND ? "foreground" : "background" );

        for(pr = jb->process_list; pr != NULL; pr = pr->next) {
            if(print_process( pr ) < 0) {
                    exit(EXIT_FAILURE);
            }
            if(jb->next != NULL) {
                printf( "\n" );
            }
        }
    }
}
void process_bar( int n ) {
    print_process( n ) ;

    /**
     * 最终要实现 `=` 符号叠加, 百分比动态出现和清除(刷新)的效果
     * 这里的退格数需要根据 `print_process()` 中所有 `printf()` 需要的显示字符数来决定
     * 10 > n 代表的是一位数; else (n>=10) 代表的是二位数
     * 由于这两种百分比的情况需要退格的数不一样: 二位数需要比一位数多退格 1 次
     * 可以通过在末尾输出换行来调试需要退格的个数
     */

    if( 10>n ) {
        backspace( n + 62 ) ;
    } else if( 100==n ) {
        printf( "\n\n更新完成!\n" ) ;
    } else {
        backspace( n + 63 ) ;
    }
}
Example #12
0
    void search_usr_in_proc (char *uid)	//w katalogu /proc szuka procesow uzytkownika
     {
       DIR *dp;
       struct passwd *pwdp;
       struct dirent *ep;
       struct stat info;
       
       char filename[100];
       	
       dp = opendir ("/proc");
       if (dp != NULL)
         {
           while ((ep=(readdir(dp))))
           
           {
            	//tylko cyfry - katalogi -PID procesów
				if( strtok(ep->d_name, "0123456789") ==0 )	
				{
				snprintf (filename, sizeof (filename), "/proc/%s", ep->d_name);	
				stat(filename, &info);
				 
				 pwdp = getpwuid(info.st_uid);
							 
				if(strcmp(uid, pwdp->pw_name) == 0)
					{
						   printf("------------>Proces uzytkownika: %d %s \n process info:\n" ,info.st_uid,pwdp->pw_name);
						   get_procstat(filename);
						   print_process();
					}
				
				}
             
            }
           (void) closedir (dp);
         }
       else
         perror ("Couldn't open the directory");
     
 
     }
Example #13
0
int main(int argc, char **argv)
{
	int i;
	int rlist;
	int rval;
	int nproc;
	int depth;
	pid_t parent_pid;
	struct prinfo *buf;
	struct node *head;

	if (argc != 1) {
		printf("Usage:%s\n", argv[0]);
		goto error;
	}

	/*
	 * Run this loop as many times as necessary in order
	 * to allocate a big enough buffer to cover info
	 * for the entire process tree.
	 */
	for (i = 0, nproc = 1; i < MAX_ITER; i++) {
		buf = calloc(nproc, sizeof(struct prinfo));
		if (buf == NULL) {
			perror("calloc:");
			goto error;
		}
		printf("Allocated a buffer of size: %d\n", nproc);
		rval = syscall(223, buf, &nproc);
		if (rval < 0) {
			perror("ptree:");
			goto error_free_mem;
		}
		printf("Total number of processes running: %d\n", rval);
		if (rval <= nproc)
			break;
		printf("Re-allocating a larger buffer\n\n");
		free(buf);
		nproc <<= 1;
	}
	/* If we get here it means that the size
	 * of buf was large enough to keep info
	 * about the whole process tree.
	 */
	printf("\n\n");
	/* Printing the init_task */
	print_process(buf[0], 0);
	parent_pid = -1;
	depth = 0;
	for (i = 1; i != nproc; i++) {
		/*
		 * If you have the same parent with the previous
		 * process keep the same identation depth.
		 */
		if (parent_pid == buf[i].parent_pid) {
			print_process(buf[i], depth);
			continue;
		}
		/*
		 * If the previous process is your parent
		 * increase identation level.
		 */
		rlist = add_depth(buf[i].parent_pid, buf[i - 1].pid, &head);
		if (rlist == 1)
			goto error_list;
		if (rlist == 0) {
			depth++;
			parent_pid = buf[i].parent_pid;
			print_process(buf[i], depth);
			continue;
		}
		/*
		 * If none of the above applies, then you are
		 * a sibling of the previous process's parent.
		 */
		while (buf[i].parent_pid != get_data_from_start(&head)) {
			--depth;
			remove_from_start(&head);
		}
		parent_pid = buf[i].parent_pid;
		print_process(buf[i], depth);
	}
	return 0;

error_list:
	free_all_nodes(&head);
error_free_mem:
	free(buf);
error:
	return -1;
}
int main(int argc, char* argv[]) {
    if(argc != 4) {
        usage();
        exit(1);
    }
    
    init_env();
    init_protocal_buf();
    pthread_mutex_init(&lockDownload, NULL);
    /** init server address **/
    struct sockaddr_in servaddr;
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(SERV_PORT);
    if(inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0) {
        printf("[%s] is not avalid IP address!\n", argv[1]);
        exit(1);
    }
    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);

    /** check if configure file exists **/
    char conf_full[100];
    strcpy(conf_full, path);
    strcat(conf_full, conf_file);
    if(access(conf_full, 0) == -1) {
        task_flag = NEW_TASK;
        printf("cannot access the file %s\n", conf_full);
        /** init config file, can be expended later for any request **/
        init_conf(conf_full);
    }else {
        task_flag = OLD_TASK;
        printf("access the file %s\n", conf_full);
        
        //TODO continue to send
        config_t *conf_hd = confRead(conf_full);
        sprintf(filename, "%s", confGet(conf_hd, "filename")); 
        load_detail(conf_hd);
        confDestory(conf_hd);
    }

    queue = Initialize_Queue();
    //Add_Queue_Item(queue, "", file_name, 0);
    //Add_Queue_Item(queue, "", file_name, 0);
    //Add_Queue_Item(queue, "", file_name, 0);

    cookLive        = YES;
    soldierLive     = YES;
    receiverLive    = YES;

    /** start Cook thread **/
    pthread_t cook_fd;
    pthread_create(&cook_fd, NULL, cook_mission, path);
    //pthread_join(cook_fd, NULL);

    /** start Receiver thread **/
    pthread_t receiver_id;
    pthread_create(&receiver_id, NULL, receiver, NULL);
    
    //pthread_join(cook_fd, NULL);
    //pthread_join(receiver_id, NULL);
    printf("===========================================================\n");

    struct synack syn_pack;
    syn_pack.thread_num = THREAD_LIMITION;
    syn_pack.file_info.blocksize = BODYLEN;


    while(clientLive){
        soldierLive = YES;
        taskIndex = 0;
        taskArray = NULL;
        filesize = 0;
        block_num = 0;

        QUEUE_ITEM *item = NULL;
        //memset(item, 0, sizeof(QUEUE_ITEM));

        while(!item && clientLive == YES){
            printf("[Main] main thread check queue\n");
            item = Get_Queue_Item(queue);
            if(item){
                printf("[Main] item.filename = %s\n", item->data);
                strcpy(filename, item->data);
                printf("[Main] transmitting: %s \n", filename);
                break;
            }else{
                printf("[Main] Queue empty will check again in 2 seconds...\n");
                sleep(2);
            }
        }
        

        strcpy(syn_pack.file_info.filename, filename);

        /** count filesize **/
        char target_full[100];
        strcpy(target_full, path);
        strcat(target_full, filename);
        int fd = open(target_full, O_RDONLY);
        filesize = get_filesize(fd);
        syn_pack.file_info.filesize = filesize;

        /** count block_num **/
        if(filesize % BODYLEN == 0)
            syn_pack.file_info.block_num = filesize / BODYLEN;
        else
            syn_pack.file_info.block_num = filesize / BODYLEN + 1;
        block_num = syn_pack.file_info.block_num;

        /** make taskArray **/
        taskArray = (int*)malloc(sizeof(int) * block_num);
        memset(taskArray, 0, sizeof(int) * block_num);

        /* count downloaded_block */
        if(task_flag == NEW_TASK) {
            printf("new task\n");
            downloaded_block = 0;
        } else {
            printf("block_num = %d, thread_num = %d, blocksize = %d, filesize = %d\n", syn_pack.file_info.block_num, syn_pack.thread_num, syn_pack.file_info.blocksize, syn_pack.file_info.filesize);

            /** count local global downloaded_block **/
            downloaded_block = 0;
            if(downloaded_block == block_num) {
                printf("download already finished\n");
                continue;
            }
            task_flag = OLD_TASK;
        }

        syn_pack.file_info.downloaded_block = downloaded_block;
        printf("figure out filesize = %d, block_num = %d, downloaded_block = %d\n", filesize, block_num, downloaded_block);

        {
        /**TODO store config info **/
        /*config_t *conf_hd = confRead(conf_full);
          if(conf_hd == NULL)
          {
          printf("conf file null, return \n");
          return 0;
          }
          confSet(conf_hd, "filename", filename);
          confSet(conf_hd, "filesize", filesize);
          store_detail(conf_hd);
          confDestory(conf_hd); */
        }

        /** ask for link with server **/
        struct synack synack_pack = get_new_port(syn_pack, sockfd, (struct sockaddr*)(&servaddr), sizeof(servaddr));
        printf("receive: thread_num = %d, downloaded_block = %d, block_num = %d\n", synack_pack.thread_num, synack_pack.file_info.downloaded_block, synack_pack.file_info.block_num);

        //if(synack_pack == NULL){
            //printf("main get connection failed, exiting...\n");
            //process_end();
            //return 0;
        //}

        /** create subthreads here **/
        task_list = (struct subthread_task *)malloc(sizeof(struct subthread_task) * THREAD_LIMITION);
        int i;
        for(i = 0; i < THREAD_LIMITION; i++) {
            task_list[i].hostname = argv[1];
            task_list[i].port = synack_pack.port[i];

            task_list[i].thread_no = i + 1;
            task_list[i].thread_num = THREAD_LIMITION;

            strcpy(task_list[i].file_info.filename, filename);
            task_list[i].file_info.filesize= filesize;

            task_list[i].file_info.block_num = block_num;
            task_list[i].file_info.blocksize= BODYLEN;

            pthread_create(&ptid[i], NULL, soldier_mission, &task_list[i]);
        }

        signal(SIGINT, process_end);
        signal(SIGKILL, process_end);

        /** print the transmit progress **/
        do{
            sleep(0.1);
            //int percent = (downloaded_block * 100) / block_num;
            /** print_process(percent, 100); **/
        }while(downloaded_block < block_num);

        //soldierLive = NO;   
        
        for(i = 0; i < THREAD_LIMITION; i ++){
            pthread_join(ptid[i], NULL);
        }
        print_process(100, 100); 
        printf("\ndownload finished, exiting...[please wait and not interrupt or power off]\n");
        
        //int j = 0;
        //for(; j < block_num; j ++)
            //printf("%d, ", taskArray[i]);
        //printf("\n");

        free(task_list);
        free(taskArray);
        task_list = NULL;
        taskArray = NULL;
    }

    pthread_mutex_destroy(&lockDownload);
    return 0;
}
Example #15
0
int engine(struct engine_s *e)
{
	int ret=0;
	int i;

#ifdef DEBUG
	do {
		CPUSET_HEXSTRING(tmpaff);
		printf("Dumping mode: 0x%x\n", e->mode);
		printf("Dumping affinity: 0x%s\n", cpuset_to_str(&(e->aff_mask), tmpaff));
		printf("We have %d args to do\n", e->n);
		for(i=0;i < e->n; i++) {
			printf("Dump arg %d: %s\n", i, e->args[i]);
		}
	} while(0);
#endif

	/*
	 handle normal query/set operation:
	 set/query all given PIDs
	 */
	for(i=0; i < e->n; i++) {

		int pid, tmpret=0;
		cpu_set_t affi;

		CPU_ZERO(&affi);
                CPU_SET(0, &affi);

                /* if in MODE_EXEC skip check for PIDs */
		if(mode_set(e->mode, MODE_EXEC)) {
			pid=getpid();
			goto exec_mode_special;
		}

		if(! (isdigit( *(e->args[i])) ) ) {
			decode_error("Ignoring arg %s: is not a PID", e->args[i]);
			continue;
		}

		pid=atoi(e->args[i]);

	exec_mode_special:
		if(mode_set(e->mode, MODE_SETPOLICY)) {
			struct sched_param_ex p;

			p.sched_priority= e->prio;
			p.sched_runtime=us_to_tspec(e->rtime);
			p.sched_deadline=us_to_tspec(e->dline);
			p.sched_period=us_to_tspec(e->priod);
			p.sched_flags=e->flags;

			/*
			 accumulate possible errors
			 the return value of main will indicate
			 how much set-calls went wrong
                         set_process returns -1 upon failure
			 */
			tmpret=set_process(pid,e->policy,&p);
			ret += tmpret;

                        /* don't proceed as something went wrong already */
			if(tmpret) {
				continue;
			}

		}

		if(mode_set(e->mode, MODE_NICE)) {
			tmpret=set_niceness(pid, e->nice);
                        ret += tmpret;

			if(tmpret) {
				continue;
			}

		}

		if(mode_set(e->mode, MODE_AFFINITY)) {
			tmpret=set_affinity(pid, &(e->aff_mask));
			ret += tmpret;

			if(tmpret) {
				continue;
			}

		}

		/* and print process info when set, too */
		if(mode_set(e->mode, MODE_PRINT)) {
			print_process(pid);
		}


		/* EXECUTE: at the end */
		if(mode_set(e->mode, MODE_EXEC)) {

			char **new_argv=e->args;

			ret=execvp(*new_argv, new_argv);

			/* only reached on error */
			decode_error("schedtool: Could not exec %s", *new_argv);
			return(ret);
		}
	}
	/*
	 indicate how many errors we got; as ret is accumulated negative,
	 convert to positive
	 */
	return(abs(ret));
}
Example #16
0
/*
 * The event loop for display. It displays data on screen and handles hotkey
 * presses.
 *
 * Parameter :
 *		duration - returns after 'duration'
 *
 * The function also returns if user presses 'q', 'Ctrl+C' or 'r'.
 *
 * Return value:
 *		0 - main() exits
 *		1 - main() calls it again
 */
int
lt_display_loop(int duration)
{
	uint64_t start;
	int remaining;
	struct timeval timeout;
	fd_set read_fd;
	int need_refresh = TRUE;
	pid_t *plist = NULL;
	id_t *tlist = NULL;
	int list_len = 0;
	int list_index = 0;
	int retval = 1;
	int next_snap;
	int gpipe;

	start = lt_millisecond();
	gpipe = lt_gpipe_readfd();

	if (!show_help) {
		print_hint(NULL);
		print_sysglobal();
	}

	get_plist(&plist, &tlist, &list_len, &list_index);

	for (;;) {
		if (need_refresh && !show_help) {
			if (list_len != 0) {
				if (!thread_mode) {
					print_taskbar_process(plist, list_len,
					    list_index);
					print_process(plist[list_index]);
				} else {
					print_taskbar_thread(plist, tlist,
					    list_len, list_index);
					print_thread(plist[list_index],
					    tlist[list_index]);
				}
			} else {
				print_empty_process_bar();
			}
		}

		need_refresh = TRUE;	/* Usually we need refresh. */
		remaining = duration - (int)(lt_millisecond() - start);

		if (remaining <= 0) {
			break;
		}

		/* Embedded dtrace snap action here. */
		next_snap = lt_dtrace_work(0);

		if (next_snap == 0) {
			/*
			 * Just did a snap, check time for the next one.
			 */
			next_snap = lt_dtrace_work(0);
		}

		if (next_snap > 0 && remaining > next_snap) {
			remaining = next_snap;
		}

		timeout.tv_sec = remaining / 1000;
		timeout.tv_usec = (remaining % 1000) * 1000;

		FD_ZERO(&read_fd);
		FD_SET(0, &read_fd);
		FD_SET(gpipe, &read_fd);

		/* Wait for keyboard input, or signal from gpipe */
		if (select(gpipe + 1, &read_fd, NULL, NULL, &timeout) > 0) {
			int k = 0;

			if (FD_ISSET(gpipe, &read_fd)) {
				/* Data from pipe has priority */
				char ch;
				(void) read(gpipe, &ch, 1);
				k = ch; /* Need this for big-endianness */
			} else {
				k = getch();
			}

			/*
			 * Check if we need to update the hint line whenever we
			 * get a chance.
			 * NOTE: current implementation depends on
			 * g_config.lt_cfg_snap_interval, but it's OK because it
			 * doesn't have to be precise.
			 */
			print_hint(NULL);
			/*
			 * If help is on display right now, and a key press
			 * happens, we need to clear the help and continue.
			 */
			if (show_help) {
				(void) werase(stdscr);
				(void) refresh();
				print_title();
				print_sysglobal();
				show_help = FALSE;
				/* Drop this key and continue */
				continue;
			}

			switch (k) {
			case 'Q':
			case 'q':
				retval = 0;
				goto quit;
			case 'R':
			case 'r':
				lt_display_deinit();
				lt_display_init();
				goto quit;
			case 'H':
			case 'h':
				show_help = TRUE;
				(void) werase(stdscr);
				(void) refresh();
				print_help();
				break;
			case ',':
			case '<':
			case KEY_LEFT:
				--list_index;

				if (list_index < 0) {
					list_index = 0;
				}

				break;
			case '.':
			case '>':
			case KEY_RIGHT:
				++list_index;

				if (list_index >= list_len) {
					list_index = list_len - 1;
				}

				break;
			case 'a':
			case 'A':
				sort_type = LT_SORT_AVG;
				print_sysglobal();
				break;
			case 'p':
			case 'P':
				sort_type = LT_SORT_TOTAL;
				print_sysglobal();
				break;
			case 'm':
			case 'M':
				sort_type = LT_SORT_MAX;
				print_sysglobal();
				break;
			case 'c':
			case 'C':
				sort_type = LT_SORT_COUNT;
				print_sysglobal();
				break;
			case 't':
			case 'T':
				if (plist != NULL) {
					selected_pid = plist[list_index];
				}

				selected_tid = INVALID_TID;
				thread_mode = !thread_mode;
				get_plist(&plist, &tlist,
				    &list_len, &list_index);
				break;
			case '1':
			case '!':
				current_list_type = LT_LIST_CAUSE;
				print_sysglobal();
				break;
			case '2':
			case '@':
				if (g_config.lt_cfg_low_overhead_mode) {
					lt_display_error("Switching mode is "
					    "not available for '-f low'.");
				} else {
					current_list_type = LT_LIST_SPECIALS;
					print_sysglobal();
				}

				break;
			case '3':
			case '#':
				if (g_config.lt_cfg_trace_syncobj) {
					current_list_type = LT_LIST_SOBJ;
					print_sysglobal();
				} else if (g_config.lt_cfg_low_overhead_mode) {
					lt_display_error("Switching mode is "
					    "not available for '-f low'.");
				} else {
					lt_display_error("Tracing "
					    "synchronization objects is "
					    "disabled.");
				}

				break;
			default:
				/* Wake up for nothing; no refresh is needed */
				need_refresh = FALSE;
				break;
			}
		} else {
			need_refresh = FALSE;
		}
	}

quit:
	if (plist != NULL) {
		selected_pid = plist[list_index];
	}

	if (tlist != NULL) {
		selected_tid = tlist[list_index];
	}

	lt_stat_proc_list_free(plist, tlist);

	return (retval);
}
Example #17
0
void print_process_file(Panda__ProcessFile *pf) {
    print_process(pf->proc);
    printf (" filename=[%s]", pf->filename);
}
Example #18
0
void print_process_key(Panda__ProcessKey *pk) {
    print_process(pk->proc);
    printf (" key=[%s] ", pk->keyname);
}
Example #19
0
int main(int argc, char *argv[])
{
    // ==================== YOUR CODE HERE ==================== //

    // Load the dispatchlist
    char *dpFile = NULL;

    if(argc > 1)
        dpFile = argv[1];

    // Read the dispatch file 
    load_dispatch(dpFile);

    // Iterate through each item in the job dispatch list, add each process
    // to the appropriate queues
    dispTime = 0;

    // Execute the block once
    do {
        // Iinitialize available resources
        initializeAvaiableResources();

        // queue data structure
        structNode *poppedStruct;

        // continually loop until dispatches aren't null
        while ( listOfDispatches != NULL  && seek(listOfDispatches)->process.arrival_time <= dispTime)  {
        	// Check if the next list of dispatch is empty
            if (listOfDispatches->next == NULL)  {
            	// pop the first element from the list of dispatches
              poppedStruct = listOfDispatches;
              listOfDispatches = NULL;
            }
            else {
              poppedStruct = pop(listOfDispatches);
            }

            // check if the popped dispatcher has arrival time that is less than the dispatched time
            if (poppedStruct->process.arrival_time <= dispTime)  {
            	// get the status of the realtime job
              bool process_1 = poppedStruct->process.res.num_printers > 0 || poppedStruct->process.res.num_scanners > 0 || poppedStruct->process.res.num_modems > 0 || poppedStruct->process.res.num_CDs > 0;
              bool process_2 = poppedStruct->process.res.num_printers > NUM_PRINTERS || poppedStruct->process.res.num_scanners > NUM_SCANNERS || poppedStruct->process.res.num_modems > NUM_MODEMS || poppedStruct->process.res.num_CDs > NUM_CDS;

              // check if the process priority is 0
              if (poppedStruct->process.priority == 0)  {
            	  	  // check if process 1 is true
                    if (process_1) {
                        printf("ERROR WITH THE REAL TIME JOB\n");
                    }
                    else {
                    	// push the process to the queue
                        rtData = push(rtData, poppedStruct->process);
                    }
                }
                else {
                	// check if the second process is true
                    if (process_2) {
                        printf("ERROR WITH THE RESOURCE\n");
                    }
                    else {
                    	// push the process onto the queue
                        userJobs = push(userJobs, poppedStruct->process);
                    }
                }
            }
        }

        // Allocate the resource necessary for the process
        // check if the user jobs aren't null
        // Check the amount of free space and return true if there is enough space for allocation
        // check for the available resource
        // continually loop until these above criteria meets
        while(userJobs != NULL && checkForMemory(userJobs->process.res, userJobs->process.MBytes) && checkForResources(userJobs->process.res))  {
        		// set the memory index to the allocated memory
                userJobs->process.memory_index = alloc_mem(userJobs->process.res, userJobs->process.MBytes);

                // create temporary queue structure
                structNode *temp;

                // continually loop through the jobs
                while( userJobs != NULL) {
                	// Check if the next element is null
                    if (userJobs->next == NULL){
                    	// assign the job to the temporary queue
                      temp = userJobs;

                      userJobs = NULL;
                    }
                    else {
                    	// pop the first element and add it to temp queue
                      temp = pop(userJobs);
                }

                // Allocate the resources for the temp process
                allocateResources(temp->process);

                // push the process to the queue
                pushToQueue(temp->process);
            }
        }

        // check if the active doesn't contain NULL
       if (activeProcess != NULL) {
    	   // decrement the active processes
            activeProcess->process.processor_time--;

            // check if the processor time is 0
            if (activeProcess->process.processor_time == 0)  {
            	// kill the active process
                kill(activeProcess->process.pid, SIGINT);

                // system call suspends execution of the calling process until a child specified by the pid
                waitpid(activeProcess->process.pid, &status, WUNTRACED);

                // free the memory
                free_mem(activeProcess->process.res, activeProcess->process.memory_index, activeProcess->process.MBytes);

                // Free the resources
                freeResources(activeProcess->process.res);

                // free the variable
                free(activeProcess);

                activeProcess = NULL;
            } else if (activeProcess->process.priority > 0 && !(rtData == NULL && firstPriority == NULL && secondPriority == NULL && thirdPriority == NULL)) {
                // kill the process
            	kill(activeProcess->process.pid , SIGTSTP);

                // system call suspends execution of the calling process until a child specified by the pid
                waitpid(activeProcess->process.pid + 1, &status, WUNTRACED);

                // set the suspended state to true
                activeProcess->process.suspended = true;

                // check if the priority is less than 3
                if(activeProcess->process.priority < 3)  {
                	// increment the priority
                    activeProcess->process.priority++;
                }

                // push the process to queue
                pushToQueue(activeProcess->process); // add back to the queue
                activeProcess = NULL;

            }
       }

       // Pop the first process from the queue
       if (activeProcess == NULL && !(rtData == NULL && firstPriority == NULL && secondPriority == NULL && thirdPriority == NULL))  {
           // check if the real time data is not null
    	   if (rtData != NULL)  {
    		   // check if the next element is not null
                if (rtData->next != NULL) {
                	// pop the first element and assign it to active
                    activeProcess = pop(rtData);
                } else {
                	// set the active process
                    activeProcess = rtData;
                    rtData = NULL;
                }
            } else if (firstPriority != NULL) {
            	// check if the first priority is not null
                if (firstPriority->next != NULL) {
                	// pop the first element
                    activeProcess = pop(firstPriority);
                } else {
                	// set the first priority to an active process
                    activeProcess = firstPriority;
                    firstPriority = NULL;
                }
            } else if (secondPriority != NULL) {
            	// check if the second priority has next element
                if (secondPriority->next != NULL) {
                	// pop the first element and assign it to the active process
                    activeProcess = pop(secondPriority);
                } else {
                	// assign the second priority task to the process
                    activeProcess = secondPriority;
                    secondPriority = NULL;
                }
            } else if (thirdPriority != NULL) {
            	// check if the next element in third priority is not null
                if (thirdPriority->next != NULL) {
                	// pop the first element and add it to active process
                    activeProcess = pop(thirdPriority);
                } else {
                	// assign the third priority to the active process
                    activeProcess = thirdPriority;
                    thirdPriority = NULL;
                }
            }

    	    // check if the process is suspended
            if(activeProcess->process.suspended == true)  {
            	// kill the suspended process
                kill(activeProcess->process.pid, SIGCONT);

                // set the state of suspended to false
                activeProcess->process.suspended = false;
            } else {
            	// create process id
                pid_t pid;

                // fork the process
                pid = fork();

                // check if the pid is less than 0, then throw error
                if (pid < 0) {
                    printf("ERROR WITH FORK\n");
                }
                else if (pid == 0)  {
                	// get the child process
                    execvp(procArgv[0], procArgv);
                }
                // set the active process id
                activeProcess->process.pid = pid;

                // print the process to the console
                print_process(activeProcess->process);

            }
        }

    // sleep for 1 second
    sleep(1);

    // increment the dispatcher time
    dispTime ++;
    //printf("Time: %d\n", dispTime);
   } while (activeProcess != NULL || !(rtData == NULL && firstPriority == NULL && secondPriority == NULL && thirdPriority == NULL) || listOfDispatches != NULL);

    return EXIT_SUCCESS;
}
Example #20
0
int main (int argc, char **argv) {
    
    str2ind = LoadDB(std::string("/tmp/lavadb"));
    ind2str = InvertDB(str2ind);
    
    pandalog_open(argv[1], "r");
    Panda__LogEntry *ple;
    while (1) {
        ple = pandalog_read_entry();
        if (ple == NULL) {
            break;
        }
        if (ple->instr == -1) {
            printf ("[after replay end] : ");
        } 
        else {
            printf ("instr=%" PRIu64 " pc=0x%" PRIx64 " :", ple->instr, ple->pc);
        }

        // from asidstory / osi
        if (ple->has_asid) {
            printf (" asid=%" PRIx64, ple->asid);
        }

        if (ple->has_process_id != 0) {
            printf (" pid=%d", ple->process_id);
        }
        if (ple->process_name != 0) {
            printf (" process=[%s]", ple->process_name);
        }

        // from file_taint
        if (ple->has_taint_label_number) {
            printf (" tl=%d", ple->taint_label_number);
        }
        if (ple->has_taint_label_virtual_addr) {
            printf (" va=0x%" PRIx64, ple->taint_label_virtual_addr);
        }
        if (ple->has_taint_label_physical_addr) {
            printf (" pa=0x%" PRIx64 , ple->taint_label_physical_addr);
        }

        if (ple->n_callstack > 0) {
            printf (" callstack=(%u,[", (uint32_t) ple->n_callstack);
            uint32_t i;
            for (i=0; i<ple->n_callstack; i++) {
                printf (" 0x%" PRIx64 , ple->callstack[i]);
                if (i+1 < ple->n_callstack) {
                    printf (",");
                }
            }
            printf ("])");
        }

        if (ple->attack_point) {
            Panda__AttackPoint *ap = ple->attack_point;
            printf (" attack point: info=[%u][%s]", ap->info, gstr(ap->info));
        }

        if (ple->src_info) {
            Panda__SrcInfo *si = ple->src_info;
            printf (" src info filename=[%u][%s] astnode=[%u][%s] linenum=%d",
                    si->filename, gstr(si->filename), si->astnodename, 
                    gstr(si->astnodename), si->linenum);
        }

        if (ple->has_tainted_branch && ple->tainted_branch) {
            printf (" tainted branch");
        }
        if (ple->taint_query_hypercall) {
            Panda__TaintQueryHypercall *tqh = ple->taint_query_hypercall;
            printf (" taint query hypercall(buf=0x%" PRIx64 ",len=%u,num_tainted=%u)", tqh->buf, tqh->len, tqh->num_tainted);
        }
        if (ple->has_tainted_instr && ple->tainted_instr) {
            printf (" tainted instr");
        }

        // dead data
        if (ple->n_dead_data > 0) {
            printf ("\n");
            uint32_t i;
            for (i=0; i<ple->n_dead_data; i++) {
                printf (" dead_data(label=%d,deadness=%.2f\n", i, ple->dead_data[i]);
            }
        }

        // taint queries
        if (ple->taint_query_unique_label_set) {
            printf (" taint query unqiue label set: ptr=%" PRIx64" labels: ", ple->taint_query_unique_label_set->ptr);
            uint32_t i;
            for (i=0; i<ple->taint_query_unique_label_set->n_label; i++) {
                printf ("%d ", ple->taint_query_unique_label_set->label[i]);
            }
        }
        
        if (ple->taint_query) {
            Panda__TaintQuery *tq = ple->taint_query;
            printf (" taint query: labels ptr %" PRIx64" tcn=%d off=%d", tq->ptr, (int) tq->tcn, (int) tq->offset);
        }

        // win7proc
        if (ple->new_pid) { 
            printf (" new_pid ");
            print_process(ple->new_pid);
        }
        if (ple->nt_create_user_process) {
            printf (" nt_create_user_process ");
            printf (" [ cur " ); 
            print_process(ple->nt_create_user_process->cur_p); 
            printf (" ]");
            printf (" [ new " ); 
            print_process(ple->nt_create_user_process->new_p); 
            printf (" ]");
            printf (" name=[%s] ", 
                    ple->nt_create_user_process->new_long_name);
        }
        if (ple->nt_terminate_process) {
            printf (" nt_terminate_process ");
            printf (" [ cur " ); 
            print_process(ple->nt_terminate_process->cur_p);
            printf (" ]");
            printf (" [ term " ); 
            print_process(ple->nt_terminate_process->term_p);
            printf (" ]");
        }

        if (ple->nt_create_file) {
            printf (" nt_create_file ");
            print_process_file(ple->nt_create_file);
        }

        if (ple->nt_read_file) {
            printf (" nt_read_file ");
            print_process_file(ple->nt_read_file);
        }
        if (ple->nt_delete_file) {
            printf (" nt_delete_file ");
            print_process_file(ple->nt_delete_file);
        }
        if (ple->nt_write_file) {
            printf ("nt_write_file ");
            print_process_file(ple->nt_write_file);
        }
        if (ple->nt_create_key) {
            printf (" nt_create_key ");
            print_process_key(ple->nt_create_key);
        }
        if (ple->nt_create_key_transacted) {
            printf (" nt_create_key_transacted ");
            print_process_key(ple->nt_create_key_transacted);
        }
        if (ple->nt_open_key) {
            printf (" nt_open_key ");
            print_process_key(ple->nt_open_key);
        }
        if (ple->nt_open_key_ex) {
            printf (" nt_open_key_ex ");
            print_process_key(ple->nt_open_key_ex);
        }
        if (ple->nt_open_key_transacted) {
            printf (" nt_open_key_transacted ");
            print_process_key(ple->nt_open_key_transacted);
        }
        if (ple->nt_open_key_transacted_ex) {
            printf (" nt_open_key_transacted_ex ");
            print_process_key(ple->nt_open_key_transacted_ex);
        }
        if (ple->nt_delete_key) {
            printf (" nt_delete_key ");
            print_process_key(ple->nt_delete_key);
        }
        if (ple->nt_query_key) {
            printf (" nt_query_key ");
            print_process_key(ple->nt_query_key);
        }
        if (ple->nt_query_value_key) {
            printf (" nt_query_value_key ");
            print_process_key_value(ple->nt_query_value_key);
        }
        if (ple->nt_delete_value_key) {
            printf (" nt_delete_value_key ");
            print_process_key_value(ple->nt_delete_value_key);
        }
        if (ple->nt_set_value_key) {
            printf (" nt_set_value_key ");
            print_process_key_value(ple->nt_set_value_key);
        }
        if (ple->nt_enumerate_key) {
            printf (" nt_enumerate_key ");
            print_process_key_index(ple->nt_enumerate_key);
        }
        if (ple->nt_enumerate_value_key) {
            printf (" nt_enumerate_value_key ");
            print_process_key_index(ple->nt_enumerate_value_key);
        }

        printf ("\n");
        panda__log_entry__free_unpacked(ple, NULL);
    }
}