TA043

Sistemas Operativos (TA043)
Index Commits Files Refs
commit 78cbf06c722bf4d69421f93000d8a7bfc4840bdf
parent ffa409a0ef74af351a39ece7b68eea418e4eba6c
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Fri, 21 Aug 2026 22:02:27 -0300

Fix sizeof write syscall

Diffstat:
Mpract/process_pingpong.c | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/pract/process_pingpong.c b/pract/process_pingpong.c
@@ -16,6 +16,7 @@
 #define LOG_ENABLE     true
 #define PIPE_READ_END  0
 #define PIPE_WRITE_END 1
+#define DELAY_MS       100
 
 #if true == LOG_ENABLE
 #define LOG(fmt, ...) do {                  \
@@ -72,7 +73,7 @@ int main (void)
         // Child
         proc_count++;
         LOG_ID("PID is %jd", (intmax_t) getpid());
-        sleep_ms(1000);
+        sleep_ms(DELAY_MS);
 
         if (close(pipefd_1[PIPE_WRITE_END]) == -1)
         {
@@ -91,15 +92,15 @@ int main (void)
         while (true)
         {
             // Wait for response from the other end
-            while (read(pipefd_1[PIPE_READ_END], &ball, 1) <= 0)
+            while (read(pipefd_1[PIPE_READ_END], &ball, sizeof(ball)) <= 0)
             {
                 ;
             }
-            sleep_ms(1000);
+            sleep_ms(DELAY_MS);
 
             ball++;
             LOG_ID("%d", ball);
-            write(pipefd_2[PIPE_WRITE_END], &ball, 1);
+            write(pipefd_2[PIPE_WRITE_END], &ball, sizeof(ball));
         }
 
         exit(EXIT_SUCCESS);
@@ -108,7 +109,7 @@ int main (void)
     {
         // Parent
         LOG_ID("PID is %jd", (intmax_t) getpid());
-        sleep_ms(1000);
+        sleep_ms(DELAY_MS);
 
         if (close(pipefd_1[PIPE_READ_END]) == -1)
         {
@@ -128,15 +129,15 @@ int main (void)
         {
             ball++;
             LOG_ID("%d", ball);
-            write(pipefd_1[PIPE_WRITE_END], &ball, 1);
+            write(pipefd_1[PIPE_WRITE_END], &ball, sizeof(ball));
 
             // Wait for response from the other end
-            while (read(pipefd_2[PIPE_READ_END], &ball, 1) <= 0)
+            while (read(pipefd_2[PIPE_READ_END], &ball, sizeof(ball)) <= 0)
             {
                 ;
             }
 
-            sleep_ms(1000);
+            sleep_ms(DELAY_MS);
         }
 
         exit(EXIT_SUCCESS);