Question

A program where parent process counts number of vowels in the given sentence and child process...

A program where parent process counts number of vowels in the given sentence and child process will count number of words in the same sentence. The above programs should use system calls like fork and wait.

Homework Answers

Answer #1

Copyable Code:

#include<unistd.h>

#include<sys/types.h>

#include<stdio.h>

#include<stdlib.h>

fun_parent(char s[])

{

    int p,t_vowel;

    int a=0,e=0,i=0,o=0,u=0;

    for(p=0;s[p];p++)

    {

        switch(s[p])

        {

            case 'a':

            case 'A':a++;break;

            case 'e':

            case 'E':e++;break;

            case 'i':

            case 'I':i++;break;

            case 'o':

            case 'O':o++;break;

            case 'u':

            case 'U':u++;break;

        }

    }

    printf("\nTotal A or a = %d",a);

    printf("\nTotal E or e = %d",e);

    printf("\nTotal I or i = %d",i);

    printf("\nTotal O or o = %d",o);

    printf("\nTotal U or u = %d",u);

    t_vowel=a+e+i+o+u;

    printf("\nTotal noumber of vowels in the sentence = %d\n",t_vowel);

}

fun_child(char s[])

{

    int w=0,y=0,f=0;

    while(s[y]!='\0')

    {

        while(s[y]==' ' && s[y]!='\0')

        {

            y++;

        }

        while(s[y]!=' ' && s[y]!='\0')

        {

            y++;

            f=1;

        }

        if(f)

        {

            w++;

            f=0;

        }

    }

    printf("\nNumber of words in the sentence = %d\n",w);

}

int main()

{

    pid_t newPID;

    char s[100];

    printf("\nEnter sentence: ");

    gets(s);

    newPID = fork();

    if(newPID<0)

    {

        printf("\nError occured in process");

        exit(-1);

    }

    else if(newPID==0)

    {

        fun_child(s);

        exit(0);

    }

    else

    {

        execlp("a.out","vowelFork.c",fun_parent(s),NULL);

        sleep(10);

        wait();

        exit(0);

    }

    return 0;

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following program calls the fork() system call to create a child process. Suppose that the...
The following program calls the fork() system call to create a child process. Suppose that the actual pids of the parent process and child process are as follows: Parent process: 801 Child process:   802 (as returned by fork) Assume all supporting libraries have been included. => Use the answer text field to write the values of the pids printed at lines 1, 2, 3, and 4 (indicate each line number and the value printed). int main() {      pid_t pid,...
Program Assignment 1: Process Management Objective: This program assignment is given to the Operating Systems course...
Program Assignment 1: Process Management Objective: This program assignment is given to the Operating Systems course to allow the students to figure out how a single process (parent process) creates a child process and how they work on Unix/Linux(/Mac OS X/Windows) environment. Additionally, student should combine the code for describing inter-process communication into this assignment. Both parent and child processes interact with each other through shared memory-based communication scheme or message passing scheme. Environment: Unix/Linux environment (VM Linux or Triton...
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
Write a python program that will perform text analysis on an input text using all of...
Write a python program that will perform text analysis on an input text using all of the following steps: 1. Take the name of an input file as a command line argument. For example, your program might be called using python3 freq.py example1 to direct you to process a plain text file called example. More information is given on how to do this below. 2. Read the contents of the file into your program and divide the text into a...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
Write a java program that calculates the number of duplicate words in a sentence. You may...
Write a java program that calculates the number of duplicate words in a sentence. You may assume that the input consists only 52 English characters with a single white-space as the separator between words (not punctuations in the inputted sentence). You need consider uppercase and lowercase letters the same. You may get the input from the keyboard. (You need to use Set and/or Hashset). What I have so far import java.util.HashSet; import java.util.Scanner; public class Duplicate { int counter; int...
Write an ARM assembly language program that counts the number of 1’s for any value in...
Write an ARM assembly language program that counts the number of 1’s for any value in R0. The program must assemble/compile in KEIL and must be able to run in the KEIL simulator. Generally, R0 may contain any value, but for purpose of this exercise, you may move 0x2345ABCD into R0. The number in R0 does not need be preserved. You may use any other registers as you need. The result, total count of 1’s in R0, should be in...
Create a MIPS program where you ask a user for 10 digit base 28 number and...
Create a MIPS program where you ask a user for 10 digit base 28 number and output a decimal in mips programming. It should also ignore any character that is not in the base 28 system and count its value as 0. Example: Input: 100000xza! Output: 17210368 Input: xyzxyzxyzx Output:0 Input: 1000000000 Output: 17210368 Output: 10578455953408 Input: 0000000000 Output:0
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
/* This program should check if the given integer number is prime. Reminder, an integer number...
/* This program should check if the given integer number is prime. Reminder, an integer number greater than 1 is prime if it divisible only by itself and by 1. In other words a prime number divided by any other natural number (besides 1 and itself) will have a non-zero remainder. Your task: Write a method called checkPrime(n) that will take an integer greater than 1 as an input, and return true if that integer is prime; otherwise, it should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT