linux 学习笔记之 Process Environment

原创 2007年10月03日 17:45:00
  1. Process Termination

          There are eight ways for a process to terminate. Normal termination occurs in file ways: 

  • Return from main
  • Calling exit
  • Calling _exit or _Exit
  • Return of the last thread from its start routine
  • Calling pthread_exit from the last thread

          Abnormal termination occurs in three ways:

  • Calling abort
  • Receipt of a signal
  • Response of the last thread to a cancellation request

      2.   Exit Functions

void exit(int status);
void _Exit(int status);

void _exit(int status);
  • _exit and _Exit, which return to the kernel immediately, and exit, which performs certain cleanup processing  (use fclose function for all open streams) and then return to kernel.
  • If  any of these functions is called without an exit status,  main does a return without a return value, or the main function is not declared to return a integer, the exit status of the process is undefined.

       3.   Memory layout of a C program

  • Test segment, the machine instructions that the CPU executes. Usually, the test segment is read-only and sharable.
  • Initialized data segment, containing variables that are specifically initialized in the program(ex: int data=100).  
  • Uninitialized data segment, data in this segment is initialized by the kernel to arithmetic 0 or NULL pointers before the program starts executing.
  • Stack:  where automatic variables are stored, along with information that is saved each time a function is called.
  • Heap: where dynamic memory allocation usually takes place. Historically, the heap has been located between the uninitialized data and the stack.

        4.  Memory Allocation

void * malloc(size_t size);
void * calloc(size _t nobj, size_t size);
void * realloc(void *ptr, size_t newsize);
  • malloc, which allocates a specified number of bytes of memory.  The initial value of the memory is indeterminate.
  • calloc, which allocates space for a specified number of objects of a specified size. The space is initialized to all 0 bits.
  • realloc, which increase or decrease the size of a previously allovated area. The initial value of the space between the old contents and the end of the new area is indeterminate.
  • One additional function is also worth mentioning. The function alloca has the same calling sequence as malloc; however, instead of allocating memory from the heap, the memory is allocated from the stack frame of the current  function. The advantage is that we don't have to free the space; it goes away automatically when the function returns. The disadvantage is that some system don't support alloca , it it's impossible to increase the size of the stack frame after the function has been called.

         5. setjmp and longjmp functions

  • In C, we can not goto a lablel that is in another function. Instead, we must use the setjmp and longjmp functions to perform this type of branching. These two functions are useful for handling error conditions that occur in a deeply rested function call.

int setjmp(jmp_buf env);
int longjmp(jmp_buf env, int val);

             Argument val decide return value on setjmp,  we can use this to check which function call longjmp.

  • The setjmp(3) manual page on one system states that variables stored in memory will have values as of the time of the longjmp, whereas variables in the CPU and floating-point registers are restored to their values when setjmp was called. If you have an automatic  variable that you don't want to rolled back, define it with the volatile attribute.














[技巧]Linux process进程

本文,在实现视频编码流媒体--控制进程实现,为了理解控制进程的实现(深入环境),记录最关键的几个知识点。 基本涉及: unix系的进程环境(C程序的启动与终止、C程序的内存布局、环境表与环境变...
  • bangdingshouji
  • bangdingshouji
  • 2017年03月30日 09:57
  • 271

Jenkins 系列: (七) Jenkins 环境变量管理

今天我们谈谈 Jenkins 中环境变量相关的问题,Jenkins中有多个地方可以设置环境变量,从而在build 构建过程中可以使用。环境变量的来源Jenkins系统变量Jenkins 有很多系统内置...
  • huaqiangli
  • huaqiangli
  • 2018年02月07日 17:18
  • 748


在zynq上进行Linux的移植并基于Linux进行驱动开发需要涉及到很多东西,用一张图说明要掌握哪些知识: 如上图所示,对开发驱动的人来说,既要懂软件也要懂硬件,软件上需要对操作系统结构和接...
  • jj12345jj198999
  • jj12345jj198999
  • 2017年01月18日 22:53
  • 1513


  • chenghuaying
  • chenghuaying
  • 2014年03月31日 16:47
  • 4924


这一篇讲一讲zynq移植linux操作系统时需要使用的 rootfs 1、rootfs简介 rootfs用于生成linux启动时ramdisk.image,其和devicetree,linux-ker...
  • jj12345jj198999
  • jj12345jj198999
  • 2017年02月10日 21:41
  • 1907

Linux netfilter 学习笔记 之十 ip层netfilter的连接跟踪模块 学习小结

  • lickylin
  • lickylin
  • 2014年06月29日 21:31
  • 1721


Linux之shell编程之条件判断与流程控制 文件判断 -b 判断该文件是否存在,并且是否为块设备文件(是为真) -c 判断该文件是否存在,并且是否为字符设备文件(是为真) -d 判断该文件是否存在...
  • zhaojianyin
  • zhaojianyin
  • 2017年03月12日 16:51
  • 194

linux 学习笔记之 Process Control

Process Identifiers Every process has unique process ID, a non-negative integer. Process ...
  • befun
  • befun
  • 2007年10月09日 06:35
  • 506

Zynq-Linux移植学习笔记之16-Zynq下linux XADC驱动

1、  简介 XADC是zynq芯片内部进行温度和电压检测的模块,通过(Xilinx Wiki - xadc.html)这篇wiki可以知道,XADC控制器有两种表现形式,一种是位于PS内部,即文档...
  • jj12345jj198999
  • jj12345jj198999
  • 2017年06月18日 21:39
  • 1011


  • jj12345jj198999
  • jj12345jj198999
  • 2017年02月14日 22:55
  • 1544
您举报文章:linux 学习笔记之 Process Environment