systemcalls
TRANSCRIPT
-
8/12/2019 SystemCalls
1/15
System Calls
-
8/12/2019 SystemCalls
2/15
Definition Services provided by OS
Communication interface betweenapplication program and kernel
System Calls codes built inside kernel
Examples
open(),close(),create()
-
8/12/2019 SystemCalls
3/15
Categories System Call for File management
System call for Process management System call for Communication
System call for Device management
System call for information retrieving
Examples: access(),creat(),pipe(),open(),close(),fork(),
exec(), write(), read(), time(), date()
-
8/12/2019 SystemCalls
4/15
Seeing manual pages man 2 function/system call name
man 3 function for library functionmanuals
man function/system call/commandGeneral manual pages
-
8/12/2019 SystemCalls
5/15
Creating a file vi filename.c
Or
vim filename.c for C program creation
-
8/12/2019 SystemCalls
6/15
Linux basic Commands cc filename.cto compile c programs which create
default out put a.out.
lslist files equivalent to dir in DOS
lllist with showing the permission and link
cat > filename -to write to a file ctrl+ D to exit
cat < filename / cat filenameto view content of file
clear- to clear the shell
mkdir-cerate a directory
rmremove file
See man pages for details
-
8/12/2019 SystemCalls
7/15
access System call used to check users permission
For help use #man 2 access
R_OK -> file readable or not F_OK -> file existing or not
Edit permissions with chmod ugo-r f1
u- user ggroup
oothers
-
8/12/2019 SystemCalls
8/15
accessexample#include #include
main(){access(fil,F_OK);perror(perror);
}Note: perror will print the system error message of errnoeg: perror: No such file or directory
-
8/12/2019 SystemCalls
9/15
Errors (256 errors)
0 to125 - are system error
126 to 255Unknown error
-
8/12/2019 SystemCalls
10/15
-
8/12/2019 SystemCalls
11/15
Create Example fd = create(argv[i],0666);
fdis an integer to use with read or write
to the specified file 0666indicates read+write to all users
(ugo)
-
8/12/2019 SystemCalls
12/15
Open() SYNOPSIS #include
#include #include
int open(const char *pathname, int
flags); int open(const char *pathname, int
flags, mode_t mode);
-
8/12/2019 SystemCalls
13/15
Open() Given a pathname for a file, open() returns a
file descriptor, a small, non-negative integer for usein subsequent system calls
(read(2), write(2), lseek(2), fcntl(2), etc.). The filedescriptor returned by a successful call will be thelowest-numbered file
descriptor not currently open for the process.
A call to open() creates a new open file description,an entry in the system-wide table of open files. Thisentry records the file
-
8/12/2019 SystemCalls
14/15
The parameter flags must include oneof the following access modes:O_RDONLY, O_WRONLY, or O_RDWR.These request opening the file read-
only, write-only, or read/write,respectively.
-
8/12/2019 SystemCalls
15/15
Library functions Library function can be called from user
application programs
Proper header files are to be included Header files defines the proper system call for
each library function call.
Examples- related to file managementoperation
Fopen(),fclose(),fprintf(),fgets(),fputc() etc.
man 3 function name