Nezer J. Zaidenberg.  Advanced programming for the unix environment (chapters about processes)

Slides:



Advertisements
Similar presentations
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Advertisements

Using tcpdump. tcpdump is a powerful tool that allows us to sniff network packets and make some statistical analysis out of those dumps. tcpdump operates.
Syslog and log files1-1 Syslog and Log Files  From logfiles, you can find m important information m History m Errors/warnings  Logging policies m Reset.
Process Relationships Terminal and Network Logins Process Groups and Sessions Job Control Relationships.
CS162B: Daemonization Jacob T.Chan. Foreground Process  Has input/output capabilities  These require users at the terminal  Lives as long as the terminal.
1 Introduction to UNIX 2 Ke Liu
Netprog: daemons and inetd1 Daemons & inetd Refs: Chapter 13.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
Page 1 Task Control: Signals and Alarms Chapter 7 and 8 B. Ramamurthy.
Process Process: the UNIX abstraction of a stand-along computer that manages resources (memory, CPU, I/O resources) comprising a running program. Processes.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process Control in Unix Operating Systems Hebrew University Spring 2004.
Unix Network Programming Chapter 13: Daemon processes and the inetd superserver Jani Peusaari.
Daemon Processes and inetd Superserver
Processes CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Phones OFF Please Processes Parminder Singh Kang Home:
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
1 Network File System. 2 Network Services A Linux system starts some services at boot time and allow other services to be started up when necessary. These.
UNIX Processes. The UNIX Process A process is an instance of a program in execution. Created by another parent process as its child. One process can be.
Unix Processes Slides are based upon IBM technical library, Speaking Unix, Part 8: Unix processes Extended System Programming Laboratory (ESPL) CS Department.
UNIX System Administration Handbook Chapter 4. Controlling Processes 3 rd Edition Evi Nemeth et al. Li Song CMSC691X Summer 2002.
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
Chapter 3 Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes Tarek Abdelzaher Vikram Adve.
Introduction to Processes CS Intoduction to Operating Systems.
Userland summary Nezer J. Zaidenberg. Today’s topics What have we learned - USERLAND summary Revisited topics execXXX functions POSIX cond Daemons Sync.
4P13 Week 1 Talking Points. Kernel Organization Basic kernel facilities: timer and system-clock handling, descriptor management, and process Management.
1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty for every terminal device invokes our login shell terminal.
 Advanced programming for the unix environment (chapters 7,8,9 of both editions + chapter 13(2 nd edition))
Scis.regis.edu ● CS 468: Advanced UNIX Class 4 Dr. Jesús Borrego Regis University 1.
Amir Averbuch Nezer J. Zaidenberg.  Advanced programming for the unix environment (chapters 7,8,9 of both editions + chapter 13(2 nd edition))
Core System Services. INIT Daemon The init process is the patron of all processes. first process that gets started in any Linux/ UNIX -based system.
TELE 402 Lecture 9: Daemon … 1 by Dr Z. Huang Overview Last Lecture –Broadcast and multicast This Lecture –Daemon processes and advanced I/O functions.
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
1 Daemons & inetd Refs: Chapter Daemons A daemon is a process that: –runs in the background –not associated with any terminal Unix systems typically.
Consider Letting inetd Launch Your Application. inetd daemon  Problems starting with /etc/rc(without inet daemon)  All the servers contains nearly identical.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Process Management CS3320 Spring Process A process is an instance of a running program. –Not the same as “program” or “processor” Process provides.
Operating Systems Process Creation
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Concurrent Servers. Idea Behind Concurrent Servers Server Client 1 Server 1 X.
ACCESS CONTROL. Components of a Process  Address space  Set of data structures within the kernel - process’s address space map - current status - execution.
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
UNIX Network Programming1 Chapter 12. Daemon Processes and inetd Superserver.
CSC414 “Introduction to UNIX/ Linux” Lecture 3
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1.
Process Manipulation. Process Manipulation in UNIX Basic process manipulation: creation, program loading, exiting, … fork(), exec(), wait(), exit() Process.
Operating Systems Review ENCE 360.
Chapter 3: Process Concept
Processes A process is a running program.
UNIX PROCESSES.
Example questions… Can a shell kill itself? Can a shell within a shell kill the parent shell? What happens to background processes when you exit from.
Lecture 5: Process Creation
CGS 3763 Operating Systems Concepts Spring 2013
CHAPTER 8 ( , ) John Carelli, Instructor Kutztown University
Introduction to Linux/UNIX
Issues in Client/Server Programming
Daemons & inetd Refs: Chapter 12.
Controlling Processes
CS510 Operating System Foundations
Lab 6: Process Management
Process Description and Control in Unix
Process Description and Control in Unix
System Programming: Process Management
Presentation transcript:

