0% found this document useful (0 votes)
52 views18 pages

UNIX System Calls

This document discusses various Unix system calls related to process control, file management, device management, information maintenance, and communication. It provides examples of common system calls like wait(), signal(), exec(), fork(), read(), write(), and more. It then focuses on the wait() and signal() system calls in more detail. wait() is used to block the calling process until a child process exits. signal() installs a new signal handler for a specific signal. The document includes code examples demonstrating the usage of these two important system calls.

Uploaded by

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

UNIX System Calls

This document discusses various Unix system calls related to process control, file management, device management, information maintenance, and communication. It provides examples of common system calls like wait(), signal(), exec(), fork(), read(), write(), and more. It then focuses on the wait() and signal() system calls in more detail. wait() is used to block the calling process until a child process exits. signal() installs a new signal handler for a specific signal. The document includes code examples demonstrating the usage of these two important system calls.

Uploaded by

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

TOPIC:- Unix system calls, for wait( ), signal (),

etc. example exercise involving the use of above Unix


system calls.
Unix system calls

System calls in Unix are used for file system control,


process control, inter process communication etc.
Access to the Unix kernel is only available through
these system calls. Generally, system calls are
similar to function calls, the only difference is that
they remove the control.
There are around 80 system calls in the Unix interface
currently.
Types of System calls
Here are the five types of system calls used in UNIX :
i. Process Control
ii. File Management
iii. Device Management
iv. Information Maintenance
v. Communication
PROCESS CONTROL SYSTEM CALLS

• These system calls deal with processes such as


process creation, process termination etc.
Process Creation and exec(),fork(), wait(), exit()
Termination
Process Owner and Group getuid(), geteuid(), getgid()
Process Process Identity getpid(), getppid()
Related Process Control signal(), kill(), alarm()
Calls
Change chdir()
Working Directory
File Management System calls

• These system calls are responsible for file manipulation such


as creating a file, reading a file, writing into a file etc.
GENERAL CLASS SPECIFIC CLASS SYSTEM CALL
---------------------------------------------------------------------
File Structure Creating a Channel creat()
Related Calls open()
close()
Input/Output read()
write()
Random Access lseek()
Channel Duplication dup()
Aliasing and Removing link()
Files unlink()
File Status stat()
fstat()
Access Control access()
chmod()
chown()
umask()
Device Control ioctl()
Device Management System calls
• These system calls are responsible for device
manipulation such as reading from device buffers,
writing into device buffers etc.
• Example of Device Management System calls
ioctl()
read()
write()
Information Maintenance System calls

• These system calls handle information and its


transfer between the operating system and
the user program.
• Examples of information maintenance system
calls are
getpid()
alarm()
sleep()
Communication System calls
• These system calls are useful for interprocess
communication. They also deal with creating and
deleting a communication connection.

Interprocess Pipelines pipe()


Communication Messages msgget()
msgsnd()
msgrcv()
msgctl()
Semaphores semget()
semop()
Shared Memory shmget()
shmat()
shmdt()
Wait()
The wait() System Call
•  The system call wait() is easy. This function blocks
the calling process until one of its child processes
exits or a signal is received. For our purpose, we
shall ignore signals.
•  wait() takes the address of an integer variable and
returns the process ID of the completed process.
• Some flags that indicate the completion status of
the child process are passed back with the integer
pointer.
• One of the main purposes of wait() is to wait for
completion of child processes.
• The execution of wait() could have two possible
situations.
i. If there are at least one child processes running when
the call to wait() is made, the caller will be blocked
until one of its child processes exits. At that moment,
the caller resumes its execution.
ii. If there is no child process running when the call
to wait() is made, then this wait() has no effect at all.
That is, it is as if no wait() is there
• The prototype for the wait() system
call is:
  int wait(status)
int *status;
// C program to demonstrate working of wait()
#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<unistd.h>
  
int main()
{
    pid_t cpid;
    if (fork()== 0)
        exit(0);           /* terminate child */
    else
        cpid = wait(NULL); /* reaping parent */
    printf("Parent pid = %d\n", getpid());
    printf("Child pid = %d\n", cpid);
  
    return 0;
}
Output:
Parent pid = 12345678
Child pid = 89546848
SIGNALS
PROCESS INTERACTION WITH SIGNALS
• A signal is an asynchronous event which is delivered to a process.
• Asynchronous means that the event can occur at any time
i. may be unrelated to the execution of the process
ii. e.g. user types ctrl-C, or the modem hangs
• Unix supports a signal facility, looks like a software version of the
interrupt subsystem of a normal CPU
• Process can send a signal to another - Kernel can send signal to a
process (like an interrupt)
• A process can:
a. ignore/discard the signal (not possible with SIGKILL or SIGSTOP)
b. execute a signal handler function, and then possibly resume
execution or terminate
c. carry out the default action for that signalS
THE SIGNAL()SYSTEM CALL
• #include <signal.h>
void (*signal(int sig, void (*handler)(int))) (int);
• The signal()system call installs a new signal
handler for the signal with number signum. The
signal handler is set to sighandler which may be a
user specified function•
EXAMPLE
#include<stdio.h>
#include<signal.h>
  
int main()
{
    signal(SIGINT, handle_sigint);
    while (1)
    {
        printf(“hello world\n”);
        sleep(1);
    }
    return 0;
}

Output
hello world
hello world
hello world
terminated
Thank you

You might also like