exec函数簇

FPGA SPI驱动ADC避坑指南:以ADC128S022为例,详解时序设计与代码调试 本文以ADC128S022为例,详细解析FPGA通过SPI驱动ADC的时序设计与代码调试中的常见问题。从时钟分频计算、SPI模式选择到状态机实现,提供避坑指南和实战技巧,帮助工程师解决数据采集系统中的时序匹配难题。特别针对FPGA与ADC通信中的微妙差异,给出精确的Verilog代码示例和ModelSim仿真验证方法。 阅读详情

exec函数簇的作用:在进程的内部执行一个可执行文件。原进程将被取代,在旧的躯壳上注入了新的灵魂。若调用成功,由于原进程不复存在,所以不返回任何值;若调用失败,则返回-1,从原进程的调用点接着往下进行。fork()配合exec(),可以使得应用程序产生一个新进程。

 

main函数:

int main( int argc, char *argv[], char *envp[] );

第一个参数argc是运行时参数的个数,第二个参数argv用来存放运行时参数,第3个参数用来存放系统环境变量。

  1 #include<stdio.h>
  2 #include<unistd.h>
  3
  4 int main( int argc, char *argv[], char *envp[] ){
  5     printf("### argc ###/n");
  6     printf("    %d      /n", argc);
  7     printf("### argv ###/n");
  8     while(*argv)
  9         printf("%s/n", *argv++);
 10     printf("### envp ###/n");
 11     while(*envp)
 12         printf("%s/n", *envp++);
 13        
 14     return 0;
 15 }

 

========================exec.c===========================

#include<unistd.h>
int main(){
int status = 0;
    char *envp[] = {"PATH=/tmp", "USER=lei", "STATUS=testing", NULL};

    char *argv_execv[]={"echo", "excuted by execv", NULL};
    char *argv_execvp[]={"echo", "excuted by execvp", NULL};
    char *argv_execve[]={"env", NULL};

    if(fork() == 0){
        if(execl("/bin/echo", "echo", "executed by execl", NULL) < 0)
            perror("Err on execl");
    }
    if(fork() == 0){
        if(execlp("echo", "echo", "executed by execlp", NULL) < 0)
            perror("Err on execlp");
    }
    if(fork() == 0){
        if(execle("/usr/lib/env", "env", "executed by execle", NULL, envp) < 0)
            perror("Err on execle");
    }
    if(fork() == 0){
        if(execv("/bin/echo", argv_execv) < 0)
            perror("Err on execv");
    }   
    if(fork() == 0){
        if(execvp("echo", argv_execvp) < 0)
            perror("Err on execvp");
    }   
    if(fork() == 0){
        if(execve("/usr/bin/env", argv_execve, envp) < 0)
            perror("Err on execve");
    }   
wait(status)    ;
}

 

====

explore@ubuntu:~/Documents/Linux C Programming/Process/exec$ cc exec.c
explore@ubuntu:~/Documents/Linux C Programming/Process/exec$ ./a.out
Err on execle: No such file or directory
excuted by execv
executed by execl
excuted by execvp
explore@ubuntu:~/Documents/Linux C Programming/Process/exec$ PATH=/tmp
USER=lei
STATUS=testing
excuted by execvp
executed by execlp
excuted by execv
PATH=/tmp
USER=lei
STATUS=testing

(对于这里的结果不解释)。

12S BMS 核心设计:基于 STM32H743+BQ34Z100 的 SOC/SOH 实现与全链路技术解析(上) 本文详细介绍了基于STM32H743和BQ34Z100的12串锂电池管理系统(BMS)设计。该系统采用主控制器+专用电量监测计架构,可实现高精度SOC(±1%)和SOH(±2%)估算,支持36V-50.4V电压范围。硬件设计包括电压/电流采样、温度测量、保护电路等模块,软件实现基于HAL库开发,采用DMA方式提高I2C通信效率。系统通过TI专利的ImpedanceTrack™算法实现三维融合估算,并具备完善的保护功能。该设计适用于电动工具、轻型电动车等中功率设备,具有精度高、响应快。 阅读详情

相关推荐

MQTT(一)C#使用 MQTTnet 快速实现 MQTT 通信(文末有完整Demo下载)

目录 MQTT(一)C#使用 MQTTnet 快速实现 MQTT 通信(文末有完整Demo下载) MQTT(二)在windows64位上安装Python环境 MQTT(三)Python客户端+net客户端+net服务端 简单通信 MQTT(四)树莓派开机自动运行Python客户端 MQTT(五)EMQ开源MQTT消息服务器 1 什么是 MQTT ? MQTT(Message Que...

