千赢娱乐手机登录_ qy8com千赢手机版_千赢网页手机版
做最好的网站

千赢娱乐手机登录

当前位置:千赢娱乐手机登录 > 千赢娱乐手机登录 > Linux下重量级命令strace使用介绍,Linux命令里面两

Linux下重量级命令strace使用介绍,Linux命令里面两

来源:http://www.modeLspro.net 作者:千赢娱乐手机登录 时间:2019-07-15 08:45

下面先看一下join命令的使用方法:
对于合并两个具有相同文件头的方法合并起来是一种很好的方法:

如何从CentOS 6.0升级到CentOS 6.2

经常使用LINUX的朋友或许经常会疑问:linux是怎么样执行一条命令并得到正确输出结果的呢?
比如你输入一个pwd,得到的是当前路径,输入一个env显示的是系统环境变量等等,那你想知道他们是怎么样执行的吗?
go ahead!!
首先:
我们先看下一个重量级的系统调用函数execve(),具体的参数和返回值请大家使用man execve命令来查询吧。
如下程序就是来自实例文档:
[www.linuxidc.com @linux]$cat yuexe.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

[www.linuxidc.com @linux source]$cat sinadept.txt
100 Harry Potter:100:Magic School
200 Alex Jason:200:Sales
300 Yu Chao:300:SINA Product Development
400 Sanjay Gupta:400:Support
500 Nisha Singh:500:Sales
1000 Yu Jun:1000:Peking University EECS
[www.linuxidc.com @linux source]$cat sinasalary.txt
100 $1000
200 $1234
300 $892
400 $2389
500 $123
1000 $2389
[www.linuxidc.com @linux source]$join sinadept.txt sinasalary.txt
100 Harry Potter:100:Magic School $1000
200 Alex Jason:200:Sales $1234
300 Yu Chao:300:SINA Product Development $892
400 Sanjay Gupta:400:Support $2389
500 Nisha Singh:500:Sales $123
1000 Yu Jun:1000:Peking University EECS $2389
[www.linuxidc.com @linux source]$join sinasalary.txt sinadept.txt
100 $1000 Harry Potter:100:Magic School
200 $1234 Alex Jason:200:Sales
300 $892  Yu Chao:300:SINA Product Development
400 $2389 Sanjay Gupta:400:Support
500 $123 Nisha Singh:500:Sales
1000 $2389 Yu Jun:1000:Peking University EECS

首先替换默认源为163源:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget
mv CentOS6-Base-163.repo /etc/yum.repos.d/
 
升级系统:
yum makecache
yum update
 
升级过程中报了一个key相关的错误,具体记不清了,重新执行yum update确定导入key即可。
 
重启,确认更新成功:
 
[root@localhost ~]# uname -r
2.6.32-220.7.1.el6.x86_64

int
main(int argc, char *argv[])
{
    char *newargv[] = { NULL, "hello", "world", NULL };
    char *newenviron[] = { NULL };

再看一下tr命令,对于需要执行整篇文章进行大小写转换的处理时很有用:

[root@localhost ~]# cat /etc/RedHat-release
CentOS release 6.2 (Final)

    if (argc != 2) {
    fprintf(stderr, "Usage: %s <file-to-exec>n", argv[0]);
    exit(EXIT_FAILURE);
    }
    newargv[0] = argv[1];
    execve(argv[1], newargv, newenviron);
    perror("execve");  /* execve() only returns on error */
    exit(EXIT_FAILURE);
}
编译成功后可以得到可执行文件:yuexe
[www.linuxidc.com @linux]$ls
grap.c  Hello  helloscons.c  helloscons.o  helloSina.h  SConstruct  weibo.h  yuexe  yuexe.c  yuexe.o
查看命令yuexe执行Hello程序的内核调用过程如下:

如下:

图片 1

[www.linuxidc.com @linux]$sudo strace ./yuexe Hello
[sudo] password for yuchao:
execve("./yuexe", ["./yuexe", "Hello"], [/* 17 vars */]) = 0
brk(0)                                  = 0x84e3000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77b6000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=103314, ...}) = 0
mmap2(NULL, 103314, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb779c000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY)        = 3
read(3, "177ELF111\0\0\0\0\0\0\0\0\03\03\01\0\0\0@n1\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1421892, ...}) = 0
mmap2(NULL, 1427880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x45f000
mmap2(0x5b6000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x157) = 0x5b6000
mmap2(0x5b9000, 10664, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x5b9000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb779b000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb779b6c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0x5b6000, 8192, PROT_READ)    = 0
mprotect(0x8049000, 4096, PROT_READ)    = 0
mprotect(0xd3f000, 4096, PROT_READ)    = 0
munmap(0xb779c000, 103314)              = 0
execve("Hello", ["Hello", "hello", "world"], [/* 0 vars */]) = 0
brk(0)                                  = 0x8cf0000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77fb000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=103314, ...}) = 0
mmap2(NULL, 103314, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb77e1000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY)        = 3
read(3, "177ELF111\0\0\0\0\0\0\0\0\03\03\01\0\0\0@n1\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1421892, ...}) = 0
mmap2(NULL, 1427880, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb3c000
mmap2(0xc93000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x157) = 0xc93000
mmap2(0xc96000, 10664, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xc96000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77e0000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb77e06c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0xc93000, 8192, PROT_READ)    = 0
mprotect(0x8049000, 4096, PROT_READ)    = 0
mprotect(0xb1c000, 4096, PROT_READ)    = 0
munmap(0xb77e1000, 103314)              = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 5), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77fa000
write(1, "Hell Scons,I'm YuChaon", 22Hell Scons,I'm YuChao
) = 22
write(1, "Hello SINA,I'm YuChaon", 22Hello SINA,I'm YuChao
) = 22
write(1, "Hell weibo,I'm YuChaon", 22Hell weibo,I'm YuChao
) = 22
exit_group(0)                          = ?
[www.linuxidc.com @linux]$

[www.linuxidc.com @linux source]$tr a-z A-Z <sinadept.txt
100 HARRY POTTER:100:MAGIC SCHOOL
200 ALEX JASON:200:SALES
300 YU CHAO:300:SINA PRODUCT DEVELOPMENT
400 SANJAY GUPTA:400:SUPPORT
500 NISHA SINGH:500:SALES
1000 YU JUN:1000:PEKING UNIVERSITY EECS
[www.linuxidc.com @linux source]$tr A-Z a-z <sinadept.txt
100 harry potter:100:magic school
200 alex jason:200:sales
300 yu chao:300:sina product development
400 sanjay gupta:400:support
500 nisha singh:500:sales
1000 yu jun:1000:peking university eecs
[www.linuxidc.com @linux source]$

到这里可以看得很清楚,美国系统调用的过程,由于linux内核不允许用户态进程直接访问硬件资源,当用户进程需要访问系统硬件资源时采用系统调用,美国系统调用都有调用参数和返回值,如果想了解系统调用的具体含义请man 之。
如上可以看到:write(1,“Hell Scons,I'm YuChaon",22 Hell Scons.....等等

本文由千赢娱乐手机登录发布于千赢娱乐手机登录,转载请注明出处:Linux下重量级命令strace使用介绍,Linux命令里面两

关键词: