•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 425,895 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,907 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 473 | Replies: 0
![]() |
•
•
Join Date: Nov 2007
Posts: 79
Reputation:
Rep Power: 1
Solved Threads: 0
i am trying to synchronize between father process and son process
created by fork() command, to print simultaneously.
my program is written in c under bash shell.
the compile goes ok but when i try to run nothing happens and the program doesnot end.
my code is:
is there any other way to synchronize father and son process ?
created by fork() command, to print simultaneously.
my program is written in c under bash shell.
the compile goes ok but when i try to run nothing happens and the program doesnot end.
my code is:
#include <stdio.h>
#include <semaphore.h>
#include <stdlib.h>
main() {
sem_t s1;
sem_t s2;
int value1 , value2;
sem_init(&s1, 0, 1);
sem_init(&s2,0,1);
sem_wait(&s2);
int pid = fork();
if (pid != 0)
{
int i;
for (i=0 ; i<=10 ; i++)
{
sem_getvalue (&s1,&value1);
while (value1 != 1)
sem_getvalue (&s1,&value1);
sem_wait(&s1);
if (i%2 != 0)
printf("%d\n",i);
sem_post(&s2);
}
}
if (pid == 0)
{
int j;
for (j=0 ; j<=10 ; j++)
{
sem_getvalue (&s2,&value2);
while (value2 != 1)
sem_getvalue (&s2,&value2);
sem_wait(&s2);
if (j%2 == 0)
printf("%d\n",j);
sem_post(&s1);
}
exit(0);
}
return 0;
}is there any other way to synchronize father and son process ?
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- What kind of processes uses the code? (*nix Software)
- memory management in wndows 2000 (Windows NT / 2000 / XP / 2003)
- High cpu in win explorer, task mng - HJ Log (Viruses, Spyware and other Nasties)
- Cannot change msn default home page (Network Security)
- start menu, desktop, and internet explorer not working (Viruses, Spyware and other Nasties)
- Search Extender (Viruses, Spyware and other Nasties)
- Help for semaphores programming project .. (C)
Other Threads in the Shell Scripting Forum
- Previous Thread: Shell Script
- Next Thread: Script to run command on another server


Linear Mode