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
ZIMPL(1)							   User Manuals 							  ZIMPL(1)

NAME
zimpl - Zuse Institute Mathematical Programming Language SYNOPSIS
zimpl [ -b ] [ -D name=value ] [ -f ] [ -F filter ] [ -h ] [ -m ] [ -l length [ -n cm|cn|cf ] [ -o outfile ] [ -O ] [ -P filter [ -r ] [ -t lp|mps|hum|rlp|pip ] [ -s seed ] [ -v 0-5 ] [ -V ] file ... DESCRIPTION
Zimpl is a little language to translate the mathematical model of a problem into a linear or (mixed-)integer mathematical program expressed in LPF or MPS file format which can be read by a LP or MIP solver. None of the options is necessary. All input files in zpl format that are given are concatenated and processed as if they are one big file. This makes is possible to combine different parts of a model on the command line. In this case the first filename given will be used as basename for the output files in absence of an -o option. The -t option is to select the output format. mps can be read by every solver. lpf is an CPLEX format, but can also read by several solvers. BE aware that for example Range-rows can not be expressed in lpf . If you want to inspected the output yourself, hum format is a variant of lpf with no name mangeling whatever, but unfortunately this violates several format restrictions, so no solver will read this in. If rlp is specified the output is in lpf format, but rows and columns are randomly permuted. OPTIONS
-b Enable bison(1) debugging output. -D name=value Sets the parameter name to the specified value. This is equivalent with having this line in the Zimpl program: param name:=val . -f Enable flex(1) debugging output. -F filter The output is piped through a filter. A %s in the string is replaced by the output filename. For example: -F "gzip -c >%s.gz" would compress all the output files. -h Show program help. -l length Sets the maximum length for variable names in LPF output files. -m Write a CPLEX .mst Mip STart file. -n cm|cn|cf Select the format for the generation of constraint names. Can be either cm which will number them 1 ... n with a `c' in front. cn will use the name supplied in the subto statement and number them 1 ... n within the statement. cf will use the name given with the subto, then a 1 .. n number like in cm and then append all the local variables from the forall statements. -o outfile Sets the base-name for the output files. Default is the name of the input file without extension. -O Optimize the generated LP by doing some presolve analysis (experimental). -P filter The input is piped through a filter. A %s in the string is replaced by the input filename. For example: -F "cpp -DWITH_C1 %s" would pass the input file through the C-preprocessor. -r Write a CPLEX .ord branching order file. -s seed Set the random number generator seed. -t lp|mps|hum|rlp|pip Selects the output format. Can be either lp which is default, or mps , or hum , which is (only) human readable, or rlp , which is randomly permuted, or pip , which means polynimial IP. -v 0-5 Set the verbosity level. 0 is quiet, 1 is default, 2 is verbose, 3 is chatter, and 5 is debug. -V Prints the version number. DIAGNOSTICS
The following diagnostics may be issued on stderr: 101 Bad filename The name given with the -o option is either missing, a directory name, or starts with a dot. 175 Illegal syntax for command line define -- ignored The parameter of a -D option was either not of the form name=value or the name was not a legal identifier. There are about a hundred other possible error messages, but these are either about the contend of the input file, or system messages. BUGS
Please report any bug to the author. AUTHOR
Thorsten Koch <koch@zib.de> WEBSITE
The lastest version of Zimpl is always available at <http://zimpl.zib.de>. SEE ALSO
The Zimpl User Guide at <http://zimpl.zib.de/download/zimpl.pdf>. Linux 30 September 2010 ZIMPL(1)
All times are GMT -4. The time now is 01:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy