Socket Programming

Only available on StudyMode
  • Topic: Process, Parent process, Exit
  • Pages : 8 (1283 words )
  • Download(s) : 132
  • Published : February 21, 2013
Open Document
Text Preview
2012/4/13

Socket Programming
BUPT-SE Spring, 2012

Basic Concepts in NP
• Introduction to Network Programming • Program Developing • Basic Concepts – Process – File Descriptor – System Call – Signal

2

1

2012/4/13

Program Developing - Phases
Begin Requirement Analysis Preliminary Design Investigate the requirements Select or develop an algorithm to solve the problem Define data structure Detailed Design Define the format of input and output Draw a flow-chart and module design Input and edit the source program Coding Compile it no errors Testing Running and testing it successful End 3

errors unsuccessful

Program Developing - skills
• Programming style
– – – – ident, remarks, variable names, http://en.wikipedia.org/wiki/Indent_style http://www.cprogramming.com/tutorial/style.html http://courses.cs.vt.edu/~cs2604/fall01/standards.html

• Editor
– vi, a very powerful full screen editor – pico, an utility with Linux – http://www.reallylinux.com/docs/editors/editor.shtml – http://pangea.stanford.edu/computing/unix/editing/editorchoices.php

• Related Linux/Unix command
– http://www.cs.cmu.edu/~gilpin/tutorial/

• Backup your program is important!
4

2

2012/4/13

Program Developing – C Compiler in Linux

• cc
– Example: % cc test1.c -o test – test1.c : program to be compiled – -o : specify the name for running program

• gcc
– Example: % gcc test1.c –o test
5

Program Developing – debugger in Linux

• • •

gdb [options] [executable-file [core file or process-id]] Example: % gdb test1 gdb Command list – – – – – – – – – – – – file : load the program for debugging kill : stop the program for debugging list : list the source code of the program for debugging break : set a break point in the source program run : run the program to be debugged next : execute a single line of the program, but not go into it step : execute a single line of the program, but go into it quit : quit the gdb to shell print : display the value of a variable make : make a run-able program without quiting gdb c : Continue running your program (e.g. at a breakpoint) bt (backtrace) : display the program stack



Reference web: http://www.chinalinuxpub.com/doc/pro/gdb.html 6

3

2012/4/13

Basic Concepts in NP
• Introduction to Network Programming • Program Developing • Basic Concepts – Process – System Call – File Descriptor – Signal

7

Basic Concepts - definition


Process

A process is an instance of a program that is being executed by the operating system. Linux/Unix kernel provides a limited number (typically between 60 and 200) of direct entry points through which an active process can obtain services from the Kernel. A file descriptor is a small integer used to identify a file that has been opened for I/O operation. A signal is a notification to a process that an event has occurred. 8



System Call

File Descriptor





Signal

4

2012/4/13

Basic concepts - process
• One of the most basic abstractions in Unix (the other one is File) • process ≠ program – – – – – Program:a file containing instructions to be executed Process: a part of a program in execution A live entity, it can be created, executed, and terminated. One program can have multiple processes One process can invoke multiple programs

• Alias: task, job

Basic concepts - process
• Process in memory
– Text: program code – Stack: temporary data (local variable, function parameters, return addresses) – Data: global variables – Heap: dynamic allocated memory, malloc()

10

5

2012/4/13

Basic concepts – process
• PID (Process ID): Every process has a unique PID. The PID is an integer, typically in the range 0 through 32,767. • PPID (Parent PID): Every process has a parent process ID. • Special process – PID = 1: init process – PID = 0: special kernel process (e.g., idle/swapper process) – PID = 2: special kernel process (e.g., page daemon process) [root@localhost ~]# ps -ef UID PID...
tracking img