Exemplo n.º 1
0
void init_unix()
{
    signal(SIGPIPE, SIG_IGN);
    prf_heap = allocate_rolling(pages, sstring("prf"));
    select_init();
    init_processes();
}
Exemplo n.º 2
0
/**
 * @brief: Handles all the initilization of the OS
 * @param: stack_start the start of free memory
 */
void init(void* memory_start) {

#ifdef INIT_DEBUG
    rtx_dbug_outs("Initilizating memory...");
#endif

    init_memory(memory_start);

#ifdef INIT_DEBUG
    rtx_dbug_outs("done\r\nInitilizating processes...");
#endif

    init_processes(memory_head);

#ifdef INIT_DEBUG
    rtx_dbug_outs(" done\r\nInitializing priority queues...");
#endif

    init_priority_queues();

#ifdef INIT_DEBUG
    rtx_dbug_outs(" done\r\nInitilizating interrupts...");
#endif

    init_interrupts();

    g_profiler.timer = &timer;

#ifdef INIT_DEBUG
    rtx_dbug_outs(" done\r\n");
#endif

}
Exemplo n.º 3
0
Arquivo: main.c Projeto: adnank/RTOS
int main()
{
	int i;
	printf("Starting.....!\n");



	time_initialize();

	initialize_table();
//	printf("Initialization Table created and initialised!\n");

	init_env();
	init_timeout_Q();
	init_blkOnRsc_Q();
	init_blkOnEnv_Q();
//	printf("All Queues and Envelope Queues Initialized!\n");
    init_TraceArrays();
    init_helperprocess();
	init_ioBuffers();
	init_signals();
    printf("Initializing Signals!\n");



	init_processes();
//	printf("Initialising Processes!\n");




//	printf("KBD and CRT Processes initialized and forked!\n");

	return 0;
}
Exemplo n.º 4
0
int main(void)
{
	status c_program;
	
	init_processes();
	ipc_open(endif_process->params, O_RDONLY);
	
	while(1)
		if (ipc_receive(endif_process->params, &c_program, sizeof(struct status)) > 0)
			run_process(&c_program, &execute_endif);
	return 0;
}
Exemplo n.º 5
0
int main(void)
{
	status c_program;
	
	init_processes(FALSE);
	
	signal(SIGINT, end_process);
	
	ipc_open(if_process->params, O_RDONLY);
	
	while(1)
		if (ipc_receive(if_process->params, &c_program, sizeof(struct status)) > 0)
			run_process(&c_program, &execute_if);
	return 0;
}
Exemplo n.º 6
0
int main(int argc, char ** argv){
	
	char * program_name;
	struct status cl_program;
	int i;
	ipc_params_t client_params;

	init_processes();

	if(argc > 1){
		program_name = argv[1];
	}else{
		printf("Entrada incorrecta\n");
		return 0;
	}

	client_params = get_params_from_pid(getpid(), PROGRAM_STATUS, sizeof(struct status));

	client_header_t header = calloc(1, sizeof(struct client_header));
	header->program_size = strlen(program_name);
	header->client_id = getpid();

	ipc_open(server_params, O_WRONLY);
	
	server_params->msg_type = PRE_HEADER;
	ipc_send(server_params, header, sizeof(struct client_header));
	
	server_params->msg_type = PROGRAM_STRING;
	ipc_send(server_params, program_name, header->program_size);
	
	ipc_close(server_params);
	
	ipc_create(client_params);
	ipc_open(client_params, O_RDONLY);
	while (!ipc_receive(client_params, &cl_program, sizeof(struct status)));
	ipc_close(client_params);
	ipc_destroy(client_params);
	
	for (i = 0; i < MEM_SIZE; i++){
		printf("%d ", cl_program.mem[i]);
	}
	printf("\n");

	return 0;
}
Exemplo n.º 7
0
int
main(void) 
{
	char * read_string;
	int aux_size;
	
	pthread_t thread_id, receive_thread_id;
	thread_status_t thread_info;
	
	signal(SIGINT, server_close);
	
	init_processes(TRUE);
	init();
	
	client_header_t header = calloc(1, sizeof(struct client_header));
	
	pthread_create(&receive_thread_id, NULL, &run_server_receive, NULL);
	
	printf("Running server...\n");
	
	while(1)
	{
		server_params->msg_type = PRE_HEADER;
		if(ipc_receive(server_params, header, sizeof (struct client_header)) > 0)
		{
			read_string = calloc(1, header->program_size);
			server_params->msg_type = PROGRAM_STRING;
			
			while(ipc_receive(server_params, read_string, header->program_size) == 0)
				sleep(1);
			printf("Received program from client: %d, program name: %s\n", 
										header->client_id, read_string);
			thread_info = calloc(1, sizeof(struct thread_status));
			thread_info->file = read_string;
			thread_info->client_id = header->client_id;
			pthread_create(&thread_id, NULL, &run_program, thread_info);
			pthread_join(thread_id, NULL);
			free(read_string);
			free(thread_info);
		}
		sleep(1);
	}
	return 0;
}
Exemplo n.º 8
0
int
main(void)
{
    char * read_string;
    int aux_size;

    pthread_t thread_id;
    thread_status_t thread_info;

    init_processes();
    init();

    client_header_t header = calloc(1, sizeof(struct client_header));

    printf("Running server...\n");

    while(1)
    {
        server_params->msg_type = PRE_HEADER;
        if(ipc_receive(server_params, header, sizeof (struct client_header)) > 0)
        {
            read_string = calloc(1, header->program_size);
            printf("%d %d\n", header->client_id, header->program_size);
            server_params->msg_type = PROGRAM_STRING;

            while(ipc_receive(server_params, read_string, header->program_size) == 0)
                sleep(1);
            printf("Recibi programa del cliente: %d, programa: %s\n",
                   header->client_id, read_string);
            thread_info = calloc(1, sizeof(struct thread_status));
            thread_info->file = read_string;
            thread_info->client_id = header->client_id;
            pthread_create(&thread_id, NULL, &run_program, thread_info);
        }
    }


    return 0;
}
Exemplo n.º 9
0
void init_workers(void)
{
	if (process_mode)
		init_processes();
}
Exemplo n.º 10
0
int main(int argc, char **argv)
{
    const double sim_time = 200; ///< Total simulation time
    static int show_usage = 0;   ///< Flag to indicate if it is necessary to show usage options
    static int pnum = 0;         ///< Number of processes in the system

    int event,             ///< Current event
        pid,               ///< ID of the process executing the event
        num_requests = 0,  ///< Total number of requests in the simulation (used as stop criterion)
        p0_time = 0,       ///< Time at which process 0 will request the critical region
        p1_time = 0,       ///< Time at which process 1 will request the critical region
        p2_time = 0;       ///< Time at which process 2 will request the critical region

    struct timeval tp;
    queue_item recvd_msg;

    print_header();

    if (argc < 3) {
        print_usage(argv[0]);
        exit(1);
    }

    // parse parameters
    int c;
    while (1) {
        static struct option long_options[] = {
            {"help",  no_argument, &show_usage, 1},
            {"nproc", required_argument, 0, 'n'},
            {"rc0",   required_argument, 0, 'p'},
            {"rc1",   required_argument, 0, 'q'},
            {"rc2",   required_argument, 0, 'r'},
            {0, 0, 0, 0}
        };
        /* getopt_long stores the option index here. */
        int option_index = 0;

        c = getopt_long(argc, argv, "n:p:q:r:", long_options, &option_index);

        /* Detect the end of the options. */
        if (c == -1) break;

        switch (c) {
            case 0:
                /* If this option set a flag, do nothing else now. */
                if (long_options[option_index].flag != 0)
                    break;
                printf ("option %s", long_options[option_index].name);
                if (optarg)
                    printf (" with arg %s", optarg);
                printf ("\n");
                break;
            case 'n':
                pnum = (int) strtol(optarg, NULL, 10);
                break;
            case 'p':
                p0_time = (int) strtol(optarg, NULL, 10);
                ++num_requests;
                break;
            case 'q':
                p1_time = (int) strtol(optarg, NULL, 10);
                ++num_requests;
                break;
            case 'r':
                p2_time = (int) strtol(optarg, NULL, 10);
                ++num_requests;
                break;
            case '?':
                /* getopt_long already printed an error message. */
                break;
            default:
                abort();
        }
    }

    if (show_usage) {
        print_usage(argv[0]);
        exit(0);
    }

    if (pnum < 2) {
        printf("Error: Invalid number of processes! Please, specify at least 2 processes using the --nproc option.\n\n");
        print_usage(argv[0]);
        exit(1);
    } else if (pnum < 2 && p2_time != 0) {
        printf("Error: You have specified a time for process 2 (starting from 0) on a simulation with only 2 processes!\n\n");
        print_usage(argv[0]);
        exit(1);
    } else if (p0_time == 0 && p1_time == 0 && p2_time == 0) {
        printf("You have not specified any critical region requests in your simulation!\n\n");
        print_usage(argv[0]);
        exit(1);
    }

    // initialize PRNG
    gettimeofday(&tp, NULL);
    srand(tp.tv_sec + tp.tv_usec / 1000);
    seed(tp.tv_sec + tp.tv_usec / 1000, 1);

    smpl(0, "Ricart-Agrawala");
    stream(1);

    process plist = init_processes(pnum);

    printf("-- BEGIN PARAMETERS --\n");
    printf("Number of processes: %d\n", pnum);
    printf("Number of critical region requests: %d\n", num_requests);
    printf("Starting events:\n");
    if (p0_time != 0) {
        printf("  - Process 0 will request the critical region at time %d\n", p0_time);
        schedule(EV_REQUEST, p0_time, 0);
    }
    if (p1_time != 0) {
        printf("  - Process 1 will request the critical region at time %d\n", p1_time);
        schedule(EV_REQUEST, p1_time, 1);
    }
    if (p2_time != 0) {
        printf("  - Process 2 will request the critical region at time %d\n", p2_time);
        schedule(EV_REQUEST, p2_time, 2);
    }
    printf("-- END PARAMETERS --\n\n");

    printf("-- SIMULATION BEGIN --\n");
    while(time() < sim_time) {
        cause(&event, &pid);
        switch(event) {
            case EV_REQUEST:
                printf("Process %d has executed a critical region REQUEST at time %g\n", pid, time());
                plist[pid].state = ST_WANTED;
                // update pid's logical clock
                plist[pid].timestamp++;
                plist[pid].request_timestamp = plist[pid].timestamp;
                // broadcast REQUEST to all processes in the system
                broadcast(plist, pnum, pid);
                break;

            case EV_RECV:
                // remove next message to be received by pid
                recvd_msg = remove_max_pqueue(plist[pid].recvd_from);
                // synchronize pid's logical clock on receive before processing the message
                plist[pid].timestamp = (plist[pid].timestamp > recvd_msg->timestamp) ?
                    plist[pid].timestamp : recvd_msg->timestamp;
                plist[pid].timestamp++;

                printf("Process %d received %s from %d at time %g\n", pid, (recvd_msg->type == MSG_REQUEST) ? "REQUEST" : "REPLY", recvd_msg->pid, time());

                recv(plist, pnum, pid, recvd_msg->pid, recvd_msg->timestamp, recvd_msg->type);

                free(recvd_msg);
                break;
            case EV_RELEASE:
                printf("Process %d released the critical region at time %g\n", pid, time());

                releasecr(plist, pnum, pid);
                num_requests--;
                break;
        }

        // no more requests to simulate, simulation ended
        if (num_requests == 0) break;
    }
    printf("-- SIMULATION END --\n");

    destroy_processes(plist, pnum);

    return 0;
}
Exemplo n.º 11
0
int main ( int argc, char *argv[] )
{
    int s;
    struct epoll_event *events;

    signal ( SIGABRT, &sighandler );
    signal ( SIGTERM, &sighandler );
    signal ( SIGINT, &sighandler );

    if ( argc != 3 )
    {
        fprintf ( stderr, "Usage: %s [port] [doc root]\n", argv[0] );
        exit ( EXIT_FAILURE );
    }

    init_processes();

    listen_sock = create_and_bind ( argv[1] );
    doc_root = argv[2];
    if ( listen_sock == -1 )
        abort ();

    s = setNonblocking ( listen_sock );
    if ( s == -1 )
        abort ();

    s = listen ( listen_sock, SOMAXCONN );
    if ( s == -1 )
    {
        perror ( "listen" );
        abort ();
    }

    efd = epoll_create1 ( 0 );
    if ( efd == -1 )
    {
        perror ( "epoll_create" );
        abort ();
    }

    event.data.fd = listen_sock;
    event.events = EPOLLIN | EPOLLET;
    s = epoll_ctl ( efd, EPOLL_CTL_ADD, listen_sock, &event );
    if ( s == -1 )
    {
        perror ( "epoll_ctl" );
        abort ();
    }

    /* Buffer where events are returned */
    events = calloc ( MAXEVENTS, sizeof event );

    /* The event loop */
    while ( 1 )
    {
        int n, i;

        n = epoll_wait ( efd, events, MAXEVENTS, -1 );
        if ( n == -1 )
        {
            perror ( "epoll_wait" );
        }
        for ( i = 0; i < n; i++ )
        {
            if ( ( events[i].events & EPOLLERR ) ||
                    ( events[i].events & EPOLLHUP ) )
            {
                /* An error has occured on this fd, or the socket is not
                   ready for reading (why were we notified then?) */
                fprintf ( stderr, "epoll error\n" );
                close ( events[i].data.fd );
                continue;
            }

            handle_request ( events[i].data.fd );

        }
    }

    free ( events );

    close ( listen_sock );

    return EXIT_SUCCESS;
}