Socket Programming

Topics: Process, Parent process, Exit Pages: 8 (1283 words) Published: February 21, 2013

Socket Programming
BUPT-SE Spring, 2012

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




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,

• Editor
– vi, a very powerful full screen editor – pico, an utility with Linux – –

• Related Linux/Unix command

• Backup your program is important!



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

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: 6



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


Basic Concepts - definition


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




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




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...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Socket Programming: UDP Essay
  • Socket Programming Essay
  • Client / Server Programming with Tcp/Ip Sockets Essay
  • Essay about Network Programming with Sockets
  • smart socket Essay
  • Essay on Network Programming Project Report
  • It Programming Essay
  • Computer Programming Research Paper

Become a StudyMode Member

Sign Up - It's Free