学习linux多线程编程 相关概念
学习Linux多进程编程
一、进程的定义:程序执行和资源管理的最小单位。
二、进程控制:
(1)进程标识: 进程标识 子进程号 父进程号
头文件 #include<unistd.h> #include<unistd.h>
函数功能 取得当前进程的进程号 取得当前进程的父进程号
函数原型 Pid_t getpid(void) Pid_t getppid(void)
函数返回值 成功返回进程的进程标识符 成功返回父进程的进程标识符
注:Pid_t其实是一个typedef类型,相当于unsigned int.
例:
#include<stdio.h>
#include<unistd.h>
int main()
{
printf("系统分配的进程号是:%d\n",getpid());
printf("系统分配的父进程号是:%d\n",getppid());
return 0;
}
(2)进程的创建:
1)exec族函数:
头文件 #include<unistd.h>
原型
int execl(const chat *path,const char *args,...)
int execv(const char *path,char const *argv[])
int execle(const cahr *path,const char *arg,...,char *const envp[])
int execve(const char *path,char *const argv[],char *const envp[])
int execlp(const char *file,char *arg,...)
int execvp(const cahr *file,char *const argv[])
返回 返回-1表示出错
由于比较多,在此只举例execve函数:
#include<stdio.h>
#include<unistd>
int main()
{
char *args[]={"/usr/bin/vim",NULL};
printf("系统分配的进程号是:%d\n",getpid());
if(execve("/usr/bin/vim",args,NULL)<0)
perror("创建进程出错!");
return 0;
}
注:在用execve函数创建新进程的后,会以新的程序取代原来的进程,然后系统会从新的进程运行,但是新的进程的PID值会与原来进程的PID值相同.
2)system()函数
头文件 #include<stdlib.h>
功能 在进程中开始另一个进程
原型 int system(const char *string)
传入值 系统变量
返回值
成功则返回执行shell命令后的返回值,调用/bin/sh数百返回127,其他
失败返回-1,三叔string为空返回非零值
&nb
相关文档:
在linux中,当我们因为需要新添加一块硬盘,或者是我们swap交换分区空间不够,需要增加,我们怎么来处理呢?首先,找一块新硬盘,在断电的情况下接入,启动计算机,接就进行如下操作:
一、新增磁盘分区、格式化
首先用fdisk -l 查看新增硬盘的盘符,例如/dev/sdb;
将其分成三个区:
#fdis ......
比如说要看
http://broadcast.hzcnc.com/player.asp?code=345&pname=%u65e0%u95f4%u9053
$ curl 'http://broadcast.hzcnc.com/Play.aspx?code=345'
<ASX VERSION = "3.0">
<ENTRY>
<REF HREF = &quo ......
准备好两台已经上网的电脑。
1、设置等会要连接到的Linux系统
(1)必须是安装了telnet软件的系统,其中该软件分为两部分,分别是telnet-client和telnet-server,其中前者默认已经装好,而后者则需自己进行安装。在这里,笔者自己的是RedHat的FC6系统,所以可以输入命令yum install telnet-serve ......
At first you have to open a terminal/bash and then enter:
file /path/file.bin
for example file /home/user/file.bin (file is the command)
Now you should see a sentence including the word “executable” and not “non-executable, not executable,… or something completely differ ......