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 % Operator describing the format, -m -> Display the month in number -h -> Display the month in words -d -> Display the day in words -y -> Display last two digits of the year
OPTIONS:
U print or sets coordinate universal time S set the current time to specified time
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.
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 -n->Will set minimum password time
LOGOUT:
DESCRIPTION:
Exit off from current login.
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 -c-> list entries by columns -d-> list directory entries -f-> do not sort -l-> use long history format -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:
cp: DESCRIPTION:
copies files and directories.
SYNTAX:
cp [option] source text
OPTIONS:
-r->copy recursively -u->copy only when the source is never
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 -w->prints word count -l-> print the line count
head: DESCRIPTION:
Gives the first part of the file.
SYNTAX:
head[options]..[file]
OPTIONS:
-c->print first N bytes -n->print first n lines
tail: DESCRIPTION:
Gives the last part of the file.
SYNTAX:
tail[option]..[file]
OPTIONS:
-c->print last N bytes -n->print last N lines
OUTPUT :
Enter a value:3 Enter a value:2 Enter c value:5 C=5 is greatest
OUTPUT :
1.add 2.sub 3.mul 4.div Enter your choice:3 Enter a value:3 Enter b value:5 The result is 15
tot=explr $m1+$m2+sm3 avg=expr $ tot/3 echo name is:$ name echo no is : $ no echo avg is: $ avg echo total is: $ tot count=expr $ count+1
OUTPUT :
enter the name: student enter the no:1 enter the marks m1,m2,m3:100 100 100 total is:300 avg is:100
OUTPUT :
Enter a and b : 4 5 Child process to do swapping pid value as 6651 A as:5,B as:4 Parent process pid value as 6649 A as:4,B as:5
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 written successfully contents is: hello everybody jec@jec-desktop:~/uma$ cat devi 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:
the file user id is: 920 the file group id is: 921 the file size is :33 the file inode number is :8230320
} int main() { int rc=0; char buf[256]; do { printf("\n sh>"); if(!gets(buf)) break; rc=system(buf); } while(!rc); exit(rc); }
OUTPUT:
sh>ls a.out Desktop gg bb fact.sh ha hai big.sh ff m3.txt odd.sh p2.c prim.sh sal.sh menu.sh p1o.c p2c.c raj mm.c small.sh simcd.c user.sh simmv.c small1.sh
chat1.c ff.sh io4.c mul.sh p1w.c p4.c rrr chat2.c fib.sh m2.txt mylist p1z.c pn.sh rr.sh sh>cal January 2009 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
SCANNING A DIRECTORY
PROGRAM:
#include<stdio.h> #include<sys/types.h> //#include<stdlib.h> #include<unistd.h> #include<string.h> #include<sys/stat.h> #if defined(BSD)&&I_POSIX_SOURCE #include<sys/dir.h> typedef struct dirent Dirent; #else #include<dirent.h> typedef struct dirent Dirent; #endif int main(int argc, char *argv[]) { Dirent* dp; int i; int cnt; DIR *dir_fdesc; while(--argc>0) { dir_fdesc=opendir(*++argv); for(i=0;i<2;i++) { for(cnt=0;dp=readdir(dir_fdesc);) {
OUTPUT:
/a.out /home/staff/rajkumar/gg pp.sh hh.txt rajkumar gg
OUTPUT:
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 :
1.List of files in the directory 2.List the lines 3.Copy 4.Remove 1 Ric.c
Sab.c Sat.c 1.List of files in the directory 2.List the lines 3.Copy 4.Remove 2 int main(int argc,char * argv[]) 1.List of files in the directory 2.List the lines 3.Copy 4.Remove 3 The file is copied 1.List of files in the directory 2.List the lines 3.Copy 4.Remove 4 The file is deleted
scanf("%d",&n); for(i=0;i<n;i++) { printf("\nENTER THE BURST TIME FOR JOB %d :",i+1); scanf("%d",&b[i]); if(i==0) { w[0]=0; t[0]=b[0]; } else { w[i]=t[i-1]; t[i]=t[i-1]+b[i]; } } printf("\nJOB\tBURST TIME\tWAITING TIME\tTURN AROUND TIME\n"); printf("\n---------------------------------------------------------------------------------\n"); for(i=0;i<n;i++) { ae+=b[i]; printf("\n%d\t\t%d\t\t%d\t\t%d\n",i+1,b[i],w[i],t[i]); aw+=w[i]; at+=t[i]; } ae/=n; aw/=n; at/=n; printf("\nAVERAGE BURST TIME IS = %f",(float)ae); printf("\nAVERAGE WAITING TIME IS = %f",(float)aw); printf("\nAVERAGE TURN AROUND TIME IS = %f",(float)at); return 0; }
OUTPUT :
FIRST COME FIRST SERVE --------------------------------------
ENTER THE NUMBER OF JOBS : 4 ENTER THE BURST TIME FOR THE JOB1 : 10 ENTER THE BURST TIME FOR THE JOB2 : 20
ENTER THE BURST TIME FOR THE JOB3 : 30 ENTER THE BURST TIME FOR THE JOB4 : 40
JOB
BURSTTIME
WAITING TIME
TURNAROUNDTIME
------------------------------------------------------------------------------------------------1 2 3 4 10 20 30 40 0 10 30 60 10 30 60 100
AVERAGE BURSTTIME IS = 25.0000000 AVERAGE WAITING TIME IS = 24.9999992 AVERAGE TURNAROUNDTIME IS = 50.00000
scanf("%d",&n); for(i=0;i<n;i++) { printf("\nENTER THE BURST TIME OF JOB %d = ",i+1); scanf("%d",&b[i]); b1[i]=b[i]; j[i]=i; } for(i=0;i<n;i++) for(k=0;k<n;k++) if(b1[i]<b1[k]) { t=b1[i]; b1[i]=b1[k]; b1[k]=t; } printf("\nJOB\tBURST TIME\tWAITING TIME\tTURN AROUND TIME\t"); printf("\n----------------------------------------------------------------------------------"); for(i=0;i<n;i++) { if(i==0) { w[0]=0; e[0]=b1[0]; } else { w[i]=e[i-1]; e[i]=e[i-1]+b1[i]; } printf("\n%d\t\t%d\t\t%d\t\t%d\n",i+1,b1[i],w[i],e[i]);
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 :
SHORTEST JOB FIRST -------------------------------
ENTER THE NUMBER OF JOBS: 3 ENTER THE BURST TIME FOR THE JOB1 = 30 ENTER THE BURST TIME FOR THE JOB2 = 10 ENTER THE BURST TIME FOR THE JOB3 = 20
JOB
BURSTTIME
WAITING TIME
TURNAROUNDTIME
----------------------------------------------------------------------------------------------1 2 3 10 20 30 0 10 30 10 30 60
= 13.333333
PRIORITY SCHEDULING
PROGRAM :
#include<stdio.h> int main() { int i,j,n,temp,start[10],pri[10],finish[10],burst[10],sw=0,st=0; printf("\nPRIORITY SCHEDULING\n"); printf("\nENTER THE NUMBER OF JOBS : "); scanf("%d",&n); start[0]=0; for(i=0;i<n;i++) { printf("\nENTER THE BURST TIME & PRIORITY OF JOB %d : ",i+1); scanf("%d %d",&burst[i],&pri[i]); } for(i=0;i<n;i++)
for(j=i+1;j<n;j++) if(pri[j]<pri[i]) { temp=pri[i]; pri[i]=pri[j]; pri[j]=temp; temp=burst[i]; burst[i]=burst[j]; burst[j]=temp; } printf("\n BURST TIME\t PRIORITY\t START TIME\t FINISH TIME"); for(i=0;i<n;i++) { start[i+1]=finish[i]=start[i]+burst[i]; st+=finish[i]; sw+=start[i]; printf("\n%d\t\t%d\t\t%d\t\t%d",burst[i],pri[i],start[i],finish[i]); } printf("\n AVERAGE TURN AROUND TIME IS %f",(float)st/n); printf("\n AVERAGE WAITING TIME IS %f",(float)sw/n); return 0; }
OUTPUT :
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 6 PRIORITY 1 START TIME 0 FINISH TIME 6
4 8
2 3
6 10
10 18
printf("\nENTER THE TIME SLICE FOR JOBS : "); scanf("%d",&s); k=1; for(j=0;j<max;j+=s) { printf("\nJOB\t BURST TIME\t REMAINING TIME"); for(i=0;i<n;i++) { if(b[i]==0) continue; if(b[i]<s) { a=b[i]; x[k]=i; xx[k]=b[i]; k++; } else { a=b[i]; x[k]=i; xx[k]=s; k++; } b[i]=a-s; printf("\n\t%d\t\t%d\t\t%d",i+1,a,b[i]); } printf("\n\n"); scanf("%d",&c); } for(i=1;i<=k;i++) count+=1; cum[i]=0; for(i=2;i<=count;i++) { cum[i]=xx[i-1]+cum[i-1]; printf("%d\t",cum[i]); } for(j=0;j<n;j++) { for(i=count-1;i>=1;i++) { if(x[i]==j) { wait[j]=cum[i+1]-b1[j]; t=t+cum[i+1]; break;
} } } printf("\n WAITING TIME"); for(i=0;i<n;i++) { printf("\n%d",wait[i]); wa=wa+wait[i]; } printf("\n AVERAGE WAITING TIME is \t%f",(float)wa/n); printf("\n AVERAGE EXECUTION TIME is \t%f",(float)t/n); wt=wa+t; printf("\n AVERAGE TURN AROUND TIME is \t%f",(float)wt/n); }
OUTPUT :
ROUND ROBIN SCHEDULING ENTER THE NUMBER OF JOBS : 3 ENTER THE BURST TIME OF JOB 1 : 4 ENTER THE BURST TIME OF JOB 2 : 2 ENTER THE BURST TIME OF JOB 3 : 6 ENTER THE TIME SLICE FOR JOBS: 2 JOB 1 2 3 JOB 1 3 JOB 3 BURST TIME 4 2 6 BURST TIME 2 4 BURST TIME 2 REMAINING TIME 2 0 4 REMAINING TIME 0 2 REMAINING TIME 0
2 4 6 8 10 12 WAITING TIME 4 2 6
AVERAGE WAITING TIME IS 4.000000 AVERAGE EXECUTION TIME IS 8.00000 AVERAGE TURN AROUND TIME IS 12.000000
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:
INTER PROCESS COMMUNICATION USING MESSAGE QUEUE... enter the message text:hai message has been sent.. the sent message is:hai
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:
INTER PROCESS COMMUNICATION USING MESSAGE QUEUE... message has been recieved.. the recieved message is:hai
if(s==2) { consumer(buffer); } printf("\nto continue ,press 1 or else press 0"); scanf("%d",&c); } while(c!=0); } void producer() { w=wait(mutex); printf("\nthe semaphore value of wait is =%d\n",w); printf("\nEnter the no of items:\n"); scanf("%d",&n); printf("\nEnter the items"); for(i=0;i<=n;i++) { scanf("%d",&np[i]); } printf("\n given items are:"); for(i=0;i<=n;i++) { printf("%d\n",np[i]); } if((in+1%bz==out)) { printf("\ndo anything"); } printf("\n the producer produce the items:\n"); for(i=0;i<=n;i++)
{ buffer[i]=np[i]; printf("%d\n",buffer[in]); in=(in+1)%bz; } sig=signal(mutex); printf("the semaphore value of signal is %d\n",sig); } void consumer(int y[bz]) { if(mutex) printf("\n the semsphore value of wait is=%d\n",w); if(in==out) { printf("\n do nothing\n"); } printf("\nthe consumer consumes the items:\n"); for(i=0;i<=n;i++) { ne[i]=y[out]; printf("%d\n",ne[i]); out=(out+1)%bz; } sig=signal(mutex); printf("the semaphore value of signal is %d\n",sig); } int signal(int m) { m++; return m; }
OUTPUT :
1.produce the items 2.consumer the items 1
The semaphore value of wait is =2 Enter the no of items: 3 Enter the items2 3 4 1 given items are:2 3 4 1 the producer produce the items: 2 3 4 1 the semaphore value of signal is 2
1.produce the items 2.consumer the items 2 the semsphore value of wait is=2 the consumer consumes the items: 2 3 4 1 the semaphore value of signal is 2 to continue ,press 1 or else press 0
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"); printf("\nEnter your choice :"); scanf("%d",&ch); while(ch!=1) { switch(ch) { case 1: return 0; case 2: printf("\nEnter which philosopher is hungry :"); scanf("%d",&n); pickup(n-1); break; case 3: printf("\nEnter which philosopher is thinking :"); scanf("%d",&n); putdown(n-1); break; } printf("State of each philosopher :"); 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"); printf("\nEnter your choice :"); scanf("%d",&ch); }
OUTPUT :
DINING PHILOSOPHERS PROBLEM : Initial state of each philosopher : PHIL NO: 1 2 3 4 5 1.EXIT 2.HUNGRY 3.THINKING Enter your choice :2 Enter which philosopher is hungry :2 State of each philosopher : PHIL NO: THINK/EAT 1 t 2 e 3 t 4 t 5 t 1.EXIT 2.HUNGRY 3.THINKING Enter your choice :3 Enter which philosopher is thinking :4 State of each philosopher : PHIL NO: THINK/EAT 1 t 2 e 3 t 4 t 5 e 1.EXIT 2.HUNGRY 3.THINKING Enter your choice :1 THINK STATUS t s t s t s t s t s SPOON s s s s s
STATUS s s s s s
SPOON n n s s s
STATUS s s s s s
SPOON n n s n n
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 :
Memory management -Paging ***************************** Enter size of physical memory 64 Enter size of frame or page 8 No of frames available are Enter page table 1 2 3 4 5 6 7 8 Enter page no 5 Enter offset 3 The physical address is :31 8
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 :
enter the no of blocks 4 enter the block size 1 200
2 250 3 300 4 400 enter no of process 3 enter process 1 size: 225 enter process 2 size: 275 enter process 3 size: 325 process 0 is allocated to block of size 200 process 1 is allocated to block of size 250 process 2 is allocated to block of size 300
FIRST FIT
PROGRAM :
#include<stdio.h> main() { int i,n,m,ps[100],bs[150],j;
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]); } 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]); } //memory allocation 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",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 :
enter the no of blocks 4 enter the block size 1
400 2 500 3 300 4 600 enter no of process 4 enter process 1 size: 200 enter process 2 size: 250 enter process 3 size: 350 enter process 4 size: 550 process 1 is allocated to block of size 400 process 2 is allocated to block of size 500 process 3 is allocated to block of size 600 process 4 is not allowed
ORPHAN PROCESS
PROGRAM:
main() { if(fork()==0) {
system("clear"); printf("CHILD:i am child & my number is :%d \n",getpid()); printf("CHILD: my parent is :%d \n",getppid()); } else { printf("PARENT:i am parent:%d \n",getpid()); printf("PARENT: my parent is :%d \n",getppid()); } }
OUTPUT:
CHILD:i am child & my number is :2663 CHILD: my parent is :1
PARENT-CHILD PROCESS
PROGRAM:
main() { if(fork()==0) { system("clear"); printf("CHILD:i am child & my number is :%d \n",getpid()); printf("CHILD: my parent is :%d \n",getppid()); } else
OUTPUT:
PARENT:i am parent:2682 CHILD:i am child & my number is :2683 CHILD: my parent is :2682 PARENT: my parent is :2434
WAITING PROCESS
PROGRAM:
main() { int pid,dip,cpid; pid=fork(); if(pid==0) { printf("1st Child Process Id is %d\n",getpid()); printf("1st Child Process TERMINATING FROM THE MEMORY\n"); } else
{ dip=fork(); if(dip==0) { printf("2st Child Process Id is %d\n",getpid()); printf("2st Child Process TERMINATING FROM THE MEMORY\n"); } else { cpid=wait(0); printf("Child with pid:%d is died\n",cpid); cpid=wait(0); printf("Child with pid:%d is died\n",cpid); } } }
OUTPUT:
1st Child Process Id is 2699 1st Child Process TERMINATING FROM THE MEMORY 2st Child Process Id is 2700 2st Child Process TERMINATING FROM THE MEMORY Child with pid:2699 is died Child with pid:2700 is died
ZOMBIE PROCESS
PROGRAM:
main() { int pid=fork(); system("clear"); printf("my number is %d\n",getpid()); if(pid>0) { printf("My parent number is %d\n",getpid()); sleep(05); }
OUTPUT:
my number is 2716 My parent number is 2716 my number is 2717
void enqueue(); void dequeue(); void list(); while(1) { printf("\n 1...Insert"); printf("\n 2...Delete"); printf("\n 3...Display"); printf("\n 4...Quit"); printf("Enter your choice:"); scanf("%d",&ch); switch(ch) { case 1: enqueue(); break; case 2: dequeue(); break; case 3: list(); break; default: exit(0); } } return 0; } void enqueue()
{ temp=(struct queue*) malloc(sizeof(struct queue)); printf("\nEnter number to be inserted:"); 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; } printf("\n\nElement %d is pushed into queue",temp->no); } void dequeue() { p=head; if(head==NULL) { printf("\n\nQueue is empty"); } else
{ head=head->next; printf("\n\nElement %d is dequeued from queue",p->no); free(p); } } void list() { if(head==NULL) { printf("\n\nQueue is empty"); } else { p=head; printf("\n\nElement present in queue\n"); while(p!=NULL) { printf("%d\t",p->no); p=p->next; } } }
OUTPUT:
1...Insert 2...Delete 3...Display 4...Quit Enter your choice:1 Enter number to be inserted:12 Element 12 is pushed into queue 1...Insert 2...Delete 3...Display 4...Quit Enter your choice:1 Enter number to be inserted:13 Element 13 is pushed into queue 1...Insert 2...Delete 3...Display
4...Quit Enter your choice:1 Enter number to be inserted:14 Element 14 is pushed into queue 1...Insert 2...Delete 3...Display 4...Quit
Enter your choice:2 Element 12 is dequeued from queue 1...Insert 2...Delete 3...Display 4...Quit Enter your choice:3 Element present in queue 13 14