Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

과목 소개

- 교재, 연구실, 그레이더


- 네트워크 프로그램 기법
- Unix / Windows / MAC
- 판서, 프로그램 슬라이드, 실습, 프로젝트

과목의 의의
- 네트워크 프로그램 이해, 개발
- 통신 및 관련 응용 프로토콜 이해
- C 프로그램 숙련, 고도화된 대형 프로그램 개발 능력 배양
- OS (kernel) 구현 이해

그림 1.2 Server handling multiple clients at the same time


Protocol Independent Code
- IPv4 vs IPv6

Error Code Wrapping


- Different Versions of Clients and Servers for the Same Service
int debug = 1;
char *progname;
main (int argc, char *argv[ ]) {
int i;
char *ptr, *malloc( );

progname = argv[0];
printf(“argc = %d\n”, argc);
for (i=0; i<argc; i++) {
prt = malloc(strlen(argv[i]+1);
strcpy(ptr, argv[i]);
if (debug)
printf(“%s\n”, ptr);
}
}

User context kernel context

Stack Kernel data

Heap
Uninitialized data
Initialized read-write data
Initialized read-only data

Text (code)

kernel context
info required to keep track of the process & to stop and restart the process
CPU registers corresponding to the process, physical memory location and size of the
process, etc
Process table (process context)
Process id, etc
Environment list
main (int argc, char * argv[], char * envp[]) {
int j;
for( j=0; envp[ j]!= (char *) 0; j++)
printf(“%s\n”, envp[ j]);
exit(0);
}

Variable = string

HOME = …..
SHELL = …..
TERM = …….
USER = …..
PATH = ……

char * getenv() // C library function

Info required for process


- Process id
 int getpid() // system call
- Parent process id
- User id
 Unsigned short getuid()
 /etc/passwd
- Group id
 Unsigned short getgid()
- Superuser : user id = 0
- File descriptor
 Integer for opened files for I/O
 0,1,2, for stdin, stdout, stderror
- Socket descriptor
- (opened) file attributes
 #include <sys/types.h>
#include <sys/stat.h>
Int stat (char *pathname, struct stat *buf);
Int fstat(int filedescriptor, struct stat *buf);

File types
Regular file (ordinary file)
Directory file (names & i-nodes)
Character special file, block special file = I/O devices
Fifo = named pipe
Symbolic link = file containing the pathname of another file
socket

Input and Output


(1) System call
(2) C library function

System calls for I/O


int open (char *pathname, int oflag, …)
int creat (char *pathname, int mode)
int close (int filedescriptor)
int read (int fildes, char *buf, unsigned int nbytes)
int write (int fildes, char *buf, unsigned int nbytes)
long lseek (int fildes, long offset, int whence)
int dup (int fildes)
int fcntl (int fildes, int cmd, int arg)
to change the properties of an open file
int ioctl (int fildes, unsigned long request, char *arg)
to change the behavior of an open file
User process

User or library function

call return

User’s main() function

call return
exit( ) _exit( )
C start off routine C exit routine C _exit routine

program invocation : exec( ) system call

Kernel

kernel passes argument list (and environment list) to main( ) on its initial stack

system call
- User program interface to get services from OS
- In Unix, interface implemented in the form of C function
cf) C library function vs system call
- a few hundred of system calls in Unix
- usually returns -1 if error (vs system int variable errno in <error.h>)

You might also like