Wednesday 31 October 2012

Important System calls

In this post I am going to explain about the important system calls used in Linux. Let us start straight away.

fork():

The famous system call which is used to spawn new processes. When a process calls this function, a child is created which is an exact copy of the parent. The underlying things that happen are explained here.

vfork():

This is just like a fork function call, but initially all the pages are shared between the parent and child and it doesn't follow the copy-on-write rule. This is used in the case when the child process calls exec() directly. This function improves the performance of spawning a new process.

exec():

This overwrites the address space of the calling process with the executable program specified as an argument for this function. There are 6 variations for this function. more from here.

mmap():

This is used to map a file onto the RAM and perform reads and writes from this memory instead of disk. more here

fcntl:

This command is used to perform various operations like duplicating the file descriptors, setting and getting the descriptor flags and much more. see here

fstat:

This is used to retrieve all the details of a file when its name or an open file descriptor is given. Similar versions of this are lstat and stat. more here.

ioctl:

This is used to perform the I/O operations on the devices by directly issuing commands to the device driver. The device controller is by-passed in this case. more here

link:

This system call creates a link to a specified file ( especially hard link). The opposite of this is done by unlink. see more

access:

This function is used to check if there are necessary permissions to perform some operations on a file by a process. view more

chmod:

This is used to change the permission bits associated with a file.(ofcourse the calling process should have appropriate permissions to do that) see more.

chown:

It is used to change the owner of a file provided the process has the permissions to do that.see more

umask:

If you want to change the default permission bits created when we create a new file or directory, then you can use this function call. see here

chroot:

This is used to change the root directory of a process. I mean to say that the path which we give as argument to this function, makes the process to think that the "/" starts from the specified point. more here.

wait:

This function call blocks until one of the child processes exits. Another variation is waitpid in which we can specify the pid of a particular process. Another variation is wait3 which is used to get more details of the terminated process like the resource info etc.check out the man pages.

get**id:

getuid returns the user id, geteuid returns the effective user id, getgid gives group ID, getegid gives the effective group ID, getpid gives process ID, getppid gives parent process ID, getpgrp returns the process group ID.

pause:

This function call gets blocked until a signal is received by a process and after that it returns. Another variation of this is sigpause. see more here

alarm:

This is used to specify some seconds as an argument after which a SIGALRM is sent to the process calling this function.

pipe:

This is used to create a pipe between two related processes and takes an argument as an array of two ints. see more.

popen:

Some variation of pipe is popen. This does all the work to create a pipe and returns a file pointer just like for an open file.

flock:

This is used to lock a file by the process. It can be locked in various modes by using a shared lock or exclusive lock. see more. Another variation of this is lockf in which we use the POSIX locks to lock a file.

mprotect:

This is used to protect(or lock) the memory of a process on the RAM. We can specify different flags to set the desired mode. see more.

setfacl:

This is used to set the file access control lists which are more better than the normal permission bits and increase the security of the file. Inorder to get the file ac. ctrl lists use getfacl. see more.

fsck:

It is used to check and repair a file system. The exit code that it returns, can be used to know the various errors in the file system. see more.

ipcrm:

It removes the msg queues, semaphores, shared memory which have the specified ID as argument. see more. Another function ipcs provides information about the various IPC facilities.

message queues:

The msgget returns an ID which corresponds to a new message queue. msgsnd sends a message into the queue. msgrcv blocks until there is atleast one message in the queue and this is returned. msgctl is used to control various activities of the msg queue. check out the man pages.

shared memory:

shmget returns an ID which corresponds to a shared memory. shmat attaches the memory on to the process address space, while shmdt does the opposite thing. Finally, shmctl is used to control various parameters of the shared memory.


The system calls related to semaphores can be seen here and many other signal related system calls from here.


No comments:

Post a Comment