学习过程遇到问题的解决方法

1.select.sh  用sh -x 和bash -x的进行脚本调试时,前者会报错误,这是内置shell的原因。

2.awk内置函数使用时,定义变量需要用-v  ;awk -v s="this" 'BEGIN{gsub([/[0-9]+/,"!",s]);print s;}'

  awk内置变量不出现结果 :shell内置函数的问题

3.静态库:ar rcsv libpow.a unsgn_pow.o:ar 是打包的意思,一个项目组多个.o文件打包成.a文件。

                     r:insert c:create s:index v:version

              gcc -o pow_test pow_test.c -L  -lpow:-L是参数,库文件。-lpow去包中获取

4.gdb:gcc -g test.c -o test;使用-g显示具体的调试信息

5.makefile:重点知道预定义变量,自动变量和环境变量

6.fsetpos进行文件指针定位时:给fpos_t pos赋值语句:pos.__pos = 10; /*pos是结构体,两个_设置pos值*/

7.clone()进程创建函数:

    clone(do_something, child_stack+16384,CLONE_VM|CLONE_FILES, NULL);

      //第二个需要加16384,执行程序从高地址-->低地址,不断地向栈底压入东西。不加的会使栈撑破,出现段错误。

#define _GNU_SOURCE//clone_vm

#include <stdio.h>//printf

#include <unistd.h>//_exit

#include <fcntl.h>//file(fd)

#include <sched.h>//clone()

#include <malloc.h>//malloc()

int variable, fd; 

int do_something() {
 variable = 42;
 close(fd);
 _exit(0);
}

int main(int argc, char *argv[]) {
 void **child_stack;
 char tempch;
 variable = 9;
 fd = open("test.file", O_RDONLY);

 child_stack = (void **) malloc(16384);

 printf("The variable was %d ", variable);
 clone(do_something, child_stack+16384,CLONE_VM|CLONE_FILES, NULL);

 sleep(1);   /* 延时以便子进程完成关闭文件操作、修改变量 */
   printf("The variable is now %d ", variable);
 if (read(fd, &tempch, 1) < 1) {
  perror("File Read Error");
  exit(1);
 }
 printf("We could read from the file ");
 return 0;

   

#define _GNU_SOURCE//clone_vm

#include <stdio.h>//printf

#include <unistd.h>//_exit

#include <fcntl.h>//file(fd)

#include <sched.h>//clone()

#include <sys/mman.h>//mmap()

int variable, fd; 

int do_something() {
 variable = 42;
 close(fd);
 _exit(0);
}

int main(int argc, char *argv[]) {
 void *child_stack;
 char tempch;
 variable = 9;
 fd = open("test.file", O_RDONLY);

 child_stack = (void *) mmap(NULL,16384,PROT_READ|PROT_WRITE,MAP_PROVATE|MAPANON|MAPANONYMOUS,-1,0);
 printf("The variable was %d ", variable);
 clone(do_something, child_stack+16384,CLONE_VM|CLONE_FILES, NULL);

 sleep(1);   /* 延时以便子进程完成关闭文件操作、修改变量 */
printf("The variable is now %d ", variable);
 if (read(fd, &tempch, 1) < 1) {
  perror("File Read Error");
  exit(1);
 }
 printf("We could read from the file ");
 return 0;

8.查找手册,如:man ar 

9.gedit保存备份(后缀~)失败:文件已保存,但上级目录未成功。需要修改目录权限。

原文地址:https://www.cnblogs.com/Z-D-/p/6805094.html