Posts Tagged ‘system software lab’

System Software Lab Programs ( UNIX Programs ) – 1B

// March 4th, 2009 // Comments // Engineering, Unix and System Software Lab

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

………………………………………………………………………………………………………………………….
PART -B

………………………………………………………………………………………………………………………….

1. b) C program that creates a child process to read commands from the standard input and execute them (a minimal implementation of a shell – like program). You can assume that no arguments will be passed to the commands to be executed.

……………………………………………………………………………………………………………………………

#include,stdio.h>

#include<unistd.h>

#include<string.h>

main()

{

int pid,n,i;

char cmd[30];

printf(“n Enter the number of commands : “);

scanf(“%d”,&n);

pid=fork();

system(“clear”);

if(!pid)

{

for(i=0;i<n;i++)

{

printf(“n Enter the command : “);

scanf(“%s”,cmd);

system(cmd);

}

}

else

{

wait(100);

exit(1);

}

printf(“n Parent process is completed..nn”);

return 0;

}

[Request : If you are going to post this program on any other website please link back to original post ]

System Software Lab Programs ( UNIX Programs )

// March 3rd, 2009 // Comments // Engineering, Unix and System Software Lab

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

………………………………………………………………………………………………………………………….
PART -B

………………………………………………………………………………………………………………………….

1. a) Non-recursive shell script that accepts any number of arguments and prints them in the Reverse order, ( for example, if the script is named rags, then executing rags A B C should produce C B A on the standard output).

……………………………………………………………………………………………………………………………

if [ $# -eq 0]

then

echo -e “No arguments”

else

a=($*)

echo -3 “Arguments are”

echo $*

let x=$#

echo -2 “Arguments in reverse order ”

while [ $x -ne -1]

do

echo -e “${a[$x]}”

let x=x-1

done

fi

[Request : If you are going to post this program on any other website please link back to original post ]

System Software Lab Programs ( Lex and Yaac Programs )exa

// February 21st, 2009 // Comments // Engineering, Unix and System Software Lab

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

………………………………………………………………………………………………………………………….
PART – A

………………………………………………………………………………………………………………………….

1 a) Lex Program to count the number of characters, words, spaces and lines in a given input file.

% {

#include<stdio.h>
int (cc=0,lc=10,wc=0,sc=0)

% }

[^ t n]+ {wc++;cc+=yyleng;}
[/t]      {sc++;}
n        {lc++}

%%

main(int arg c, char * argv[])
{
FILE * file;
if(argc>1)

file=fopen(argv[1],”r”);
if(!file)
{
printf(“Could not open file :) ;
exit(1);
}
yyin=file;
}
yylex();

printf(“n Number of Spaces = %d “,sc);
printf(“n Number of Words = %d “,wc);
printf(“n Number of Characters = %d “,cc);
printf(“n Number of Lines  = %d “,lc);

return 0;

}

…………………………………………………………………………………….

SAMPLE OUTPUT

…………………………………………………………………………………….

FILE CONTENT :

HELLO WORLD,

WELCOME TO MY FIRST LEX PROGRAM

PROGRAM OUTPUT :

Number of Spaces = 6

Number of Words = 8
Number of Characters = 38
Number of Lines  = 2

 

[Request : If you are going to post this program on any other website please link back to original post ]