Concurrent and Sequential process
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Concurrent and Sequential process




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Concurrent and Sequential process  
Bhavin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-26-07 12:20 AM

HI,
I have to implement a program using exec command to illustrate
concurrent and sequential process. What I did is just create two input
file

Alpha.txt
========
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
.  .  .
abcdefghijklmnopqrstuvwxyz (upto 50 lines)

Number.txt
========
1234567890
1234567890
1234567890
. .  .
1234567890 ( upto 50 lines)

my code is
========
#include <sys/types.h>
#include<unistd.h>
#include<iostream>

using namespace std;

int pid1,pid2;

int main ()
{

pid1 = fork();  //first child process

if (pid1<0){

perror("error");

}

if (pid1 ==0)
{

execl("/bin/cat","cat","Alpha.txt",NULL);

}
//parent process

if (pid1>0) {

}

pid2 =fork();       //second child process

if (pid2==0){

execl("/bin/cat", "cat","Number.txt",NULL);
}

if (pid2>0){

}
}

output ( I want output in this manner)
===========================
For Concurrent process:-

abcdefghijklmnopqrstuvwxyz
1234567890
abcdefghijklmnopqrstuvwxyz
1234567890
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
1234567890
.................... ( this its goes one)

but i am getting all the alphabets first then number( they are not
overlapping which it should happened  in concurrent)

For Sequential process :

I want all alphabets then number

please help me, Thanks in advance






[ Post a follow-up to this message ]



    Re: Concurrent and Sequential process  
Ben Bacarisse


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-26-07 12:20 AM

Bhavin <v2desperado@gmail.com> writes:

> HI,
>      I have to implement a program using exec command to illustrate
> concurrent and sequential process. What I did is just create two input
> file
>
> Alpha.txt
> ========
> abcdefghijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
>           .  .  .
> abcdefghijklmnopqrstuvwxyz (upto 50 lines)
>
> Number.txt
> ========
> 1234567890
> 1234567890
> 1234567890
>      . .  .
> 1234567890 ( upto 50 lines)
>
> my code is
> ========
> #include <sys/types.h>
> #include<unistd.h>
> #include<iostream>
<snip program that forks and runs two copies of "cat">
> output ( I want output in this manner)
> ===========================
> For Concurrent process:-
>
> abcdefghijklmnopqrstuvwxyz
> 1234567890
> abcdefghijklmnopqrstuvwxyz
> 1234567890
> abcdefghijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
> 1234567890
>  ..................... ( this its goes one)
>
> but i am getting all the alphabets first then number( they are not
> overlapping which it should happened  in concurrent)

Ah, but that is allowed.  Concurrent does not mean "as interleaved as
I want but no more" but simply that both run eventually.

Try using a longer-running program and see what happens.  The command
"yes" can be useful here, but you should be ready to kill the
child processes by hand since "yes" never stops.

--
Ben.





[ Post a follow-up to this message ]



    Re: Concurrent and Sequential process  
fjblurt@yahoo.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-26-07 12:20 AM

On Sep 25, 2:57 pm, Bhavin <v2desper...@gmail.com> wrote:
> HI,
>      I have to implement a program using exec command to illustrate
> concurrent and sequential process. What I did is just create two input
> file
>
> Alpha.txt
> ========
> abcdefghijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
>           .  .  .
> abcdefghijklmnopqrstuvwxyz (upto 50 lines)
>
> Number.txt
> ========
> 1234567890
> 1234567890
> 1234567890
>      . .  .
> 1234567890 ( upto 50 lines)
>
> my code is
> ========
> #include <sys/types.h>
> #include<unistd.h>
> #include<iostream>
>
> using namespace std;
>
> int pid1,pid2;
>
> int main ()
> {
>
>         pid1 = fork();  //first child process
>
> if (pid1<0){
>
>         perror("error");
>
> }
>
> if (pid1 ==0)
>         {
>
>              execl("/bin/cat","cat","Alpha.txt",NULL);
>
>         }
> //parent process
>
> if (pid1>0) {
>
>         }
>
> pid2 =fork();       //second child process
>
> if (pid2==0){
>
>          execl("/bin/cat", "cat","Number.txt",NULL);
>         }
>
> if (pid2>0){
>
> }
> }
>
> output ( I want output in this manner)
> ===========================
> For Concurrent process:-
>
> abcdefghijklmnopqrstuvwxyz
> 1234567890
> abcdefghijklmnopqrstuvwxyz
> 1234567890
> abcdefghijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
> 1234567890
>  ..................... ( this its goes one)
>
> but i am getting all the alphabets first then number( they are not
> overlapping which it should happened  in concurrent)

That would only happen if your system were very slow.  Most likely it
is fast enough that 'cat Alpha.txt' completes in its first timeslice,
before one is given to the other process.

If you make Alpha.txt and Number.txt really large, you will probably
see them interlaced (say 10000 lines of Alpha then 10000 lines of
Number).

If it were important that they alternate lines, you'd have to use your
own program instead of cat, which would write a line and then
communicate with the other process to agree on who should go next.

> For Sequential process :
>
> I want all alphabets then number

man waitpid






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:00 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register