Posts Tagged ‘6th sem vtu’

System Software Lab Programs ( UNIX Programs ) – 7b

// June 7th, 2009 // Comments // Educational, Engineering, Unix and System Software Lab

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

[Click Here to get other programs by email ]

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

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

7b) C program to prompt the user for the name of an environment variable and print its value if it is defined and a suitable message otherwise; and to repeat the process if user wants it.

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>

int main()
{
char env[10],*p;
int ch=1;

while(ch!=0)
{
printf(“n Enter name of evironment variable :”);
scanf(“%s”,env);

p=getenv(env);
printf(“%s”,p);
printf(“n Want to change ? 1 for yes & 0 for no :”);
scanf(“%d”,&ch);
}
return 0;
}

[Click Here to get other programs by email ]

System Software Lab Programs ( UNIX Programs ) – 7a

// June 7th, 2009 // Comments // Educational, Engineering, Unix and System Software Lab

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

[Click Here to get other programs by email ]

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

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

7. a) Shell script to implement terminal locking. It should prompt the user for a password. After accepting the password entered by the user, it must prompt again for password confirmation (to retype the password). If a match occurs, it must lock the terminal and promp for the password. If the proper password is entered, the terminal must be unlocked. Note the script must be written to disregard BREAK, Control-D etc. No time limit need be implemented for the lock duration.

stty -echo
echo “Enter the password: ”
read pw
echo “Confirm password: ”
read cpw
if["$pw" = "$cpw"]
then
trap “.” 1 2 15 18 30
echo “Keyboard locked”
fi
echo “Enter password to resume
read npw
while["$pw" = "$npw"]
do
echo “Enter password”
read npw
done
echo “Terminal unlock”
fi
stty sane

[Click Here to get other programs by email ]

System Software Lab Programs ( UNIX Programs ) – 6b

// June 6th, 2009 // Comments // Educational, Engineering, Unix and System Software Lab

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

[Click Here to get other programs by email ]

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

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

6b) C program that accepts a valid directory names as a command line argument and lists all the files in the given directory as well as all  the subsequent subdirectories. (The solution can be recursive or nonrecursive).

#include<stdio.h>
#include<ftw.h>
int recursive(const char *dir,const struct stat *name,int type)
{
if(type==FTW_D)
printf(“n Directory->%s”,dir);
else if(type==FTW_F)
printf(“nFile->%s”,dir);
return 0;
}

int main(int argc,char *argv[])
{
int depth=5;
ftw(argv[1],recursive,depth);
printf(“n”);
return 0;
}

[Click Here to get other programs by email ]

System Software Lab Programs ( UNIX Programs ) – 6a

// June 6th, 2009 // Comments // Educational, Engineering, Unix and System Software Lab

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

[Click Here to get other programs by email ]

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

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

6. a) Shell script that accepts valid log-in names as arguments and prints their corresponding home directories. If no arguments are specified, print a suitable error message.

if [ $# -eq 0 ]
then
echo -e “No arguments”
else
for a in $*
do
grep $a /etc/passwd>list
if [ $? -eq 0 ]
then
echo “Home dir of $a is :”
cut -c 20-46 list
else
echo “Improper login name $a”
fi
done
fi

[Click Here to get other programs by email ]

System Software Lab Programs ( UNIX Programs ) – 5b

// June 5th, 2009 // Comments // Educational, Engineering, Unix and System Software Lab

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

[Click Here to get other programs by email ]

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

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

5b) C program that accepts one command-line argument, executes the arguments as a shell command, determines the time taken by it and prints the time values, Use the “times”, function and the “tms” structure. The code need not include error checking.

#include<stdio.h>
#include<sys/times.h>
#include<unistd.h>

int main(int argc,char *argv[10])
{
char cmd[10];
struct tms obj1,obj2;
clock_t st,end;
float time;
st=times(&obj1);
system(“clear”);
printf(“%Sn”,argv[1]);
end=times(&obj2);
printf(“Real time taken = %fn”,st);
printf(“User time taken = %fn”,end);
time=(end-st)/3600;
printf(“nSystem time taken : %f”,time);
return 0;
}

[Click Here to get other programs by email ]

System Software Lab Programs ( UNIX Programs ) – 5a

