C語言execv()函式:執行檔案函式
相關函式:fork, execl, execle, execlp, execve, execvp
標頭檔案:#include <unistd.h>
定義函式:int execv (const char * path, char * const argv[]);
函式說明:execv()用來執行引數path 字串所代表的檔案路徑, 與execl()不同的地方在於execve()只需兩個引數, 第二個引數利用陣列指標來傳遞給執行檔案.
返回值:如果執行成功則函式不會返回, 執行失敗則直接返回-1, 失敗原因存於errno 中.
錯誤程式碼:請參考 execve ().
範例
/* 執行/bin/ls -al /etc/passwd */
#include <unistd.h>
main()
{
char * argv[] = {"ls", "-al", "/etc/passwd", (char*)};
execv("/bin/ls", argv);
}
執行:
-rw-r--r-- 1 root root 705 Sep 3 13 :52 /etc/passwd
相關推薦
C語言execv()函式:執行檔案函式
相關函式:fork, execl, execle, execlp, execve, execvp 標頭檔案:#include <unistd.h> 定義函式:int execv (const char * path, char * const argv[]
C語言fread()函式:讀檔案函式(從檔案流讀取資料)
相關函式:fopen, fwrite, fseek, fscanf標頭檔案:#include <stdio.h>定義函式:size_t fread(void * ptr, size_t size, size_t nmemb, FILE * stream);函式說
C語言獲取當前編譯執行檔案(XXX.exe)檔名和目錄路徑
C語言獲取當前編譯執行檔案(XXX.exe)檔名和目錄路徑 vc2010編譯通過 #include<stdio.h> #include<string.h> #include<windows.h> #include<stdlib.h> int ma
C語言lseek()函式:移動檔案的讀寫位置
相關函式:dup, open, fseek 標頭檔案:#include <sys/types.h> #include <unistd.h> 定義函式:off_t lseek(int fildes, off_t offset, int whenc
C語言link()函式:建立檔案連線
相關函式:symlink, unlink 標頭檔案:#include <unistd.h> 定義函式:int link (const char * oldpath, const char * newpath);函式說明:link()以引數newpath 指定的名
C語言fclose()函式:關閉檔案流
標頭檔案:#include <stdio.h>fclose()函式用來關閉當前檔案流,其原型為: int fclose(FILE * stream);【引數】stream為檔案流指標。【返回值】若關檔案動作成功則返回0,有錯誤發生時則返回EOF,並把錯誤程
C語言學習筆記:printf()函式詳解
C語言中有關printf()函式的詳細使用方法: 修飾符: - digit(s) :欄位寬度的最小值。如果該欄位不能容納要列印的數或者字串,系統就會使更寬的欄位。 如%4d。 - .digit(s):精度,將結果保留到小數點後的多少位。 - h: 和整數轉
C語言學習筆記:指標函式和函式指標的淺析
#include "stdio.h" #include "stdlib.h" #include <string.h> /*--------------指標函式---------------*/ int *f(int a,int b ){ int
c語言學習筆記:字串常見的幾種函式
首先在使用字串函式時請務必匯入#include<string.h>1.strlen:獲取當前字串的長度。2.strcpy:拷貝字串到另一個字串。如strcpy(A,B);其中A和B分別代表兩個字串變數,此方法的意思是copy字串B到A,第一個引數是目標地址,第二個
C語言linux環境下使用gettimeofday函式得到程式執行時間
編寫的一個打字遊戲中需要計算程式的執行時間,通過網上查閱資料發現大多數都是說通過clock()函式來獲取時間,之後做差從而的到程式的執行時間。但是在linux中測試以後發現結果是0,並不能得到程式的執行時間。 請教老師後得知可以通過引用標頭檔案time.h,使
c語言一個語句中多個函式執行的順序
已printf為例: 如printf("min = %d , topV = %d\n", min(&mystack), pop(&mystack)); 執行順序是先執行pop,然後在執
C語言readdir()函式:讀取目錄函式
相關函式:open, opendir, closedir, rewinddir, seekdir, telldir, scandir標頭檔案:#include <sys/types.h> #include <dirent.h>定義函式:struc
C語言-----string.h標頭檔案中相關字串函式的模擬實現
strlen:用途:Get the length of a string.獲取字串長度。函式原型:size_t strlen( const char *string ); size_t表示無符號的意思,長度值肯定是無符號的。源字串以'\0'作為結束標誌。strlen函式返回的
【C語言】字串處理自定義函式
1、字串求長度 #include <stdio.h> int Mystrlen1(const char *str) { int i=0; while(*(str++)!='\0') { i++; } return i; } int Mystrlen2(cons
C語言及程式設計 實踐參考 分段函式求值switch語句版
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
C語言 指標基礎篇 陣列,函式與指標的運用 2 14
下面看看如何在函式中運用指標吧 下面是往函式傳入指標的簡單操作,不是傳入陣列的。判斷一個a是否大於b是的話給,是的話對其進行操作,不是的話就直接返回。 1 #include <stdio.h> 2 int main(){ 3 int num1,num2,*p1,
C#開根號函式:math.pow()函式
參考資料:https://blog.csdn.net/sjpz0124/article/details/45191299 標頭檔案:#include <math.h> pow() 函式用來求 x 的 y 次冪(次方),其原型為: d
C++ 進階筆記:一些庫函式……還有一些奇技淫巧
一、奇技淫巧 1.取帶小數的餘數 (1)“整除”取餘法 #include<iostream> using namespace std; void main() { float a = 362.75; int b = 360; float aMod= a - ((i
c語言4個比較大小,函式的巢狀
#include <stdio.h> int main()// { int max_4(int a,int b,int c,int d);//對max _4的宣告 int a,b,c,d,max; printf("Please enter 4 interger numbe
Java併發(十八):阻塞佇列BlockingQueue BlockingQueue(阻塞佇列)詳解 二叉堆(一)之 圖文解析 和 C語言的實現 多執行緒程式設計:阻塞、併發佇列的使用總結 Java併發程式設計:阻塞佇列 java阻塞佇列 BlockingQueue(阻塞佇列)詳解
阻塞佇列(BlockingQueue)是一個支援兩個附加操作的佇列。 這兩個附加的操作是:在佇列為空時,獲取元素的執行緒會等待佇列變為非空。當佇列滿時,儲存元素的執行緒會等待佇列可用。 阻塞佇列常用於生產者和消費者的場景,生產者是往佇列裡新增元素的執行緒,消費者是從佇列裡拿元素的執行緒。阻塞佇列就是生產者