linux系统和网络编程

fcntl.h


int open(const char * pathname , int flags);
int open(const char * pathname, int flags, mode_t mode);

unistd.h


pid_t fork(void);
如果 fork()调用成功,就会使内核建立一个新的进程,所建的新进程是调用 fork()的进程的副本。新建立的进程被成为子进程(child process),那个调用 fork()建立此新进程的进程被称为父进程(parent process)。以后,父进程与子进程就并发执行,它们都从fork()调用后的那句语句开始执行。父进程中返回子进程pid,子进程中返回0,出错返回-1


int execl(const char * path, const char * arg, ...);
int execlp(const char * file, const char * arg, ...);
int execle(const char * path, const char * arg, ..., char * const envp[]);
int execv(const char * path, char * const argv[]);
int execvp(const char * file, char * const argv[]);
exec 系列中的系统调用都完成相同的功能,它们把一个新程序装入调用进程的内存空间,来改变调用进程的执行代码,从而形成新进程。如果 exec 调用成功,调用进程将被覆盖,然后从新程序的入口开始执行。这样就产生了一个新的进程,但是它的进程标识符与调用进程相同。如果 execl返回,说明调用失败

execl(“/bin/ls”,”ls”,”-l”,NULL); //ls -l  第一个参数描述命令path 
char* av[]={"ls","-l",NULL};
execv("/bin/ls",av); //ls -l

execl(“ls”,”ls”,”-l”,NULL);
char* argin[]={"ls", "-l", NULL};
execvp(argin[0],argin); // ls -l;
//execlp 和 execvp 的区别是不用完整path,会在系统path环境变量中搜索

void _exit(int status);
接使进程停止运行,清除其使用的内存空间,并销毁其在内核中的各种数据结构


sys/wait.h


int wait(int *status);
父进程一旦调用了wait就立即阻塞自己,由wait自动分析是否当前进程的某个子进程已经退出,如果让它找到了这样一个已经变成僵尸的子进程,wait就会收集这个子进程的信息,并把它彻底销毁后返回;如果没有找到这样一个子进程,wait就会一直阻塞在这里,直到有一个出现为止。返回子进程pid和子进程返回值status


stdlib.h


void exit(int status);
比 _exit() 多做一些事情,清理I/O缓冲


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
broadcast icmp jiqiao multi_broad raw sys_net_ml tcp1 term thread udp cap io mul_thread_download qq sem tcp tcp_dos testerr time wav ./broadcast: broad.h client.c server server.c ./cap: capture_packet capture_packet.c ./icmp: icmp.c ./io: aa ba conf filename.c fwrite.c print.c scandir.c setvbuf test tree1.c vprintf ab bb conf.c fwrite print scandir server.conf setvbuf.c tree tree.c vprintf.c ./io/test: a abb b c d ./io/test/d: e f g ./jiqiao: client client.c udp_server udp_server.c ./mul_thread_download: down.c download download-注释.c readme.txt ./multi_broad: client.c mul.h server.c ./qq: ansi_code.c client gen_single_nohead_pre.c Makefile server tcp.h ansi_code.h client.c gen_single_nohead_pre.h play_sub.c server.c ansi_code.o client.o gen_single_nohead_pre.o play_sub.h server.o ./raw: gethostbyname.c ping1.c ping.c zs.c ./sem: semget_1.c semget.c ./tcp: fork qq simple ./tcp/fork: client client.c server server.c tcp.h ./tcp/qq: client client.c gen_single_nohead_pre.h server.c client1.cv gen_single_nohead_pre.c server tcp.h ./tcp/simple: client client.c makefile server server.c tcp.h ./tcp1: fork ftp simple simple1 ./tcp1/fork: client.c server.c tcp.h ./tcp1/ftp: client.c ftp.h server.c ./tcp1/simple: client client.c makefile server server.c tcp.h ./tcp1/simple1: client1.c client2.c client.c server1.c server2.c server.c ./tcp_dos: tcp_dos tcp_dos.c ./term: getpass getpass.c gets gets.c translate ./term/translate: ansi_code.c ansi_code.o chin.c dict dict.o glist.c glist.o input.h Makefile ansi_code.h chin ciku.dict dict.c glist1.c glist.h input.c input.o tags ./testerr: testerr_copyclient.c testerr_copyserver.c testerrno_copyserver1.c ./thread: aa bping.c hello pthread_attr.c pthread_create pthread_mutex.c while.c aa.c chain hello.c pthread_attr.s pthread_create1.c pthread_rwlock aa.h cond pthread_attr pthread_cond pthread_create.c pthread_rwlock.c bping cond.c pthread_attr1.c pthread_cond.c pthread_mutex while ./thread/chain: chain_queue.c chain_queue_hanoi chain_queue.o hanoi.c main.c chain_queue.h chain_queue_hanoi.c hanoi main ./time: asctime ctime gettimeofday strftime time time.c asctime.c ctime.c gettimeofday.c strftime.c timea.c ./udp: client client_echo client_loop reliable_udp server_echo.c server_loop.c udp_server client1 client_echo.c client_loop.c server server_hello stack client1.c client_hello htonl server.c server_hello.c stack.c client.c client_hello.c htonl.c server_echo server_loop ts ./udp/reliable_udp: reliable_recv reliable_recv_std reliable_send reliable_send_std reliable_recv.c reliable_recv_std.c reliable_send.c reliable_send_std.c ./wav: exec line.c lrc_display makefile play.c playwav.c setitimer1.c getline llist.c lrc_display.c mp3 play_sub.c playwav.h setitimer.c getline.c llist.h main.c play play_sub.h setitimer ./wav/mp3:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值