當前位置:編程學習大全網 - 網站源碼 - [求助]有沒有C語言高手啊,關於execv的用法

[求助]有沒有C語言高手啊,關於execv的用法

execv用法介紹:

execv會停止執行當前的進程,並且以progname應用進程替換被停止執行的進程,進程ID沒有改變。

如果應用程序正常執行完畢,那麽execv是永遠不會返回的;當execv在調用進程中返回時,說明這個應用程序應該出錯了,此時它的返回值應該是-1,具體的錯誤代碼可以通過全局變量errno查看,還可以通過stderr得到具體的錯誤描述字符串。

示例如下:

#include?<stdlib.h>

#include?<stdio.h>

#include?<unistd.h>

#include?<errno.h>

main(void)

{

pid_t?pid?=?fork();

if(?pid?==?0?)?//?this?is?the?child?process

{

execv("/bin/ls",?NULL);

//?the?program?should?not?reach?here,?or?it?means?error?occurs?during?execute?the?ls?command.

printf("command?ls?is?not?found,?error?code:?%d(%s)",?errno,?strerror(errno);

}

  • 上一篇:創世飛羽屬性和幻夢編織怎麽樣?
  • 下一篇:小狐貍abc真的有效嗎
  • copyright 2024編程學習大全網