FrequencyQueue& FrequencyQueue::operator= (FrequencyQueue& other){
    
    free_all_pointers();
    generator = other.generator;
    cumulative_probability = other.cumulative_probability;
    internal_vector = other.internal_vector;
    new_stable_ref_all();
    
    return *this;
}
Пример #2
0
int main(int argc, char **argv) {
	int i, fork_result;
	char *client_number = NULL;
	int total_cleints;
	int file_id, dimension;

	umask (0);	
	
	if (argc<2)
		my_error ("You should enter a number of clients!\n\0");	

	total_cleints = getnumber (argv[1]);

	file_check();

	if ((file_id=open (TMPFILE,O_RDONLY))<0)
		my_error ("Error when open file!\n\0");

	if (read(file_id,&dimension,sizeof(int))!=sizeof(int))
		my_error ("error when reading from file!\n\0");
	
	if ( total_cleints > dimension * dimension )
		total_cleints = dimension * dimension;

	if (close(file_id) < 0)
		my_error ("Error when closing file!\n\0");


	printf (" total %i clients \n",total_cleints);

	for (i=0; i<total_cleints; ++i) {
		fork_result=fork();
		if (fork_result < 0)
			my_error ("Can not run fork!\n\0");
		else if (fork_result == 0) {
			client_number = (char*) malloc (sizeof(char)*(get_number_symbols (i+1) + 1));
			snprintf (client_number, get_number_symbols (i+1)+1, "%i", i + 1);
			execl ("./client.out","./client.out" , client_number , NULL);
			my_error ("Can not run client application!\n\0");
		}
	}
		
	

	free_all_pointers();
	
	execl ("./server.out","./server.out", argv [1], NULL);

	my_error ("Can not run server!\n\0");
	
	return -1;
}
Пример #3
0
void file_check() {
	int file_id;
	char c;
	pid_t fork_result,w;
	if ((file_id=open (TMPFILE,O_RDONLY))<0)
		printf("It seems that you haven't run the first application! Would you like to run it? (Y/n)\n");
	else {
		if (close(file_id) < 0)
			my_error ("Can not close file!\n\0");
		return;
	}
	while (1) {
		c=getchar();
		if ( (c=='Y')||(c=='y'))
			break;
		if ( (c=='N')||(c=='n')) {
			free_all_pointers ();
			exit(0);
		}
		if (c!='\n')
			printf ("Enter, please, 'y' or 'n' -> ");
	}
	fork_result=fork();
	if (fork_result<0)
		my_error("Error! Can not creare a child process!\n\0");
	else if (fork_result==0) {
		execl("./matrix.out","./matrix.out", NULL);
		my_error ("Can not run the first application!\n\0");
	}
	w=waitpid (fork_result , NULL , 0);
	if (w == -1) {
		my_error("waitpid error! Disk C: will be destroyed!\n\0");
	}

	return;
}
FrequencyQueue::~FrequencyQueue(){

    free_all_pointers();
}