0% found this document useful (0 votes)
2 views2 pages

Implementation of IO System Call in Linux

The document contains two C programs demonstrating system calls in UNIX operating systems. The first program lists the contents of a specified directory using opendir, readdir, and closedir functions. The second program illustrates process creation and management using fork, getpid, and exit functions.

Uploaded by

vishnupriyapacet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Implementation of IO System Call in Linux

The document contains two C programs demonstrating system calls in UNIX operating systems. The first program lists the contents of a specified directory using opendir, readdir, and closedir functions. The second program illustrates process creation and management using fork, getpid, and exit functions.

Uploaded by

vishnupriyapacet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

PROGRAM FOR SYSTEM CALLS OF UNIX OPERATING SYSTEMS


(OPENDIR, READDIR, CLOSEDIR, ETC)

#include<stdio.h>
#include<stdlib.h>
#include<dirent.h>
struct dirent *dptr;
int main(int argc, char *argv[])
{
char buff[100];
DIR *dirp;
printf("\n\n ENTER DIRECTORY NAME");
scanf("%s", buff); if((dirp=opendir(buff))==NULL)
{
printf("The given directory does not exist");
exit(1);
}
while(dptr=readdir(dirp))
{
printf("%s\n",dptr->d_name);
}
closedir(dirp);
}

2.PROGRAM FOR SYSTEM CALLS OF UNIX OPERATING SYSTEM (Fork,


Getpid, Exit, Etc)

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
void main()
{
int pid,pid1,pid2; pid=fork();
if(pid==-1)
{
printf("ERROR IN PROCESS CREATION \n");
exit(1);
}
if(pid!=0)
{
pid1=getpid();
printf("\n the parent process ID is %d\n", pid1);
}
else
{
pid2=getpid();
printf("\n the child process ID is %d\n", pid2);
}
}

You might also like