10 2012 档案
摘要:/* * Killing other processes */
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h> int main()
{
pid_t child;
int status, retval; if((child = fork()) < 0)
{
perror ("fork");
exit (EXIT_FAILURE);
}
if(child
阅读全文
摘要:通过execve简单的调用,下面我们要调用 “ls”来显示我当前目录下的文件 :/* * execve */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h> int main()
{ char *args[] = {"/bin/ls", NULL}; if(execve ("/bin/ls", args, NULL) == -1) { perror ("execve"); exit(EXIT_FAILURE); } puts(&q
阅读全文
摘要:/* * simple fork usage */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h> int main()
{ pid_t child; if ((child = fork()) == -1) { perror("fork"); exit(EXIT_FAILURE); } else if(child == 0) { puts("in child"); printf ("\tchild pid = %d\n", get
阅读全文
摘要:system函数声明为: int system(const char *string);
string为你要输入的命令。 实例如下:
/* * Demonstrate the system() call */
#include <stdio.h>
#include <stdlib.h> int main()
{ int retval;//retval is the return value of the system call retval = system("ls -l"); if(retval == 127) { fprintf(stderr,
阅读全文

浙公网安备 33010602011771号