Sponsored Content
Full Discussion: synchronize two processes
Top Forums Programming synchronize two processes Post 302208344 by ramen_noodle on Monday 23rd of June 2008 03:57:20 PM
Old 06-23-2008
Sure. I'm not sure what the original exercise is supposed to accomplish, but a simple pipe, with an ack/syn type system is workable.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <time.h>

#define BSZ 20
#define MGC 12

void do_msg_send(int []);

int main(void) {
int err;
int pip[2];
char bbuf[BSZ];
pid_t fng;

                       pipe(pip);
                       if ( (fng = fork()) == 0) {
                                                 do_msg_send(pip);
                       }
                       close(pip[1]);
                       while (1) {
                                 if (read(pip[0],bbuf,BSZ) > 0) {
                                     printf("Received packet from child %d = %s..Announcing availability of data.\n",fng,bbuf);
                                 }
                       }
}

void do_msg_send(int pip[]) {
int rseed;
char nbuf[BSZ];
time_t foo, now;

          
                        close(pip[0]);
                        now = foo = time(NULL);
                        foo += (int)(1 + rand() % MGC);
                        while (1) {
                              now = time(NULL);
                              if (now >= foo) {
                                 sprintf(nbuf,"%d",time(NULL));
                                 write(pip[1],nbuf,BSZ);
                                 foo += (int)(1 + rand() % MGC); 
                              }
                              sleep(1);
                       }
}

Example code.

Last edited by ramen_noodle; 06-23-2008 at 05:48 PM..
 

9 More Discussions You Might Find Interesting

1. Programming

synchronize as in java

Hi, I am trying to implement the synchronize feature of java using C. I am using a semaphore for the same. I have a wrapper called "synch" to which I pass the function pointer(any_fn). This pointer points to the function (my_fn) which needs to be synchronized. However to create the semaphore I... (8 Replies)
Discussion started by: linuxpenguin
8 Replies

2. Shell Programming and Scripting

How to synchronize all the linux machine?

Hi, I have three Linux machine have three different times. Can I synchronize them using one process? I have root access. Thanks! (1 Reply)
Discussion started by: whatisthis
1 Replies

3. Shell Programming and Scripting

how to synchronize different dirs

I have 4 directory Dir1 file1 file2 file3 file4 Dir2 file3 file5 file6 file8 Dir3 file1 file2 file6 file9 file10 Dir4 file3 file6 file12 file15 and all the 4 dirs are having couple of files. Few of the files are common to other directory/ies and few... (1 Reply)
Discussion started by: reldb
1 Replies

4. Programming

need a way to synchronize processes

I am writing a program in C for my networking class, so I am relatively new to this. To begin, I have 7 processes that need do send messages to every other one, and every one of them needs to receive the messages sent by others. I am using fork() to create 6 more processes. The message... (1 Reply)
Discussion started by: inabramova
1 Replies

5. UNIX for Advanced & Expert Users

synchronize processes

hi. i am writing a c program under bash shell. i would like to use semaphore functions like sem_wait(), sem_post() and i included <semaphore.h> and it compailes fine but when i try to run it gives me an error "undefined reference to sem_wait() , sem_post() , sem_init()" what have i missed... (2 Replies)
Discussion started by: emil2006
2 Replies

6. Shell Programming and Scripting

Synchronize Files-Help

Hi, I have two servers1&2, one is not in the network. Cant communicate from it to other servers. The second one can communicate to above mentioned server. I am trying a script which synchronizes files between server 1 an 2? server1: cant communicate to any other servers server2: can... (4 Replies)
Discussion started by: Tuxidow
4 Replies

7. Shell Programming and Scripting

How to synchronize using FTP

Hi everyone! I need to write a script that will synchronize two servers using FTP. So basically the script will get only the files that exist on the remote server that do not exist on the local server. Is there an option to do this when using mget? If not, is there a way to copy over only the... (2 Replies)
Discussion started by: Fatbob
2 Replies

8. AIX

Verify and Synchronize HACMP

Hi Earlier we used to move the resource groups between nodes manually. Recently I have added the HACMP startup and stop scripts. Then I moved the resource group to see if everything works fine as per the startup and stop scripts, but it didn't work out as expected. Do i need to do bring... (4 Replies)
Discussion started by: samsungsamsung
4 Replies

9. UNIX for Advanced & Expert Users

How to synchronize two different files?

Hello, I have the latest stable release of a UNIX-like O.S. in the ISO format, and want to synchronize it with the latest Release Candidate (RC) of it, in order to reducing bandwidth usage. The ISO images for that O.S. is provided via different protocols including rsync, FTP and HTTP Is this... (4 Replies)
Discussion started by: temp-usr
4 Replies
vsig(1F)							   FMLI Commands							  vsig(1F)

NAME
vsig - synchronize a co-process with the controlling FMLI application SYNOPSIS
vsig DESCRIPTION
The vsig executable sends a SIGUSR2 signal to the controlling FMLI process. This signal/alarm causes FMLI to execute the FMLI built-in command checkworld which causes all posted objects with a reread descriptor evaluating to TRUE to be reread. vsig takes no arguments. EXAMPLES
Example 1: A sample output of vsig command. The following is a segment of a shell program: echo "Sending this string to an FMLI process" vsig The vsig executable will flush the output buffer before it sends the SIGUSR2 signal to make sure the string is actually in the pipe created by the cocreate function. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ SEE ALSO
coproc(1F), kill(1), kill(2), signal(3C), attributes(5) NOTES
Because vsig synchronize with FMLI, it should be used rather than kill to send a SIGUSR2 signal to FMLI. SunOS 5.10 5 Jul 1990 vsig(1F)
All times are GMT -4. The time now is 01:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy