Slip 1: A) //file Exist or Not
Slip 1: A) //file Exist or Not
Slip 1:
A)
//file exist or not
#include<stdio.h>
#include<stdio.h>
#include<dirent.h>
DIR *d;
struct dirent *dir; // pointer for directory entry
if(argc!=2)
{
printf("Invalid Arguments");
exit(0);
}
d=opendir(".");
if(d==NULL)
return(0);
while((dir=readdir(d))!=NULL)
{
if(strcmp(dir->d_name
,argv[1])==0)
printf("File exist");
else
printf("File doesn't exist");
}
closedir(d);
}
Slip 2:
A) Write a C program that uses a string as an argument and return all the files that begin
with that name in the current directory. For example > ./a.out foo will return all file names
that begin with foo.
#include<stdio.h>
#include<dirent.h>
#include<string.h>
int main(int argc, char* argv[])
{
DIR *d;
char *position;
struct dirent *dir;
int i=0;
if(argc!=2)
{
printf("Provide sufficient args");
}
else {
d = opendir(".");
if (d)
{
while ((dir = readdir(d)) != NULL)
{
position=strstr(dir->d_name,argv[1]);
i=position-dir->d_name;
if(i==0)
printf("%s\n",dir->d_name);
}
closedir(d);
}
return(0);
}
}
Slip 3 :
A)Write a C program to find file properties such as inode number, number of hard link,
File permissions, File size, File access and modification time and so on of a given file
using stat() system call.
#include<sys/types.h>
#include<sys/stat.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
struct stat info;
if (argc != 2)
{
printf("Enter filename\n");
}
if (stat(argv[1], &info) == -1)
{
printf("stat erro");
exit(EXIT_FAILURE);
}
printf("I-node number: %ld\n", (long) info.st_ino);
printf("File size: %lld bytes\n",(long long) info.st_size);
printf("Last file access: %s", ctime(&info.st_atime));
printf("Last file modification: %s", ctime(&info.st_mtime));
printf("No of hard links: %d\n",info.st_nlink);
printf("File Permissions: \t");
printf( (info.st_mode & S_IRUSR) ? "r" : "-");
printf( (info.st_mode & S_IWUSR) ? "w" : "-");
printf( (info.st_mode & S_IXUSR) ? "x" : "-");
printf( (info.st_mode & S_IRGRP) ? "r" : "-");
printf( (info.st_mode & S_IWGRP) ? "w" : "-");
printf( (info.st_mode & S_IXGRP) ? "x" : "-");
printf( (info.st_mode & S_IROTH) ? "r" : "-");
printf( (info.st_mode & S_IWOTH) ? "w" : "-");
printf( (info.st_mode & S_IXOTH) ? "x" : "-");
putchar('\n');
}
B) Write a C program to create ‘n’ child processes. When all ‘n’ child processes
terminate, Display total cumulative time children spent in user and kernel mode.
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<time.h>
#include<sys/times.h>
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i, status;
pid_t pid;
time_t currentTime;
struct tms cpuTime;
if((pid = fork())==-1) //start child process
{
perror("\n fork error");
exit(EXIT_FAILURE);
}
else
if(pid==0) //child process
{
time(¤tTime);
printf("\nChild process started at %s",ctime(¤tTime));
for(i=0;i<5;i++)
{
printf("\nCounting= %dn",i); //count for 5 seconds
sleep(1);
}
time(¤tTime);
printf("\nChild process ended at %s",ctime(¤tTime));
exit(EXIT_SUCCESS);
}
else
{
//Parent process
time(¤tTime); // gives normal time
printf("\nParent process started at %s ",ctime(¤tTime));
if(wait(&status)== -1) //wait for child process
perror("\n wait error");
if(WIFEXITED(status))
printf("\nChild process ended normally");
else
printf("\nChild process did not end normally");
if(times(&cpuTime)<0) //Get process time
perror("\nTimes error");
else
{
// _SC_CLK_TCK: system configuration time: seconds clock tick
printf("\nParent process user time= %fn",((double) cpuTime.tms_utime));
printf("\nParent process system time = %fn",((double) cpuTime.tms_stime));
printf("\nChild process user time = %fn",((double) cpuTime.tms_cutime));
printf("\nChild process system time = %fn",((double) cpuTime.tms_cstime));
}
time(¤tTime);
printf("\nParent process ended at %s",ctime(¤tTime));
exit(EXIT_SUCCESS); } }
Slip 4 :
A)Write a C program to find file properties such as inode number, number of hard link,
File permissions, File size, File access and modification time and so on of a given file
using fstat() system call.
#include<unistd.h>
#include<fcntl.h>
#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
int main(int argc, char **argv)
{
if(argc != 2)
return 1;
int file=0;
if((file=open(argv[1],O_RDONLY)) < -1)
return 1;
struct stat fileStat;
if(fstat(file,&fileStat) < 0)
return 1;
printf("Information for %s\n",argv[1]);
printf("---------------------------\n");
printf("File Size: \t\t%d bytes\n",fileStat.st_size);
printf("Number of Hard Links: \t%d\n",fileStat.st_nlink);
printf("File inode: \t\t%d\n",fileStat.st_ino);
//printf("Last file access: %s", ctime(&fileStat.st_atime));
//printf("Last file modification: %s", ctime(&fileStat.st_mtime));
printf("File Permissions: \t");
printf( (S_ISDIR(fileStat.st_mode)) ? "d" : "-");
printf( (fileStat.st_mode & S_IRUSR) ? "r" : "-");
printf( (fileStat.st_mode & S_IWUSR) ? "w" : "-");
printf( (fileStat.st_mode & S_IXUSR) ? "x" : "-");
printf( (fileStat.st_mode & S_IRGRP) ? "r" : "-");
printf( (fileStat.st_mode & S_IWGRP) ? "w" : "-");
printf( (fileStat.st_mode & S_IXGRP) ? "x" : "-");
printf( (fileStat.st_mode & S_IROTH) ? "r" : "-");
printf( (fileStat.st_mode & S_IWOTH) ? "w" : "-");
printf( (fileStat.st_mode & S_IXOTH) ? "x" : "-");
printf("\n");
close(file);
return 0;
}
B) Write a C program to implement the following unix/linux command (use fork, pipe and
exec system call). Your program should block the signal Ctrl-C and Ctrl-\ signal during
the execution. ls –l | wc–l
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<errno.h>
#include<sys/wait.h>
#include<unistd.h>
int main()
{
// array of 2 size a[0] is for // reading and a[1] is for // writing over a pipe
int a[2];
// using pipe for inter process communication
pipe(a);
if(!fork())
{
// closing normal stdout
close(1); // making stdout same as a[1]
dup(a[1]); // closing reading part of pipe // we don't need it at this time
close(a[0]); // executing ls
execlp("ls","ls",NULL);
}
else
{
// closing normal stdin
close(0); // making stdin same as a[0]
dup(a[0]); // closing writing part in parent, // we don't need it at this time
close(a[1]); // executing wc
execlp("wc","wc",NULL);
}
}
Slip 5 :
A) Write a C program to create an unnamed pipe. The child process will write the
following three messages to pipe and the parent process display it. Message1 = “Hello
World” Message2 = “Hello SPPU” Message3 = “Linux is Funny”
#include<stdio.h>
#include<unistd.h>
int main() {
int pipefds[2];
int returnstatus;
char writemessages[3][20]={"Hello World", "Hello SPPU","Linux is
Funny"};
char readmessage[20];
returnstatus = pipe(pipefds);
if (returnstatus == -1) {
Else {
read(pipefds[0], readmessage, sizeof(readmessage));
printf("Parent Process is Reading from pipe – Message 1 is %s\n",readmessage);
Slip 6 :
A) Write a C program to map a given file in memory and display the contain of mapped
file in reverse.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include
<sys/stat.h> #include <fcntl.h> #include <sys/types.h>
struct stat s;
size = s.st_size;
int i;
putchar(c);
int x;
int y = 0; close(fd);
FILE *f1;
f1 = fopen(argv[2], "w+");
for(x = size - 1; x >= 0; x--)
char c;
c = f[x];
fputc(c, f1);
}return 0;
B) Write a C program that behaves like a shell (command interpreter). It has its own
prompt say “NewShell$”. Any normal shell command is executed from your shell by
starting a child process to execute the system program corresponding to the command.
It should additionally interpret the following command. i) list f - print name of all files in
directory ii) list n - print number of all entries iii) list i - print name and inode of all files
#include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<dirent.h>
char *buff,*t1,*t2,*t3,ch;
int pid;
DIR *dir;
if (dir==NULL)
switch(t2)
printf("%s\n",entry->d_name);
break;
case 'n' : while((entry=readdir(dir))!=NULL)
cnt++;
printf("\n%s\t %d",entry->d_name,entry->d_ino);
break;
closedir(dir);
main()
while(1)
{
printf("myshell$");
fflush(stdin);
t1=(char *)malloc(80);
t2=(char *)malloc(80);
t3=(char *)malloc(80);
buff=(char *)malloc(80);
fgets(buff,80,stdin);
sscanf(buff,"%s %s %s",t1,t2,t3);
if(strcmp(t1,"pause")==0)
exit(0);
else if(strcmp(t1,"list")==0) list(t2[0],t3);
else
{ pid=fork(); if(pid<0)
execlp("/bin",NULL);
if(strcmp(t1,"exit")==0)
exit(0); system(buff);
}
Else
{
wait(NULL); exit(0);
}}}}
Slip 7 :
int main(void)
int fd;
if (write(fd, buf1, 7) != 7)
printf("buf1 write error");
lseek(fd,100,SEEK_CUR);
B) Write a C program which display the information of a given file similar to given by the
unix /linux command on current directory (l.e File Access permission, file name, file type,
User id, group id, file size, file access and modified time and so on) ls –l DO NOT simply
exec ls -l or system command from the program
Slip 8 :
A) Write a C program to get and set the resource limits such as files, memory associated
with a process.
#include <stdio.h>
#include <sys/resource.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main() {
if( getrlimit(RLIMIT_NOFILE, &old_lim) == 0) printf("Old limits -> soft limit= %ld \t"" hard limit= %ld \n",
old_lim.rlim_cur,old_lim.rlim_max);
else
lim.rlim_max = 1024;
else
return 0;
B) Write a C program which receives file names as command line arguments and display
those filenames in ascending order according to their sizes. (e.g $ a.out a.txt b.txt c.txt,
…)
structfilelist
charfname[100]; intfsize;
};
dp=opendir("./"); if (dp!=NULL)
while(ep=readdir(dp))
if((strcmp(ep->d_name,argv[i]))==0)
stat(ep->d_name,&sb); strcpy(f1[j].fname,ep->d_name);
f1[j].fsize=sb.st_size;
j++;
Break; } } }
(void)closedir(dp);
for(i=0;i<j;i++)
for(k=0;k<=j;k++)
{
if(f1[i].fsize< f1[k].fsize)
{
temp=f1[k]; f1[k]=f1[i]; f1[i]=temp;
}}}
for(i=0;i<j;i++)
printf("%s\t%d\n",f1[i].fname,f1[i].fsize);
return 0;
/*[root@localhostsppuslipquestions]# cc slip20.c
[root@localhostsppuslipquestions]# ./a.out slip12.c a1.c
Slip 9 :
#include <stdio.h>
int i;
for (i = 0; envp[i] != NULL; i++)
{
printf("\n%s", envp[i]);
}
/* set environment variable _EDC_ANSI_OPEN_DEFAULT to "Y"*/
setenv("_EDC_ANSI_OPEN_DEFAULT","Y",1);
printf("program1_EDC_ANSI_OPEN_DEFAULT = %s\n", (x !=
NULL) ? x : "undefined");
}
B) Write a C program that will only list all subdirectories in
alphabetical order from current directory.
while (i<n) {
free(namelist);
} }
Slip 10 :
A)Write a C program to display statistics related to memory allocation
system. (Use mallinfo() system call)
#include <malloc.h>
#include "tlpi_hdr.h"
static void
display_mallinfo(void)
{
struct mallinfo mi;
mi = mallinfo();
char *alloc[MAX_ALLOCS];
numBlocks = atoi(argv[1]);
blockSize = atoi(argv[2]);
freeStep = (argc > 3) ? atoi(argv[3]) : 1;
freeBegin = (argc > 4) ? atoi(argv[4]) : 0;
freeEnd = (argc > 5) ? atoi(argv[5]) : numBlocks;
display_mallinfo();
exit(EXIT_SUCCESS);
}
B) Write a C program which creates two files. The first file should have read and
write permission to owner, group of owner and other users whereas second file
has read and write permission to owner(use umask() function). Now turn on
group-id and turn off group execute permission of first file. Set the read
permission to all user for second file (use chmod() function).
#include "apue.h"
#include <fcntl.h>
#define RWRWRW
(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
int main(void)
{
umask(0);
if (creat("foo", RWRWRW) < 0)
err_sys("creat error for foo");
#include "apue.h"
int main(void)
Slip 11:
// last.
};
s->stud_id = id;
s->struct_size
= (sizeof(*s)
+ sizeof(char) * strlen(s->stud_name));
return s;
"Allocated_Struct_size: %d\n\n",
printStudent(s1); printStudent(s2);
// size in bytes
// size in bytes
B) Write a C program that behaves like a shell (command interpreter). It has its own
prompt say “NewShell$”. Any normal shell command is executed from your shell by
starting a child process to execute the system program corresponding to the
command. It should additionally interpret the following command. i) count c - print
number of characters in file ii) count w - print number of words in file iii) count l - print
number of lines in file
int pid;
int charcount=0,wordcount=0,linecount=0;
if((fp=fopen(t3,"r"))==NULL)
printf("File not found");
else
{
while((ch=fgetc(fp))!=EOF)
{
if(ch==' ') wordcount++;
else if(ch=='\n')
{
linecount++; wordcount++;
}
Else charcount++; }
fclose(fp);
if(strcmp(t2,"c")==0)
printf("The total no. of characters :%d\n",charcount);
else if(strcmp(t2,"w")==0)
printf("The total no. of words :%d\n",wordcount);
else if(strcmp(t2,"l")==0)
printf("The total no. of lines :%d\n",linecount);
else
}}
main()
while(1)
{
printf("myshell$"); fflush(stdin);
t1=(char *)malloc(80);
t2=(char *)malloc(80);
t3=(char *)malloc(80);
buff=(char *)malloc(80);
fgets(buff,80,stdin);
sscanf(buff,"%s %s %s",t1,t2,t3);
if(strcmp(t1,"pause")==0)
exit(0);
else if(strcmp(t1,"count")==0)
count(t2,t3);
else
{ pid=fork();
if(pid<0)
}}}}
/*
myshell$ls
*/
Slip 12:
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include<signal.h>
#include<sys/types.h>
#include<sys/wait.h>
#include <stdlib.h>
void Dingdong()
{
printf("Ding!");
exit(1);
{ if(argc!=3)
int PauseSecond=(argv[1]);
if(fork()==0)
} } }
B) Write a C program to display all the files from current directory and its
subdirectory whose size is greater than ’n’ Bytes Where n is accepted from user
through command line.
Slip 13:
A) Write a C program that redirects standard output to a file output.txt. (use of dup
and open system call).
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h>
int main(void){
int number1,number2, sum;
int input_fds = open("./input.txt", O_RDONLY);
if(dup2(input_fds, STDIN_FILENO) < 0) {
printf("Unable to duplicate file descriptor.");
exit(EXIT_FAILURE);
}
scanf("%d %d",&number1,&number2);
sum = number1 + number2;
printf("%d + %d = %d\n", number1, number2, sum);
return EXIT_SUCCESS;
B) Write a C program that behaves like a shell (command interpreter). It has its
own prompt say “NewShell$”. Any normal shell command is executed from your
shell by starting a child process to execute the system program corresponding
to the command. It should additionally interpret the following command. i)
typeline +10 - print first 10 lines of file ii) typeline -20 - print last 20 lines of file
iii) typeline a - print all lines of file
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
char *buff,*t1,*t2,*t3,ch;
FILE *fp;
int pid;
int i,n,count=0,num;
if((fp=fopen(t3,"r"))==NULL)
if(strcmp(t2,"a")==0)
{ while((ch=fgetc(fp))!=EOF) printf("%c",ch);
fclose(fp);
return;
n=atoi(t2);
if(n>0)
i=0;
while((ch=fgetc(fp))!=EOF)
if(ch=='\n') i++;
if(i==n)
break; printf("%c",ch);
}
printf("\n");
else
count=0;
while((ch=fgetc(fp))!=EOF)
if(ch=='\n')
count++;
fseek(fp,0,SEEK_SET);
i=0;
while((ch=fgetc(fp))!=EOF)
if(ch=='\n') i++;
if(i==count+n-1)
break;
}
while((ch=fgetc(fp))!=EOF)
printf("%c",ch);
fclose(fp);
main()
{ while(1)
printf("myshell$");
fflush(stdin);
t1=(char *)malloc(80);
t2=(char *)malloc(80);
t3=(char *)malloc(80);
buff=(char *)malloc(80); fgets(buff,80,stdin);
sscanf(buff,"%s %s %s",t1,t2,t3);
if(strcmp(t1,"pause")==0)
exit(0);
else if(strcmp(t1,"typeline")==0)
typeline(t2,t3);
else
{
pid=fork();
if(pid<0)
printf("Child process is not created\n");
else if(pid==0)
execlp("/bin",NULL);
if(strcmp(t1,"exit")==0)
exit(0);
system(buff);
}
Else
{
wait(NULL);
exit(0);
}}}}
dyp gm
#a.c# a.out ass2 a.txt b.c count.c list.c search.c s.txt typeline.c
myshell$pause
*/
Slip 14:
A) Write a C program to create an unnamed pipe. Write following three
messages to pipe and display it. Message1 = “Hello World” Message2 = “Hello
SPPU” Message3 = “Linux is Funny”
#include<stdio.h>
#include<unistd.h>
int main() {
int pipefds[2];
int returnstatus;
char writemessages[3][20]={"Hello World", "Hello SPPU","Linux is Funny"};
char readmessage[20];
returnstatus = pipe(pipefds);
if (returnstatus == -1) {
Else {
read(pipefds[0], readmessage, sizeof(readmessage));
printf("Parent Process is Reading from pipe – Message 1 is %s\n",readmessage);
int pid;
void search(char *t2,char *t3,char *t4)
{ if(strcmp(t2,"f")==0)
{ while(fgets(buff,80,fp))
if((strstr(buff,t3))!=NULL)
} i++;
}
else if(strcmp(t2,"c")==0)
while(fgets(buff,80,fp))
if((strstr(buff,t3))!=NULL)
{
count++;
}
}
else if(strcmp(t2,"a")==0)
while(fgets(buff,80,fp))
if((strstr(buff,t3))!=NULL)
{
printf("%d: %s\n",i,buff);
i++;
}
else
fclose(fp);
}
main()
while(1)
printf("myshell$"); fflush(stdin);
t1=(char *)malloc(80);
t2=(char *)malloc(80);
t3=(char *)malloc(80);
t4=(char *)malloc(80);
buff=(char *)malloc(80);
fgets(buff,80,stdin);
sscanf(buff,"%s %s %s %s",t1,t2,t3,t4);
if(strcmp(t1,"pause")==0)
exit(0);
else if(strcmp(t1,"search")==0)
search(t2,t3,t4);
else
{ pid=fork();
if(pid<0)
printf("Child process is not created\n"); else if(pid==0)
{ execlp("/bin",NULL); if(strcmp(t1,"exit")==0)
exit(0); system(buff);
Else {
wait(NULL); exit(0); } } } }
/*
3: tybcs aa dyp
5: dyp gm myshell$ls
myshell$pause
*/
Slip 15 :
B) Write a C program which creates a child process and child process catches a
signal SIGHUP, SIGINT and SIGQUIT. The Parent process send a SIGHUP or
SIGINT signal after every 3 seconds, at the end of 15 second parent send
SIGQUIT signal to child and child terminates by displaying message "My Papa
has Killed me!!!”.
#include<stdio.h>
#include<signal.h>
#include<stdlib.h>
void sighup();
void sigint();
void sigquit();
main()
{
int pid,i,j,k;
if ((pid = fork() ) < 0)
perror("fork");
exit(1);
}
if ( pid == 0)
signal(SIGHUP,sighup);
signal(SIGINT,sigint);
signal(SIGQUIT,sigquit);
for(;;);
}
else
{ j=0;
for(i=1;i<=5;i++)
{ j++;
printf("PARENT: sending SIGHUP Signal : %d\n",j);
kill(pid,SIGHUP);
sleep(3);
sleep(3);
}
void sighup()
signal(SIGHUP,sighup);
void sigint()
{
signal(SIGINT,sigint);
printf("Child: I have received sighINT\n");
void sigquit()
{
printf("My daddy has killed me\n");
exit(0);
}
Slip 16 :
A)Write a C program that catches the ctrl-c (SIGINT) signal for the first time and
display the appropriate message and exits on pressing ctrl-c again.
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <signal.h>
{
printf("You have presses Ctrl-C , please press again to exit");
(void) signal(SIGINT, SIG_DFL);
int main()
while(1)
{ printf("Hello World!”);
sleep(1);
return(0);
{
char d[50];
if(argc==2)
bzero(d,sizeof(d));
strcat(d,"ls ");
strcat(d,"> ");
strcat(d,argv[1]); system(d);
else
/*output:-
Slip 17:
A) Write a C program to display the given message ‘n’ times. (make a use
of setjmp and longjmp system call)
#include <stdio.h>
#include <setjmp.h>
jmp_buf buf;
main() {
int x = 1,n;
setjmp(buf); //set the jump position using buf
printf("Hello"); // Prints a msg
x++;
B) Write a C program to display all the files from current directory which are
created in a particular month.
#include<stdio.h>
#include<dirent.h>
#include<string.h>
#include<sys/stat.>
#include<time.h>
#include<stdlib.h>
{
char in[100],st[100],*ch,*ch1,c,buff[512];
DIR *dp;
int i; structdirent *ep;
struct stat sb;
charmon[100];
dp=opendir("./");
if (dp != NULL)
while(ep =readdir(dp))
if(stat(ep->d_name,&sb) == -1)
perror("stat");
exit(EXIT_SUCCESS);
strcpy(mon,ctime(&sb.st_ctime));
ch=strtok(mon," ");
ch=strtok(NULL,",");
ch1=strtok(ch," ");
if((strcmp(ch1,argv[1]))==0)
printf("%s\t\t%s",ep->d_name,ctime(&sb.st_ctime));
} }
(void)closedir(dp); }
return 0;
/*
[root@localhostUnix]# cc month.c
[root@localhostUnix]# ./a.out Mar
a.out Fri Mar 20 22:15:23
2020
. Fri Mar 20 22:15:23 2020
*/
Slip 18 :
A) Write a C program to display the last access and modified time of a given file
{
char filename[] = "c:\\test.txt";
char timeStr[ 100 ] = "";
struct stat buf;
time_t ltime;
char datebuf [9];
char timebuf [9];
if (!stat(filename, &buf))
{
else
_strtime(timebuf);
_strdate(datebuf);
);
return 0;
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include<errno.h>
#include<sys/wait.h>
#include <unistd.h>
int main(){
if(!fork())
Slip 19 :
A) Write a C program to move the content of file1.txt to file2.txt and remove the
file1.txt from directory.
#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#define buffersize 10000
int main()
{
ssize_t read_in,write_out; //Number of bytes returned by single read and write operation
printf(“Enter source file name”);
scanf(“%s”,&source);
printf(“%s”,source);
int sourcefiledesc = open(source,O_RDONLY); //Source file open in read only mode
if(sourcefiledesc < 0 )
}
else
write_out = write(destfiledesc,&buffer,read_in);
if (remove(sourcefiledesc) == 0)
printf("File Deleted successfully");
else
return 0;
Slip 20 :
A) Write a C program that print the exit status of a terminated child process.
/#include <stdio.h>
#include <stdlib.h> #include <unistd.h> #include <sys/types.h>
#include <sys/wait.h>
// Driver code
int main(void)
int status;
if ( WIFEXITED(status) )
{
int exit_status = WEXITSTATUS(status);
printf("Exit status of the child was %d\n",exit_status);
return 0;