السلام عليكم ورحمة الله وبركاته
اخواني انا كتبت برنامج يقوم بانشاء معالجين:
الأول:يستخدم دالة open لانشاء ملف جديد
والثاني:يستخدم دالة write لكتابة رقم المعالج
والأب المفروض ينتظر عياله حتى يخلصون :P الدوام
لكن فيه بعض الأخطاء, ياريت المساعده و شرح بعض الاشياء كمان
وهذا الكود
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#define BUFFSIZE 1024
main ()
{
pid_t child1;
if ((child1= fork()) == 0)
{
while(((child1=wait(&status)) == -1) && (errno == EINTR)); /* I want each child to wait untill the other finish his job */
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
open( "abc", O_WRONLY | O_CREAT | O_TRUNC, mode); /* I want creat a file call abc in the home directory using 'open' system call, but I'm not sure about the bath if its wright or wrong */
}
else
{
wait(); /* I want to make the father wait until the first child finish his job*/
pid_t child2;
if ((child2= fork()) == 0)
{
int A;
A = (long)getpid(); /*I'll save the pid for this process to A*/
write(STDOUT_FILENO, &A, 10); /*I tried to print the pid to the screen using the 'write' system call*/
}
else
{
}
}وتحياتي للجميع
