aboutsummaryrefslogtreecommitdiff
path: root/sync/writer.c
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2017-11-24 18:12:18 -0500
committerTucker Evans <tuckerevans24@gmail.com>2017-11-24 18:12:18 -0500
commit2177f0712fb47a95b2970c6838a4a4d978174b3b (patch)
treefe66e6a05d978e9fb91560d03774ee88c862db4c /sync/writer.c
parent0e15942312c9c20fcac5ac9f2368d94b80fda230 (diff)
CS3871/assignments/sync: Initial Commit
Diffstat (limited to 'sync/writer.c')
-rw-r--r--sync/writer.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/sync/writer.c b/sync/writer.c
new file mode 100644
index 0000000..0a7a1fe
--- /dev/null
+++ b/sync/writer.c
@@ -0,0 +1,51 @@
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <types.h>
+
+
+int main(argc, argv)
+int argc;
+char **argv;
+{
+ int shmid, i, pid, id;
+ char *mem;
+ timeval *s;
+
+ if (argc != 1) {
+ printf("usage: reader [id]\n");
+ exit(1);
+ }
+
+ id = atoi(argv[1]);
+
+ if (argc < 2) {
+ printf("usage: sync [number readers] [number writers]\n");
+ exit(1);
+ }
+
+ if ((shmid = shmget(52, 1<<14, IPC_CREAT | 0666)) == -1){
+ perror("shmget: shmget failed");
+ exit(1);
+ }
+
+ if ((mem = shmat(shmid, NULL, 0)) == (char *) -1) {
+ perror("shmat");
+ exit(1);
+ }
+
+ srand(time(NULL));
+
+
+ while (1) {
+ s->tv_sec = rand() % (id * 2;
+ for (i = 0; i < 1<<14; i++) {
+ mem[i]= 0x30 + id;
+ select(0, NULL, NULL, NULL, s);
+ }
+ }
+}