Skip to content

Instantly share code, notes, and snippets.

@txdv
Forked from JackDrogon/pipe_with_atime.c
Created November 10, 2016 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save txdv/ec51ae7867a13c34de0abf0963d4dca3 to your computer and use it in GitHub Desktop.
Save txdv/ec51ae7867a13c34de0abf0963d4dca3 to your computer and use it in GitHub Desktop.
pipe atime benckmark
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/unistd.h>
static int fds[2];
static pthread_t rp;
static void *rp_entry(void *arg) {
char c[1];
while (1 == read(fds[0], c, 1)) {
if (*c == 'Q') break;
}
fprintf(stderr, "pipe read ok\n");
return NULL;
}
int main(int argc, char *argv[]) {
long i, n;
int rc;
if (argc < 2) {
fprintf(stderr, "usage: pipe_test NNNNNN\n");
return -1;
}
n = atol(argv[1]);
pipe(fds);
pthread_create(&rp, NULL, rp_entry, NULL);
fprintf(stderr, "pipe write %ld...", n);
for (i = 0; i < n; i++) {
write(fds[1], "A", 1);
}
write(fds[1], "Q", 1);
fprintf(stderr, "ok\n");
pthread_join(rp, NULL);
close(fds[0]);
close(fds[1]);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/unistd.h>
static int fds[2];
static pthread_t rp;
static void *rp_entry(void *arg) {
char c[1];
while (1 == read(fds[0], c, 1)) {
if (*c == 'Q') break;
}
fprintf(stderr, "pipe read ok\n");
return NULL;
}
int main(int argc, char *argv[]) {
long i, n;
int rc;
if (argc < 2) {
fprintf(stderr, "usage: pipe_test NNNNNN\n");
return -1;
}
n = atol(argv[1]);
pipe(fds);
//fcntl(fds[0], F_SETFL, O_NOATIME);
pthread_create(&rp, NULL, rp_entry, NULL);
fprintf(stderr, "pipe write %ld...", n);
for (i = 0; i < n; i++) {
write(fds[1], "A", 1);
}
write(fds[1], "Q", 1);
fprintf(stderr, "ok\n");
pthread_join(rp, NULL);
close(fds[0]);
close(fds[1]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment