140 likes | 293 Views
Minix editors. Mined - (mined) is a simple screen editor. Elle - (elle) is a clone of Emacs. Elvis - (elvis, ex, vi) is a clone of vi. Minix System Calls. System calls are an interface between the operating system and the application programs. Minix has 53 system calls.
E N D
Minix editors • Mined - (mined) is a simple screen editor. • Elle - (elle) is a clone of Emacs. • Elvis - (elvis, ex, vi) is a clone of vi. CPSC 451 Editors and Systems Calls
Minix System Calls • System calls are an interface between the operating system and the application programs. • Minix has 53 system calls. • Posix standard specifies a number of procedures that a conformant system must supply without stating if these are system calls, library calls or something else. CPSC 451 Editors and Systems Calls
System calls description • Manual pages include a name, synopsis and description of each system call. • E.g., to find out about the fork system call use: • man fork • For very detail description of system calls check man pages on titan. CPSC 451 Editors and Systems Calls
Process Management System Calls • These are the calls that provide for process: • creation • execution • termination • suspending of a process • resizing of process data segment • obtaining process id and group. CPSC 451 Editors and Systems Calls
Process management calls- fork () • #include <sys/types.h> • #include <unistd.h> /* include files */ • pid_t fork(void); /* synopsis */ The fork() function creates a new process. The new process (child process) is an exact copy of the calling process. Upon successful completion, fork() returns 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, (pid_t)-1 is returned to the parent process and no child process is created. CPSC 451 Editors and Systems Calls
Example of fork usage #include <lib.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> if (fork() == 0) { printf("After fork, child process %d, group %d.\n", getpid(), getpgrp()); } else {printf("After fork, parent process %d, group %d.\n” ,getpid(),getpgrp()); } CPSC 451 Editors and Systems Calls
Process management calls- waitpid • #include <sys/types.h> • #include <sys/wait.h> • pid_t waitpid(pid_t pid, int *stat_loc, int options); waitpid() suspends the calling process until one of its children changes state (e.g. exits or terminates) if a child process changed state, prior to the call to waitpid(), return is immediate. pid specifies a set of child processes for which status is requested. CPSC 451 Editors and Systems Calls
Process management calls- execve • #include <unistd.h> • int execve (const char *path, char *const argv[], char *const envp[]); • The execve function overlays a new process image on an old process. The new process image is constructed from an ordinary, executable file. This file is either an executable object file, or a file of data for an interpreter. There can be no return from a successful call to one of these functions because the calling process image is overlaid by the new process image. CPSC 451 Editors and Systems Calls
Process management callsexit, size, brk, getpid • exit(status) - terminates process execution and returns status • size=brk(data) - gets and sets the data segment • getpid() - returns caller’s process id • getgid() - returns caller’s group id CPSC 451 Editors and Systems Calls
Signals • Signals handle unplanned inter-process communication events. • E.g. if the user wants to interrupt current event such as editing a long file, she should be able to press a specified key to do it. • When a signal is send to process that does not have a signal handling routine, either the process is killed or the signal is ignored. CPSC 451 Editors and Systems Calls
Signals -sigaction #include <signal.h> int sigaction(int sig, const struct sigaction *act, struct sigaction *oact); (struct sigaction is a structure defined in signal.h) The sigaction() function allows the calling process to examine or specify the action to be taken on delivery of a specific signal. CPSC 451 Editors and Systems Calls
Example of signal handler #include <signal.h> ... void termination_handler (int signum) { ... struct temp_file *p; for (p = temp_file_list; p; p = p->next) unlink (p->name); } CPSC 451 Editors and Systems Calls
int main(void) { struct sigaction new_action, old_action; /* Set up the structure to specify the new action. */ new_action.sa_handler = termination_handler; new_action.sa_flags = 0; sigaction (SIGINT, NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (SIGINT, &new_action, NULL); ..} CPSC 451 Editors and Systems Calls
Signals-sigprocmask, sigpending, sigsuspend, kill, alarm, pause • sigprocmask(how,&set, &old)- examines or changes signal mask • sigpending(set) - gets the set of blocked signals • sigsuspend(sigmask) - replaces the signal mask and suspends the process • kill(pid,sig) - sends a signal to a process • alarm(seconds) - sets the alarm • pause() - suspends the caller until the next signal CPSC 451 Editors and Systems Calls