Professional Documents
Culture Documents
COMMANDS:
CAL:
DESCRIPTION:
The cal command is used to display the calendar.
SYNTAX:
[$ CAL YEAR]
DATE:
DESCRIPTION:
The date command is used to display the day,month,year and time.
SYNTAX:
[$DATE]
The command can also be used within suitable format specified as argument .
Each format specified as argument .Each format is prescribed by a symbol followed by the %
OPTIONS:
MAN:
DESCRIPTION:
Format and displays online manuals.
SYNTAX:
Man [option] name
CLEAR:
DESCRIPTION:
Clear the terminal screen .
WHO:
DESCRIPTION:
Displays the information of logged in user.
OPTIONS:
-a-> All
-b-> Time of the last symbol boot
WHO AM I:
DESCRIPTION:
Show the login of the current user .
PASSWD:
DESCRIPTION:
Update on users authentication token.
SYNTAX:
Passwd [*][-1][-v][-f][-d][-n mindays][-m maxdays][username]
OPTIONS:
-k-> Used to lock an account
LOGOUT:
DESCRIPTION:
Exit off from current login.
FILE COMMANDS:
pwd:
DESCRIPTION:
Points the name of the current working directory
OPTIONS:
-help->displays help
mkdir:
DESCRIPTION:
Used to make/create the new directory.
SYNTAX:
mkdir [option] directory
OPTIONS:
-m ->sets permission mode]
cd:
DESCRIPTION:
Change the current directory to specified path.
SYNTAX:
cd [directory]
rmdir:
DESCRIPTION:
Used to remove/delete the empty directories.
SYNTAX:
rmdir [option]directory]
OPTIONS:
-output->diagnostics from each step
ls:
DESCRIPTION:
Used to list directory contents.
SYNTAX:
ls [option]…[file]
OPTIONS:
-a-> do not hide entries starting with author of each
-r->recursive list
-s->sort by size
-v->sort by version
cat:
DESCRIPTION:
Concatenate files and prints on the standard output.
SYNTAX:
cat [option] [file]
OPTION:
-a->show all
-t->show tabs
cp:
DESCRIPTION:
copies files and directories.
SYNTAX:
cp [option] source text
OPTIONS:
-r->copy recursively
rm:
DESCRIPTION:
Removes files (or) directories.
SYNTAX:
rm[option]..file..
OPTION:
-f->never prompt
-r->recursive remove
-i->interactive operation
mv:
DESCRIPTION:
Move or remove files.
SYNTAX:
mv[options]..source text
OPTION:
-f->do not prompt
-u->update
-i->interactive operation
file:
DESCRIPTION:
Determines the file type.
SYNTAX:
file[-f file name]
wc:
DESCRIPTION:
Prints the number of bytes,words&lines.
SYNTAX:
wc[options][file]
OPTION:
-c-> prints the character count
head:
DESCRIPTION:
Gives the first part of the file.
SYNTAX:
head[options]..[file]
OPTIONS:
-c->print first N bytes
tail:
DESCRIPTION:
Gives the last part of the file.
SYNTAX:
tail[option]..[file]
OPTIONS:
-c->print last N bytes
OUTPUT :
Enter a value:3
Enter a value:2
Enter c value:5
C=5 is greatest
ARITHMETIC OPERATION USING SWITCH CASE
PROGRAM :
echo 1.add
echo 2.sub
echo 3.mul
echo 4.div
echo enter your choice:
read n
echo enter a value:
read a
echo enter b value:
read b
case $ n in
1)c=’expr $a+$b’;;
2) c=’expr $a-$b’;;
3) c=’expr $a*$b’;;
4) c=’expr $a/$b’;;
esac
OUTPUT :
1.add
2.sub
3.mul
4.div
Enter a value:3
Enter b value:5
The result is 15
STUDENT DETAILS USING WHILE LOOP
PROGRAM :
OUTPUT :
total is:300
avg is:100
SYSTEM CALLS USING FORK()
PROGRAM :
#include<stdio.h>
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
main()
{
int pid;
int a,b,t;
printf("\nEnter a and b :");
scanf("%d%d",&a,&b);
pid=fork();
if(pid<0)
{
printf("error in fork");
}
if(pid==0)
{
printf("\nChild process to do swapping");
t=a;a=b;b=t;
}
else
{
printf("\nParent process");
wait(2);
}
printf("pid value as %d\n",getpid());
printf("A as:%d,B as:%d\n",a,b);
}
OUTPUT :
Enter a and b : 4
A as:5,B as:4
A as:4,B as:5
SYSTEM CALLS USING EXEC()
PROGRAM :
#include<stdio.h>
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
main(int age ,char *args[])
{
int pid;
pid=fork();
if(pid<0)
{
printf("error in fork");
}
if(pid==0)
{
printf("\nChild Process\n");
execlp("/home/jec/uma/sem.c","sem.c",NULL);
}
else
{
wait(NULL);
printf("\nChild Completed");
exit(0);
}
return 0;
}
OUTPUT :
Child Process
Child Completed
FILE CREATION
PROGRAM :
#include<stdio.h>
#include<unistd.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
main()
{
int fd;
char buf1[100],buf2[]="hello everybody",fname[30];
printf("enter filename\n");
scanf("%s",fname);
fd = creat(fname,S_IRWXU);
if(fd < 0)
{
printf("error in file creation");
}
else
{
write(fd,buf2,30);
printf("contents written successfully\n");
fd=open(fname,O_RDONLY);
read(fd,buf1,30);
printf("contents is:\n%s\n",buf1);
close(fd);
}
}
OUTPUT :
jec@jec-desktop:~/uma$ cc systemcall3.c
jec@jec-desktop:~/uma$ ./a.out
enter filename
devi
contents is:
hello everybody
hello everybody
FILE ATTRIBUTES
PROGRAM:
#include<errno.h>
#include<stdio.h>
#include<sys/stat.h>
#include<unistd.h>
int main()
{
struct stat statv;
if(stat("/home/staff/rajkumar/ww",&statv)==-1)
perror("stat");
else
{
printf("\n the file user id is: %d",statv.st_uid);
printf("\n the file group id is: %d",statv.st_gid);
printf("\n the file size is :%d",statv.st_size);
printf("\n the file inode number is :%d",statv.st_ino);
}
return (0);
}
OUTPUT:
./a.out ram.c
[cse@localhost ~]$ vi ram.c
HELLO WORLD
SIMULATION OF UNIX COMMANDS
PROGRAM :
#include<stdio.h>
int main()
{
char c;
int n;
printf("1.List of files in the directory\n2.List the lines\n3.Copy\n4.Remove\n");
scanf("%d",&n);
switch(n)
{
case 1:
system("ls");
break;
case 2:
system("grep argc john.c");
break;
case 3:
system("cp z c");
printf("the file is copied");
break;
case 4:
system("rm z c");
printf("the file is deleted");
break;
}
}
OUTPUT :
OUTPUT :
--------------------------------------
-------------------------------------------------------------------------------------------------
1 10 0 10
2 20 10 30
3 30 30 60
4 40 60 100
aw+=w[i];
ae+=e[i];
}
aw/=n;
ae/=n;
printf("\nAVERAGE WAITITNG TIME IS = %f",aw);
printf("\nAVERAGE TURN AROUND TIME IS = %f",ae);
return 0;
}
OUTPUT :
-------------------------------
-----------------------------------------------------------------------------------------------
1 10 0 10
2 20 10 30
3 30 30 60
PRIORITY SCHEDULING
ENTER THE NUMBER OF JOBS : 3
ENTER THE BURST TIME & PRIORITY OF JOB 1 : 4
2
ENTER THE BURST TIME & PRIORITY OF JOB 2 : 6
1
ENTER THE BURST TIME & PRIORITY OF JOB 3 : 8
3
BURST TIME PRIORITY START TIME FINISH TIME
6 1 0 6
4 2 6 10
8 3 10 18
OUTPUT :
CHATTING PROGRAM
PROGRAM:
#include<stdio.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<unistd.h>
#include<string.h>
int main()
{
int mid;
char mess[20];
printf("\n\n INTER PROCESS COMMUNICATION USING MESSAGE QUEUE...");
mid=msgget(27,IPC_CREAT|0777);
if(mid==-1)
{
printf("\n\t invalid message id..");
exit(1);
}
printf("\n enter the message text:");
scanf("%s",mess);
msgsnd(mid,mess,strlen(mess),0);
printf("\n\n message has been sent..\n");
printf("\n the sent message is:%s\n",mess);
}
OUTPUT:
PROGRAM:
#include<stdio.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<unistd.h>
#include<string.h>
int main()
{
int i,mid,len;
char mess[20];
printf("\n\n INTER PROCESS COMMUNICATION USING MESSAGE QUEUE...");
mid==msgget(27,IPC_CREAT|0777);
if(mid==-1)
{
printf("\n\t invalid message id..");
exit(1);
}
msgrcv(mid,mess,100,0,0);
printf("\n\n message has been recieved..\n");
printf("\n\n the recieved message is:%s\n",mess);
}
OUTPUT:
OUTPUT :
3
Enter the items2
1
the semaphore value of signal is 2
printf("\n%d\t\t%c\t\t%c\t\t%c",i+1,state[i],self[i],spoon[i]);
printf("\n1.EXIT\n2.HUNGRY\n3.THINKING");
scanf("%d",&ch);
while(ch!=1)
switch(ch)
case 1:
return 0;
case 2:
scanf("%d",&n);
pickup(n-1);
break;
case 3:
scanf("%d",&n);
putdown(n-1);
break;
printf("\nPHIL NO:\tTHINK/EAT\tSTATUS\t\tSPOON");
for(i=0;i<5;i++)
printf("\n%d\t\t%c\t\t%c\t\t%c",i+1,state[i],self[i],spoon[i]);
printf("\n1.EXIT\n2.HUNGRY\n3.THINKING");
scanf("%d",&ch);
OUTPUT :
1.EXIT
2.HUNGRY
3.THINKING
1.EXIT
2.HUNGRY
3.THINKING
1.EXIT
2.HUNGRY
3.THINKING
PAGING
PROGRAM :
#include<stdio.h>
main()
{
int i,j,arr[100],pt[20],val,pgno,offset,phymem,fs,nf;
printf("Memory management -Paging\n");
printf("\n*****************************");
printf("\nEnter size of physical memory");
scanf("%d",&phymem);
for(i=20,j=0;i<phymem+20,j<phymem;i++,j++)
arr[i]=j;
printf("\nEnter size of frame or page ");
scanf("%d",&fs);
nf=phymem/fs;
printf("\nNo of frames available are \t %d",nf);
printf("\nEnter page table");
for(i=0;i<nf;i++)
{
scanf("%d",&pt[i]);
}
printf("\nEnter page no");
scanf("%d",&pgno);
printf("\nEnter offset\n");
scanf("%d",&offset);
val=(fs*pt[pgno])+offset;
printf("The physical address is :%d\n",arr[val]);
}
OUTPUT :
*****************************
64
4
5
Enter page no
Enter offset
BEST FIT
PROGRAM :
#include<stdio.h>
main()
{
int i,n,m,ps[100],bs[150],j,pi[50],bi[50],t;
printf("enter the no of blocks\n");
scanf("%d",&n);
printf("enter the block size\n");
for(i=1;i<=n;i++)
{
printf("%d\n",i);
scanf("%d",&bs[i]);
bi[i]=i;
}
printf("enter no of process\n");
scanf("%d",&m);
for(i=1;i<=m;i++)
{
printf("enter process %d size:\n",i);
scanf("%d",&ps[i]);
pi[i]=i;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(bs[i]<bs[j])
{
t=bs[i];
bs[i]=bs[j];
bs[j]=t;
t=bi[i];
bi[i]=bi[j];
bi[j]=t;
}
if(ps[i]<ps[j])
{
t=ps[i];
ps[i]=ps[j];
ps[j]=t;
t=pi[i];
pi[i]=pi[j];
pi[j]=t;
}
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(ps[j]<=bs[i])
{
printf("process %d is allocated to block of size %d\n",pi[j],bs[i]);
ps[j]=10000;
break;
}
}
}
for(i=1;i<=m;i++)
{
if(ps[i]!=10000)
{
printf("\nprocess %d is not allowed",i);
}
}
}
OUTPUT :
OUTPUT :
ORPHAN PROCESS
PROGRAM:
main()
if(fork()==0)
system("clear");
else
}
OUTPUT:
CHILD:i am child & my number is :2663
CHILD: my parent is :1
PARENT-CHILD PROCESS
PROGRAM:
main()
if(fork()==0)
system("clear");
else
sleep(2);
}
OUTPUT:
PARENT:i am parent:2682
int pid,dip,cpid;
pid=fork();
if(pid==0)
else
dip=fork();
if(dip==0)
else
cpid=wait(0);
OUTPUT:
1st Child Process Id is 2699
int pid=fork();
system("clear");
if(pid>0)
sleep(05);
}
OUTPUT:
my number is 2716
my number is 2717
SINGLY LINKED LIST
PROGRAM:
#include<stdio.h>
#include<malloc.h>
struct queue
int no;
*p,*q,*temp,*head=NULL;
int main()
int ch;
void enqueue();
void dequeue();
void list();
while(1)
printf("\n 1...Insert");
printf("\n 2...Delete");
printf("\n 3...Display");
printf("\n 4...Quit");
scanf("%d",&ch);
switch(ch)
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
list();
break;
default:
exit(0);
return 0;
void enqueue()
scanf("%d",&temp->no);
if(head==NULL)
head=temp;
temp->next=NULL;
}
else
q=head;
while(q->next!=NULL)
q=q->next;
q->next=temp;
temp->next=NULL;
void dequeue()
p=head;
if(head==NULL)
printf("\n\nQueue is empty");
else
head=head->next;
free(p);
void list()
{
if(head==NULL)
printf("\n\nQueue is empty");
else
p=head;
while(p!=NULL)
printf("%d\t",p->no);
p=p->next;
}
OUTPUT:
1...Insert
2...Delete
3...Display
4...Quit
1...Insert
2...Delete
3...Display
4...Quit
1...Insert
2...Delete
3...Display
4...Quit
1...Insert
2...Delete
3...Display
4...Quit
Enter your choice:2
1...Insert
2...Delete
3...Display
4...Quit
13 14
1...Insert
2...Delete
3...Display
4...
Quit