Nezer J. Zaidenberg

 Advanced programming for the unix environment (chapters about processes)

 Memory  Environment variables  Fd table  Signal handlers

 Signals are “software interrupt”  Whenever the OS wants to tell a process something it sends a signal  Signal example : you are about to be killed, you are about to be suspended (both of this cannot be caught), div by 0, segmentation violation etc. (those are often caught by debuggers), child process has terminated or as a response to other system call (wait(2), alarm(2))

 Sigabrt/term please shutdown  Sigkill – kill program (cannot be caught)  SIGUSR1/2 – for user use  Sighup – terminal hanghup (usually used in most servers to re-read conf file)  Sigsusp – suspand program (cannot be caught)  sigio,SIGALRM – generated by select(2), alarm(2)  SIGCHLD(SIGCLD) – child process died

 Wait(2)  Select(2)  Alarm(2)

 Set of parameters that are inherited from process to process.  Getenv(2) setenv(2)  See also in bash(1) set, export in tcsh(1) set, setenv  Usages – set default parameters for all process for example setting EDITOR or VISUAL makes other programs open the editor as default editor (for example cron(8))

 Heap  Stack  Global variables  Program (compiled code)  Ex. (not for submission) – write a class that finds out if it is in the stack, global variable or heap. (Idea by Scott Mayers)  Notable functions malloc(2), free(2), alloca  We will talk about memory management later

Each process has its parent. Several process with common ancestor will have the same process group (the pid of the first parent is the group gid) Processes from the same session have the same session id (session>group>process)  Getpid(2)  Getppid(2)  Setsid(2)

 Daemon – process that does some service for users. (usually process that never returns)  Examples – Apache httpd, Wu-ftpd, and almost any process that ends with “d” you see on ps(1)  In order to make a process daemon make it start his own process group (fork and cause the father to terminate) then lose controlling terminal and fork() again.  Exact code will be shown in ex.

 Losing controlling terminal means that nobody sees I/O messages. Also daemon process runs for very long time. Sometimes we would want to see what happened at a certain moment even if there was nobody at the moment at the computer.  Openlog(3)  Syslog(3) (don’t be mistaken by syslog(1))  Closelog(3)

Nov 20 04:57: login[16146]: USER_PROCESS: ttys000 Nov 20 04:59: pppd[17475]: Connection terminated. Nov 20 04:59: pppd[17475]: PPTP disconnecting... Nov 20 04:59: pppd[17475]: PPTP disconnected Nov 20 04:59:37 Macintosh configd[14]: setting hostname to "Macintosh.local" Nov 20 04:59:38 Macintosh pppd[16479]: pppd (Apple version 314) started by root, uid 501 Nov 20 04:59:38 Macintosh pppd[16479]: PPTP connecting to server ' ' ( )... Nov 20 04:59:38 Macintosh pppd[16479]: PPTP connection established. Nov 20 04:59:38 Macintosh pppd[16479]: Connect: ppp0 socket[34:17] Nov 20 04:59:38 Macintosh pppd[16479]: PAP authentication succeeded Nov 20 04:59:38 Macintosh pppd[16479]: local IP address Nov 20 04:59:38 Macintosh pppd[16479]: remote IP address

 void syslog(int priority, const char *message,...);  void openlog(const char *ident, int logopt, int facility);  void closelog(void);  Syslog output file is usually found in /var/log (usually /var/log/messages under Linux)  Multiple log files and compressed enteries will usually be found this is handled by logrotate(1) which is beyond our scope

 Historically many servers have used the same TCP code. (socket/bind/listen/fork/accept) those same lines of code were replicated  Many times, those files were linked with faulty tcp libraries and faulty tcp connections.  In order to address code reusability and security inetd super server is created  Inetd super server forks a process with its stdin and stdout opened as TCP socket of given port.  As a result coding servers became much easier.