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

#include<stdlib.h>
void exit(int status);
void _Exit(int status);

#include
<unistd.h>
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.
#include<setjmp.h>

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.

 

 

 

 

 

 

 

 

 

 

 

 

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Mybatis源码学习笔记(三) 配置详解(properties 和environment)

配置详解:propertiess和environmentproperties的使用用法

halcon学习笔记之(一)label_word_process_mlp.hdev

* This example shows how OCR results can be improved by restricting the * allowed results using a re...

nginx 源码学习笔记(十七)—— ngx_worker_process_cycle子进程执行

上一节主要讲解主进程如何开启子进程,并且讲解了主进程做的一些操作,这一节主要学习子进程处理函数ngx_worker_process_cycle [cpp] view plaincop...

node child_process模块学习笔记

NodeJs是一个单进程的语言,不能像Java那样可以创建多线程来并发执行。当然在大部分情况下,NodeJs是不需要并发执行的,因为它是事件驱动性永不阻塞。但单进程也有个问题就是不能充分利用CPU的多...
  • canot
  • canot
  • 2017-05-19 22:52
  • 646

Nginx函数ngx_single_process_cycle学习笔记

ngx_cycle_t=ngx_cycle_s ngx_cycle_s的定义如下,下面介绍的函数中有一个重要的ngx_cycle_t类型的参数cycle,所一写介绍下它的类型结构。 struct n...

nginx 源码学习笔记(二十一)—— event 模块(二) ——事件驱动核心ngx_process_events_and_timers

首先继续回忆下,之前子线程执行操作里面有一个未涉及的内容ngx_process_events_and_timers,今天我们就来研究下这个函数。 本篇文章来自于:http://blog.csdn.n...

【APUE 学习笔记】4: Unix Process Control 进程控制

本文是APUE第8章:进程控制知识点的总结和代码实践的总结。

nginx 源码学习笔记(十七)—— ngx_worker_process_cycle子进程执行

上一节主要讲解主进程如何开启子进程,并且讲解了主进程做的一些操作,这一节主要学习子进程处理函数ngx_worker_process_cycle src/os/unix/ngx_process_cyc...

nginx 源码学习笔记(十五)—— ngx_master_process_cycle 多进程(一)

了解core模块之前还应改学习ngx_start_worker_processes函数,今天我就来详细学一下这个方法,主要内容来自于http://blog.sina.com.cn/s/blog_677...

nginx 源码学习笔记(二十一)—— event 模块(二) ——事件驱动核心ngx_process_events_and_timers

首先继续回忆下,之前子线程执行操作里面有一个未涉及的内容ngx_process_events_and_timers,今天我们就来研究下这个函数。 本篇文章来自于:http://blog.csdn...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)