URDINESH: unix
Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Saturday, August 1, 2015

Extract text From Shared Memory & Print it in Uppercase


PROGRAM: 

#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<sys/shm.h>
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#include<string.h>
main()
{
int shmid,i;
char *pa,a[1000];
shmid=shmget((key_t)1300,1024,0600|IPC_CREAT);
if(shmid==-1)
{printf("shmget failed");
return;
}
pa=(char*)shmat(shmid,0,0);
if(pa==(void *)-1)
{
printf("shmat failed");
return;
}
for(i=0;pa[i]!='\0';i++)
{
if(pa[i]>='a'&&pa[i]<='z')
pa[i]=pa[i]-32;
else
continue;
}
printf("\nUppercase Message : %s",pa);

}


OUTPUT:



[user @localhost ~]$ cc umgsh.c
[user @localhost ~]$ ./a.out

Uppercase Message : MESSAGE STORED IN SHARED MEMORY
SHARED MEMORY PROGRAMS
[user @localhost ~]$


Storing Lower case Message in Shared Memory-I


#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<sys/shm.h>
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#include<string.h>
main()
{
int shmid,i;
char *pa,a[1000];
shmid=shmget((key_t)1300,1024,0600|IPC_CREAT);
if(shmid==-1)
{printf("shmget failed");
return;
}
pa=(char*)shmat(shmid,0,0);
if(pa==(void *)-1)
{
printf("shmat failed");
return;
}
printf("Enter text&press$to terminate\n");
for(i=0;(a[i]=getchar())!='$';i++);
a[i]='\0';
strcpy(pa,a);
printf("The given text is placed into shared memory\n");
}






OUTPUT


[user@localhost ~]$ cc mgsh.c
[user @localhost ~]$ ./a.out
Enter text&press$to terminate
Message stored in shared memory
shared memory programs$
The given text is placed into shared memory

[user @localhost ~]$ 

MarkSheet Preparation Using SharedMemory –II

 PROGRAM:

#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<sys/shm.h>
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#include<string.h>
struct stud
{char name[25];
int roll,m1,m2,m3,tot;
float avg;
};
main()
{struct stud m,*p;
p=&m;
int shmid;
shmid=shmget((key_t)1300,1024,0660|IPC_CREAT);
if(shmid==-1)
{printf("shmget failed");
return;
}
p=(struct stud *)shmat(shmid,0,0);
if(p==(void *)-1)
{printf("shmat failed");
return;
}
p->tot=p->m1+p->m2+p->m3;
p->avg=(float)p->tot/3.0;
printf("\nNAME: %s",p->name);
printf("\nROLLNO:%d",p->roll);
printf("\nMARK1:%d",p->m1);
printf("\nMARK@:%d",p->m2);
printf("\nMARK#:%d",p->m3);
printf("\nTOTAL:%d",p->tot);
printf("\nAVERAGE:%f",p->avg);
}




OUTPUT:


[user @localhost ~]$ cc cmarsh.c
[user @localhost ~]$ ./a.out

NAME: Kannan
ROLLNO:987
MARK1:89
MARK@:98
MARK#:78
TOTAL:265

AVERAGE:88.333336[user @localhost ~]$

MarkSheet Preparation Using SharedMemory –I

PROGRAM:

#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#include<string.h>
struct stud
{
char name[25];
int roll,m1,m2,m3,tot;
float avg;
};
main()
{
struct stud m,*p;
p=&m;
int shmid;
shmid=shmget((key_t)1300,1024,0600|IPC_CREAT);
if(shmid==-1)
{printf("shmget failed");
return;
}
p=(struct stud *)shmat(shmid,0,0);
if(p==(void *)-1)
{
printf("shmat failed");
return;
}
printf("Enter the name:\n");
scanf("%s",p->name);
printf("Enter the Roll.No:\n");
scanf("%d",&p->roll);
printf("Enter the marks  got in 3 subject: \n");
scanf("%d%d%d",&p->m1,&p->m2,&p->m3);
printf("\nThe given information is placed in shared memory\n");
}


OUTPUT:

[user @localhost ~]$ cc marsh.c
[user @localhost ~]$ ./a.out
Enter the name:
Kannan
Enter the Roll.No:
987
Enter the marks  got in 3 subject:
89 98 78

