Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Nezer J. Zaidenberg.  Advanced programming for the unix environment (chapters about processes)"— Presentation transcript:

1 Nezer J. Zaidenberg

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

3  Memory  Environment variables  Fd table  Signal handlers

4  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))

5  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

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

7  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))

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

9 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)

10  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.

11  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)

12 Nov 20 04:57:39 89-138-166-80 login[16146]: USER_PROCESS: 16146 ttys000 Nov 20 04:59:35 89-138-166-80 pppd[17475]: Connection terminated. Nov 20 04:59:36 89-138-166-80 pppd[17475]: PPTP disconnecting... Nov 20 04:59:36 89-138-166-80 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 2.4.2 (Apple version 314) started by root, uid 501 Nov 20 04:59:38 Macintosh pppd[16479]: PPTP connecting to server '172.26.255.245' (172.26.255.245)... 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 89.138.196.228 Nov 20 04:59:38 Macintosh pppd[16479]: remote IP address 212.143.205.162

13  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

14  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.


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

Similar presentations


Ads by Google