Пример #1
0
/* module init function is called from finit_module() system call */
static int dummy_load(void)
{
	printk(KERN_INFO "%s\n", __func__);

	print_process_info();

	return 0;
}
Пример #2
0
static void
process_killer(void)
{
    int i, j, max = erts_ptab_max(&erts_proc);
    Process* rp;

    erts_printf("\n\nProcess Information\n\n");
    erts_printf("--------------------------------------------------\n");
    for (i = max-1; i >= 0; i--) {
	rp = erts_pix2proc(i);
	if (rp && rp->i != ENULL) {
	    int br;
	    print_process_info(ERTS_PRINT_STDOUT, NULL, rp);
	    erts_printf("(k)ill (n)ext (r)eturn:\n");
	    while(1) {
		if ((j = sys_get_key(0)) <= 0)
		    erts_exit(0, "");
		switch(j) {
		case 'k': {
		    ErtsProcLocks rp_locks = ERTS_PROC_LOCKS_XSIG_SEND;
		    erts_aint32_t state;
		    erts_proc_inc_refc(rp);
		    erts_smp_proc_lock(rp, rp_locks);
		    state = erts_smp_atomic32_read_acqb(&rp->state);
		    if (state & (ERTS_PSFLG_FREE
				 | ERTS_PSFLG_EXITING
				 | ERTS_PSFLG_ACTIVE
				 | ERTS_PSFLG_ACTIVE_SYS
				 | ERTS_PSFLG_IN_RUNQ
				 | ERTS_PSFLG_RUNNING
				 | ERTS_PSFLG_RUNNING_SYS
				 | ERTS_PSFLG_DIRTY_RUNNING
				 | ERTS_PSFLG_DIRTY_RUNNING_SYS)) {
			erts_printf("Can only kill WAITING processes this way\n");
		    }
		    else {
			(void) erts_send_exit_signal(NULL,
						     NIL,
						     rp,
						     &rp_locks,
						     am_kill,
						     NIL,
						     NULL,
						     0);
		    }
		    erts_smp_proc_unlock(rp, rp_locks);
		    erts_proc_dec_refc(rp);
		}
		case 'n': br = 1; break;
		case 'r': return;
		default: return;
		}
		if (br == 1) break;
	    }
	}
    }
}
Пример #3
0
void
process_info(int to, void *to_arg)
{
    int i;
    for (i = 0; i < erts_max_processes; i++) {
	Process *p = erts_pix2proc(i);
	if (p && p->i != ENULL) {
	    if (!ERTS_PROC_IS_EXITING(p))
		print_process_info(to, to_arg, p);
	}
    }

    port_info(to, to_arg);
}
Пример #4
0
long test_syscall(long size, long *num_filled){
	struct process_info *info_array = NULL;

	if (size > 0){
		info_array = malloc(sizeof(struct process_info)*size);
	}
	long ret = syscall(_PROCESS_ANCESTORS_, info_array, size, num_filled);
	printf("size=%ld, num_filled=%ld, ret=%ld\n", size, *num_filled, ret);
	if (info_array != NULL){
		print_process_info(info_array, *num_filled);
		free(info_array);
	}
	printf("\n");

	return ret;
}
Пример #5
0
void
process_info(int to, void *to_arg)
{
    int i, max = erts_ptab_max(&erts_proc);
    for (i = 0; i < max; i++) {
	Process *p = erts_pix2proc(i);
	if (p && p->i != ENULL) {
	    /* Do not include processes with no heap,
	     * they are most likely just created and has invalid data
	     */
	    if (!ERTS_PROC_IS_EXITING(p) && p->heap != NULL)
		print_process_info(to, to_arg, p);
	}
    }

    port_info(to, to_arg);
}
Пример #6
0
int main(int argc, const char* argv[])
{
    int status, bg_pipes[2], num_pipes, flags;
    struct sigaction act_bg_term, act_int_old, act_int_new;
    /* Define handler for SIGINT (ignore) */
    act_int_new.sa_handler = SIG_IGN;
    act_int_new.sa_flags = 0;
    if (sigaction(SIGINT, &act_int_new, &act_int_old))
        perror("Failed to change handler for SIGINT");

    /* Define handler for detecting background process termination */
    if (SIGNAL_DETECTION == 1)
    {
        if (sigaction(SIGUSR1, NULL, &act_bg_term))
            perror("Failed to get handler for SIGUSR1");
        act_bg_term.sa_handler = sig_bg_handler;
        act_bg_term.sa_flags = SA_RESTART;
        if (sigaction(SIGUSR1, &act_bg_term, NULL))
            perror("Failed to set handler for SIGUSR1");
    }

    /* Create pipe for printing background process info */
    num_pipes = 1;
    create_pipes(bg_pipes, num_pipes);

    /* Configure pipe to be non-blocking on read end */
    flags = fcntl(bg_pipes[0], F_GETFL, 0);
    fcntl(bg_pipes[0], F_SETFL, flags | O_NONBLOCK);

    while (1)
    {
        char input[80], cmd[80];
        int i;

        /* Wait for all defunct children */
        /* Continue even if no child has exited */
        if (!(SIGNAL_DETECTION == 1))
            while (waitpid(-1, &status, WNOHANG | WUNTRACED) > 0);

        /* Print prompt */
        if (!print_prompt()) continue;

        /* Exit if error occurs */
        if (!fgets(input, 80, stdin))
        {
            perror("Failed to get input");
            continue;
        }

        /* Remove newline, if present */
        i = strlen(input) - 1;
        if (input[i] == '\n') input[i] = '\0';

        /* Read given commands */
        i = 0; /* Input index */
        i = read_cmd(cmd, input, i);

        if (strcmp(cmd, "exit") == 0)
            break;
        else if (strcmp(cmd, "cd") == 0)
            cd(input, cmd, i);
        else if (strcmp(cmd, "checkEnv") == 0)
            check_env(input, i);
        else if (cmd[0] == '\0') {} /* Just print process info */
        else
            general_cmd(input, &act_int_old, bg_pipes);

        /* Print accumulated process information */
        print_process_info(bg_pipes);
    }

    /* Close pipe for printing background process info */
    close_pipes(bg_pipes, num_pipes);

    exit_shell();

    return 0;
}
Пример #7
0
void *consumer_function(void *arg){
    int cpu_num = (int) arg;
    consumer_t *cpu = &cpus[cpu_num];
    cpu_queue_t *cpu_queue;
    process_info_t task;
    long start_time, end_time;
    int execution_time;
    int sleep_avg;


    printf("Hi i'm the consumer %d\n", cpu_num);
    while(!thread_finished || cpu->size !=0){
        //CRITICAL SECTION
        pthread_mutex_lock(&cpu->mutex);
        if (cpu->ready_queue[0].size > 0) {
            cpu_queue = &cpu->ready_queue[0];
            task = cpu_queue->queue[cpu_queue->head];
            cpu_queue->head = (cpu_queue->head + 1) % Q_CAPACITY;
            cpu_queue->size--;
        } else if (cpu->ready_queue[1].size > 0) {
            task = get_max_priority(&cpu->ready_queue[1]);
        } else if (cpu->ready_queue[2].size > 0) {
            task = get_max_priority(&cpu->ready_queue[2]);
        } else {
            pthread_mutex_unlock(&cpu->mutex);
            sleep(1);
            continue;
        }
        
        cpu->size--;
        
        pthread_mutex_unlock(&cpu->mutex);
        
        if (task.scheduling_type == NORM) {
            start_time = time_in_millis();
            sleep_avg = (start_time - task.last_execution) / 200;
            task.sleep_avg = min(10, sleep_avg + task.sleep_avg);
        }
        
        if (task.scheduling_type == FIFO)
            execution_time = task.expected_execution_time;
        else
            execution_time = min(quantum(task.static_priority), task.expected_execution_time - task.accumulated_execution_time);
        
        int io_operation = task.scheduling_type == RR && rand() % 2;
        
        if  (io_operation) execution_time = 10; // I/O Wait
        
        start_time = time_in_millis();
        usleep(execution_time * 1000);
        end_time = time_in_millis();
        task.accumulated_execution_time += end_time - start_time;
        
        printf("The following process was selected by cpu: %d to run for %dms\n", cpu_num, execution_time);
        print_process_info(task);
        
        if (io_operation) {
            printf("I/O Operation In Progress for process %d\n", task.pid);
            usleep(1200 * 1000); // I/O Wait
        }
        
        sleep(1); // Prevents rediculous output speeds.
        
        task.last_cpu = cpu_num;

        if (task.accumulated_execution_time < task.expected_execution_time) {
            
            if (task.scheduling_type == NORM) {
                printf("Process %d updated the dynamic priority from %d to ", task.pid, task.dynamic_priority);
                sleep_avg = (end_time - start_time) / 200;
                task.sleep_avg = max(0, task.sleep_avg - sleep_avg);
                task.dynamic_priority = max(100, min(139, task.dynamic_priority - task.sleep_avg + 5));
                printf("%d.\n", task.dynamic_priority);
            }

            //CRITICAL SECTION
            pthread_mutex_lock(&cpu->mutex);

            if (task.dynamic_priority < 100)
                cpu_queue = &cpu->ready_queue[0];
            else if (task.dynamic_priority < 130)
                cpu_queue = &cpu->ready_queue[1];
            else
                cpu_queue = &cpu->ready_queue[2];

            cpu_queue->queue[cpu_queue->tail] = task;
            cpu_queue->tail = (cpu_queue->tail + 1) % Q_CAPACITY;
            cpu_queue-> size++;
            cpu->size++;

            pthread_mutex_unlock(&cpu->mutex);
            continue;
        }
        printf("CPU %d finished process %d in %d ms\n",
               cpu_num,
               task.pid,
               task.accumulated_execution_time);
    }

    thread_finished += 1;
    printf("CPU %d Exiting\n", cpu_num);
    pthread_exit(NULL);
}