pw的博客 10万+

exec函数族

1. exec函数族介绍 fork()函数可以用来创建子进程,但是子进程执行的是和父进程相同的程序,或者说执行父进程程序的一部分,或者父进程与子进程执行不同的代码分支,但总归是跟父进程关系很大的程序。但我们创建子进程的目的往往是要让进程执行新的程序才行,这个时候就需要用到exec函数族。 当进程调用一种exec函数时,该进程用户空间的代码和数据会被新程序完全替代,然后从新程序的第一行代码开始执行,中间只要不出现错误就不会返回到原程序的代码,如果出现错误则返回到原程序中调用exec函数的下一行继续执行。

向上吧贺凯 1344

成分数据的闭合效应对地球化学数据的影响及其解决方案

封闭效应 (Closure Effect),也称为常数和效应 (Constant Sum Effect),是地球化学数据分析中一个需要特别注意的统计现象。它的产生是由于我们通常使用成分数据 (Compositional Data)百分比 (%)百万分率 (ppm)由于这些数据表示的是各组分占总体的比例,它们的总和必然是一个常数 (例如 100% 或 1,000,000 ppm)。这意味着每个元素的含量不是独立的,而是与其他元素的含量相互制约。改变其中一个元素的含量必然会影响其他元素的相对比例。

qq_59349063的博客 1533

Linux下的exec函数簇

本文将详细介绍Linux环境下exec函数簇的原理、用法及实际应用场景,帮助读者更好地掌握这一重要的系统调用。

2201_75782847的博客 1598

1014. 福尔摩斯的约会 (20)-PAT乙级真题

1014. 福尔摩斯的约会 (20) 大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧!3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母’D’,代表星期四;第2对相同的字符是’

柳婼 の blog 2644

大模型微调框架之TRL

近年来,大语言模型(LLMs)的快速发展推动了下游应用的繁荣,但如何高效地对这些模型进行对齐和微调,依然是研究与应用的热点。Hugging Face 开源的 TRL(Transformer Reinforcement Learning) 框架,提供了基于强化学习的语言模型训练方法,并支持 SFT(监督微调)、PPO(近端策略优化)、DPO(直接偏好优化)等多种方式,是目前对齐和微调 LLM 的重要工具。

和大家一起涨芝士 904

fork()和exec函数簇

介绍 功能:创建一个新的进程 返回:子进程中为0,父进程中为子进程ID,出错为-1。 说明: 由fok创建的新进程被称为子进程( child process)。 父、子进程完全一样(代码、数据),子进程从fork内部开始执行,fork返回子进程的pid后,接着执行下一条语句该函数被调用一次,但返回两次。两次返回的区别是子进程的返回值是0,而父进程的返回值则是子进程的进程|D。 一般来说,在fork之后是父进程先执行还是子进程先执行是不确定的。这取决于内核所使用的调度算法。 继承 使用fork函

奋进的小白粥 605

Pixhawk变砖自救指南:从DFU模式到固件重刷全流程(附2.4.8实测)

本文详细介绍了Pixhawk飞控变砖后的自救方法,从DFU模式进入、固件重刷到高级恢复技巧全流程。特别针对国产版本boot0引脚未引出的特殊情况提供了解决方案,帮助用户通过QGC或Mission Planner地面站工具恢复飞控功能,适用于2.4.8等常见固件版本。

weixin_29168813的博客 337

【Linux】进程程序替换——exec函数簇

主要学习介绍进程程序的替换原理以及替换函数exec函数簇的使用解析

紫阳战君的博客 941

【机械视觉】Halcon—【二、Halcon算子全面介绍(超详细版)】

Halcon 的算子(operators)按照功能被系统性地划分为多个类别,官方文档中目前(Halcon 22.11 版本)共有 19 个主分类,每个主分类下还有若干子分类。 本人在此对这19个分类的常用核心算子进行了一系列的总结,且本人在文章最后还总结了一些案例经验。 注意: ​​​​​​​跨分类调用:某些算子可能在多个分类中,但官方文档中会明确其主分类。 例如: read_image(文件操作)常被其他分类(如图像处理)的示例调用,但其核心功能是文件读取。

qq_3517289697的博客 3913

分享一下如何使用labelimg制作自己的YOLO数据集

首先准备一下自己的下准备一个空文件夹用于保存标签文件,如下图所示。

skywalkerxhx的博客 831

小记——exec函数簇

#include int execl(const char* path, const char *arg, ...); int execlp(const char *file, const char *arg, ...); int execle(const char *path, const char *arg, ..., char * const envp[]); int execv(

心清的专栏 1092

华为od统一考试B卷【单词搜索】C++ 实现

