Problem regarding process

B

Bhavin

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
 
G

Guest

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


First of, you are off topic in this group since what you are using and
seeing are platform specific. Your problem is that your files are quite
small and the scheduler does not have time to make a process switch
before the fist cat has finished (I'm not sure but I think many
schedulers give new processes a bit of extra time). I think the best
solution would be to make the files much larger, 500 or 5000 lines and
redirect the output to a file (beware of file locking).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,296
Latest member
HeikeHolli

Latest Threads

Top