1° Trabalho
Erik Tronkos
Pedro Boueke
UFRJ - 2016.04.28
$ ./handler
Running...
Running...
Running...
Caught signal 4
Running...
Running...
Running...
Caught signal 1
Process finished with exit code 1
$ ./raiser 4 10527
Sent signal 4 to process 10527
Process finished with exit code 0
$ ./raiser 1 10527
Sent signal 1 to process 4
Process finished with exit code 0
int pd[2];
pipe(pd);
void producer(int iterations, int file)
FILE *pipe_wr_end = fdopen(file, "w");
product += rand() % 100;
string pd = to_string(product) + " ";
sent = fprintf(pipe_wr_end, "%s", pd.c_str());
fprintf(pipe_wr_end, "%d", 0);
void consumer(int file)
fscanf(pipe_rd_end, "%c", &cnumber);
fclose(pipe_rd_end);
FILE *pipe_rd_end = fdopen(file, "r");
Product sent[3]: 83
Product sent[4]: 169
Product sent[4]: 246
Product sent[4]: 261
Product sent[4]: 354
Product sent[4]: 389
Product sent[4]: 475
Product sent[4]: 567
Product sent[4]: 616
Product sent[4]: 637
Consumer got 83, which is prime.
Consumer got 169, which isn't prime.
Consumer got 246, which isn't prime.
Consumer got 261, which isn't prime.
Consumer got 354, which isn't prime.
Consumer got 389, which is prime.
Consumer got 475, which isn't prime.
Consumer got 567, which isn't prime.
Consumer got 616, which isn't prime.
Consumer got 637, which isn't prime.
Terminating consumption.
Process finished with exit code 0
socket(family, socktype,protocol)
sockfd = socket(family, socktype,protocol)
listen(sockfd, BACKLOG)
new_fd = accept(sockfd, &their_addr, &sin_size);
send(new_fd, prod, strlen(prod), 0)
recv(new_fd, buf, MAXDATASIZE - 1, 0)
sockfd = socket(family, socktype,protocol)
connect(sockfd, p->ai_addr, p->ai_addrlen)
send(sockfd, sendmsg, strlen(sendmsg), 0)
recv(sockfd, buf, MAXDATASIZE - 1, 0)
if (isPrime(atoi(buf))
$ ./server 10
Server: waiting for connections...
Server: got connection from 127.0.0.1
Server: received 'Hello There!'
Server: sent '183'
Server: received '183 isn't prime.'
...
Server: sent '667'
Server: received '667 isn't prime.'
Server: sent '716'
Server: received '716 isn't prime.'
...
$ ./client 0
client: connecting to 0.0.0.0
client: received '183', which isn't prime.
...
client: received '667', which isn't prime.
client: received '716', which isn't prime.
client: received '737', which isn't prime.
client: received '0',
Terminating consumption.
Process finished with exit code 0