// June 5th, 2009 // Comments // Educational, Unix and System Software Lab

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

[Click Here to get other programs by email ]

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

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

5. a) Shell script that accepts path names and creates all the components in that pathnames as directories. For example, if the script name is
mpe, then the command mpe a/b/c/d should create directories a, a/b, a/b/c, and a/b/c/d.

v1=`echo $* |tr “/” ” “`
echo $v1
for i in $v1
do
mkdir $i
cd $i
done

[Click Here to get other programs by email ]

System Software Lab Programs ( UNIX Programs ) – 4b

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

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

[Click Here to get other programs by email ]

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

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

4b) C program to do the following: Using fork( ) create a child process. The child process prints its own process-id and id of its parent and then exits. The parent process waits for its child to finish (by executing the wait( )) and prints its own process-id and the id of its child process and then exits.

#include<stdio.h>
#include<sys/types.h>

int main()
{
int status,ppid,mpid,pid;
pid=fork();

if(pid<0)
{
printf(“Error in forking a child..!”);
exit(0);
}

if(pid==0)
{
ppid=getppid();

printf(“nChild is executing and it’s Parent ID is  : %d”,ppid);
mpid=getpid();
printf(“nChild ID is  : %d”,mpid);
kill();
exit(0);
}
//pid=wait(pid,&status,0);
mpid=getpid();

printf(“nParent ID is : %d  and it’s child ID is : %dn”,mpid,pid);
}

[Click Here to get other programs by email ]

System Software Lab Programs ( UNIX Programs ) – 4a

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

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

[Click Here to get other programs by email ]

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

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

4. a) Shell script that accepts file names specified as arguments and creates a shell script that contains this file as well as the code to
recreate these files. Thus if the script generated by your script is executed, it would recreate the original files(This is same as the “bundle” script described by Brain W. Kernighan and Rob Pike in “ The Unix Programming Environment”, Prentice – Hall India).

#!/bin/bash

echo “# to unbundle,bash this file n:”
for i
do
echo “echo $ i1>i2″
echo “cat >$i <<’END of $i’”
cat $i
echo “END OF $i”
echo -e
done

[Click Here to get other programs by email ]

System Software Lab Programs ( UNIX Programs ) – 3b

// June 2nd, 2009 // Comments // Educational, Engineering, Unix and System Software Lab

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

[Click Here to get other programs by email ]

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

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

Problem Definition : C program that accepts valid file names as command line arguments and for each of the arguments, prints the type of the file (Regular file, Directory file, Character special file, Block special file, Symbolic link etc.)

#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>

int main(int argc,char *argv[])
{
int i;
struct stat buf;

for(i=1;i<=argc;i++)
{
printf(“%s”,argv[i]);

if(lstat(argv[i],&buf)==-1)
{
printf(“nlstat error..n”);
continue;
}

if(S_ISREG(buf.st_mode))
printf(“nRegular filen”);

else if(S_ISDIR(buf.st_mode))
printf(“nDirectory filen”);

else if(S_ISCHR(buf.st_mode))
printf(“nCharacter special filen”);

else if(S_ISBLK(buf.st_mode))
printf(“nBlock special filen”);

else if(S_ISLNK(buf.st_mode))
printf(“nSymbolic link filen”);

else
printf(“nUnknown filen”);

return 0;
}
}

[Click Here to get other programs by email ]

System Software Lab Programs ( UNIX Programs ) – 3a

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

Subject : System Software Laboratory

Branch : Information Science & Engineering

Semester : 6

University : VTU

[Click Here to get other programs by email ]

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

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


3.a) Shell function that takes a valid directory names as an argument an recursively descends all the sub directories, finds the maximum length of any file in that hierarchy and writes this maximum value to the standard output.

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

clear

find

{

clear tput

echo -e “Enter a valid directory name : ”

read dir

if [  -d @dir ]

then

ls -1R $dir>file1

grep -h “^-r” file1>file2

cat file2

cut -c 24-28 file2>file3

sort -n file3>file4

tail -1 file4>file5

echo -e “Max length is ”

cat file5

else

else

echo -e “Invalid dir ”

fi

}

[Click Here to get other programs by email ]

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