The given information is placed in shared memory
[user @localhost ~]$


Length of the string using Shared Memory-II

Program:

#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<sys/shm.h>
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#include<string.h>
main()
{
int shmid,i,len;
char *pa,a[1000];
shmid=shmget((key_t)1300,1024,0600|IPC_CREAT);
if(shmid==-1)
{printf("shmget failed");
return;
}
pa=(char*)shmat(shmid,0,0);
if(pa==(void *)-1)
{
printf("shmat failed");
return;
}
len=strlen(pa);
printf("\nThe length of the text is : %d\n",len);
}




OUTPUT:

[user @localhost ~]$ cc lenshm.c
[user @localhost ~]$ ./a.out

The length of the text is : 54

[user @localhost ~]$

Length of the string using Shared Memory

Program

#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<sys/shm.h>
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#include<string.h>
main()                 
{
int shmid,i;
char *pa,a[1000];
shmid=shmget((key_t)1300,1024,0600|IPC_CREAT);
if(shmid==-1)
{printf("shmget failed");
return;
}
pa=(char*)shmat(shmid,0,0);
if(pa==(void *)-1)
{
printf("shmat failed");
return;
}
printf("Enter text&press$to terminate\n");
for(i=0;(a[i]=getchar())!='$';i++);
a[i]='\0';
strcpy(pa,a);
printf("The given text is placed into shared memory\n");
}


OutPut


[user@localhost ~]$ cc mgsh.c
[user @localhost ~]$ ./a.out
Enter text&press$to terminate
Message stored in shared memory
shared memory programs$
The given text is placed into shared memory
[user @localhost ~]$ 

Wednesday, July 22, 2015

SHELL SCRIPT TO COPY ONE FILE TO ANOTHER FILE

COPY ONE FILE TO ANOTHER FILE:

echo "copying one file to another"
if [ $# -eq 4 ]
then
   cp $3 $1
   cp $4 $2
 fi
























OUTPUT:

[@localhost ~]$ cat f3
hai this is rajasekar
[@localhost ~]$ cat f4
i did my pg in nmc
[@localhost ~]$ sh copy.sh f1 f2 f3 f4
copying one file to another
[@localhost ~]$ cat f1
hai this is rajasekar
[@localhost ~]$ cat f2
i did my pg in nmc

SHELL SCRIPT TO REMOVE THE LINES IN A GIVEN PATTERN

REMOVE THE LINES IN A GIVEN PATTERN:


echo "Enter file name"
read file
echo "Enter pattern"
read pat
grep -v $pat $file







OUTPUT:

[@localhost ~]$ sh pattern.sh
Enter file name
raja
Enter pattern
did
HAI I AM RAJASEKAR
I DID MY STUDIES IN NMC
I COMPLEATED MY PG DEGREE IN MBA AND MCA
I AM ALWAYS BE A OVER-CONFIDENT PERSON
THEN ONLY LEADS TO VERY SUCCESSFULL MANNER

[@localhost ~]$ sh pattern.sh
Enter file name
raja
Enter pattern
COMPLEATED
HAI I AM RAJASEKAR
I DID MY STUDIES IN NMC
I AM ALWAYS BE A OVER-CONFIDENT PERSON
THEN ONLY LEADS TO VERY SUCCESSFULL MANNER

[@localhost ~]$ sh pattern.sh
Enter file name
raja
Enter pattern
I
THEN ONLY LEADS TO VERY SUCCESSFULL MANNER

Tuesday, July 21, 2015

SHELL SCRIPT TO PAYBILL PREPARATION

PAYBILL PREPARATION:


 echo -e "\tPAYBILL CALCULATION"
echo -e "\t~~~~~~~~~~~~~~~~~~~~"
echo -e "\tenter the n value"
read n
echo -e "\tenter name id salary"
for((i=1;i<=n;i++))
do
`read name id salary
echo -e "\tbefore calculation"
echo -e "\t***********************"
echo -e "\tname\t:$name\n\tid\t:$id\n\tsalary\t:$salary"
echo -e "\t***********************"
echo -e "\t calculation part"
if [ $salary -lt 10000 ]
then
lic=`expr $salary*0.05|bc`
echo -e "\n\tlic:\t"$lic
pf=`expr $salary*0.03|bc`
echo -e "\n\tpf:\t"$pf
ded=`expr $lic+$pf|bc`
echo -e "\n\tded:\t"$ded
hra=`expr $salary*0.03|bc`
echo -e "\n\thra:\t"$hra
da=`expr $salary*0.08|bc`
echo -e "\n\tda:\t"$da
add=`expr $hra+$da|bc`
echo -e "\n\tadd:\t"$add
gpay=`expr $salary-$ded|bc`
echo -e "\n\tgpay:\t"$gpay
npay=`expr $gpay+$add|bc`
echo -e "\n\tnpay:\t"$npay
echo -e "\n\tafter calculation"
echo -e "\n\t*********************"
echo -e "\n\tname\t:$name\n\tid\t:$id\n\tnetpay\t:$npay"
echo -e "\n\t***********************"
else
lic=`expr $salary*0.05|bc`
echo -e "\n\tlic:\t"$lic
pf=`expr $salary*0.03|bc`
echo -e "\n\tpf:\t"$pf
ded=`expr $lic+$pf|bc`
echo -e "\n\tded:\t"$ded
hra=`expr $salary*0.03|bc`
echo -e "\n\thra:\t"$hra
da=`expr $salary*0.08|bc`
echo -e "\n\tda:\t"$da
add=`expr $hra+$da|bc`
echo -e "\n\tadd:\t"$add
gpay=`expr $salary-$ded|bc`
echo -e "\n\tgpay:\t"$gpay
npay=`expr $gpay+$add|bc`
echo -e "\n\tnpay:\t"$npay
echo -e "\n\tafter calculation"
echo -e "\n\t*********************"
echo -e "\n\tname\t:$name\n\tid\t:$id\n\tnetpay\t:$npay"
echo -e "\n\t***********************"
fi
done































OUTPUT:

[@localhost ~]$ sh paybill.sh
        PAYBILL CALCULATION
        ~~~~~~~~~~~~~~~~~~~~
        enter the n value
2- INSERT --
        enter name id salary
rajasekar 324 100000
        before calculation
        ***********************
        name    :rajasekar
        id      :324
        salary  :100000
        ***********************
         calculation part

        lic:    5000.00

        pf:     3000.00

        ded:    8000.00

        hra:    3000.00

        da:     8000.00

        add:    11000.00

        gpay:   92000.00

        npay:   103000.00

        after calculation

        *********************

        name    :rajasekar
        id      :324
        netpay  :103000.00


        ***********************

SHELL SCRIPT TO COMPARE TWO FILE

COMPARE TWO FILE:
cmp $1 $2
if [ $? -eq 0 ]
then
echo "Both files are EQUAL"
else
echo "Both files are NOTEQUAL"
fi























OUTPUT:

[@localhost ~]$ ls
acceptlogin.sh  current.sh     file1.sh     mark.sh  pol        totaldir.sh
add.sh          dcurrent.sh    file1.txt    new1.c   pol.sh     tri.sh
a.out           eletricity.sh  file2.txt    new1.sh  raj        userlog
big.sh          fact           fileper      new.c    raja.c     userlog.sh
big.shwq        fact.sh        fileper.sh   op.sh    series.sh  x.txt
com.sh          fib.sh         firstlet.sh  per.sh   subdir.sh  y.txt


[@localhost ~]$ sh com.sh fib.sh fact.sh
fib.sh fact.sh differ: byte 1, line 1
Both files are NOTEQUAL

[@localhost ~]$

SHELL SCRIPT FOR FIBONACCI SERIES

FIBNOCIS SERIES:

echo "Enter choice="
read n
fib1=0
fib2=1
echo "The series are=$fib1 $fib2"
for ((i=0; $i<$n; i=`expr $i + 1|bc`))
do
fib3=`expr $fib1 + $fib2 |bc`
fib1=$fib2
fib2=$fib3
echo "$fib3"
done
















OUTPUT:
 [@localhost ~]$ sh fib.sh
Enter choice=
10
The series are=0 1
1
2
3
5
8
13
21
34
55
89

[@localhost ~]$

Followers