找到它是一个小游戏,你需要在一个矩阵中找到给定的单词。假设给定单词 HELLOWORD,在矩阵中只要能找到 H->E->L->L->O->W->O->R->L->D连成的单词,就算通过。意区分英文字母大小写,并且您只能上下左右行走,不能走回头路。

MISAYAONE的博客 709

Linux:进程程序替换(exec函数簇)

进程程序替换: 替换正在运行的程序,让正在运行的进程执行新程序; 进程程序替换原理及过程: 一个可执行程序运行起乱来的时候一定是一个PCB或称为task_struct结构体,里面游艇变量叫内存指针,这个内存指针指向了进程虚拟地址空间,该空间包含栈区,堆区,数据段,代码段等程序; 通过页表结构和物理内存映射,程序在运行起来后,代码段里就运行者我们自己写的代码; 如果想让该程序替换成另一个程序,我们会在代码中调用进程替换函数; 此时当前运行的程序会做一件事,那就是更新替换当前进程的代码段和数据段为新的程

qq_45481606的博客 691

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

(17)Linux的进程阻塞&&进程程序替换 && exec 函数簇

本章我们讲解它的 options 参数。在讲解之前我们需要理解进程阻塞,然后我们重点讲解二进程程序替换,这是本章的重点,然后介绍一个进程替换函数 execl,通过介绍这个函数来打开突破口,引入进程创建的知识点。最后,我们在学习进程创建的 exec 函数簇。

ayf9999的博客 1210

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

linux 之进程基础 (四)、进程API之进程执行exec函数簇

4. 进程API之创建执行exec函数簇 4.1 exec()函数簇说明 可执行文件查找方式: 带p:对文件查找方式为p的(以p结尾的函数)可以只给出文件名,系统会自动从环境变量“$PATH”所包含的路径中进行查找。 不带p:需要提供完整的路径名。 向新程序传递环境表的方式: 带e:接受一个附加的环境参数列表,参数格式为NULL结尾的字符串数组,且字符串的格式为“VARIABLE=value...

江南又一春 404

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

exec函数簇(创建进程)

exec函数簇(创建进程) 1、 头文件:#include <unistd.h> 2、 函数原型:int execl(const char *path, const char *arg,(char *) NULL); int execv(const char *path, char *const argv[]); 注:一般execv + fork 配合使用。 3、 函数形参:path...

qq_45595832的博客 847

Linux 进程:exec函数簇

介绍了exec函数簇:execl、execlp、execle、execv、execvp、execve。介绍了它们的参数、以及展示了它们的使用方法。

weixin_57761086的博客 1575

【C++高并发服务器WebServer】-2:exec函数簇、进程控制

【C++高并发服务器WebServer】-2:exec函数簇、进程控制

theaipower的博客 8190

进程exec函数簇与wait/waitpid函数

1,被加载的文件的参数列表必须以自身名字为开始,以 NULL 为结尾。比如要加载执 行当前目录下的一个叫做 a.out 的文件,需要一个参数”abcd”,那么正确的调用应该是: execl(“./a.out”, “a.out”, “abcd”, NULL); 或者: const char *argv[3] = {“a.out”, “abcd”, NULL}; execv(“./a.out”, a...

weixin_44522306的博客 401

linux - exec函数簇

/ 等待子进程结束。// 子进程异常退出。// 在子进程中执行 ‘ls’// 如果 exec 失败。重点是execl 和execlp。错误用法 缺“ls”

chenjian276325128的博客 309

linux exec函数簇,Linux下的exec系统调用详解

1.系统调用exec是以新的进程去代替原来的进程,但进程的PID保持不变。因此,可以这样认为,exec系统调用并没有创建新的进程,只是替换了原来进程上下文的内容。原进程的代码段,数据段,堆栈段被新的进程所代替。一个进程主要包括以下几个方面的内容:(1)一个可以执行的程序(2) 与进程相关联的全部数据(包括变量,内存,缓冲区)(3)程序上下文(程序计数器PC,保存程序执行的位置)exec是一个函数簇...

weixin_39860919的博客 364

Linux(入门基础):12---exec函数簇

一、exec函数簇 int execl(const char *path, const char *arg, ...); 2 int execlp(const char *file, const char *arg, ...); 3 int execle(const char *path, const char *arg, ..., char * const envp[]); 4 int execv(const char *path, char *const argv[]); 5 int execvp(co

du_lijun的博客 290
上一篇: vfork()系统调用-创建子进程,阻塞父进程
下一篇: exit()与_exit()的辨析
deep_explore
博客等级 码龄16年 54粉丝 97原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值