linux c fork简单调用bin or shell script demo
来源:互联网 发布:格式化工厂软件 编辑:程序博客网 时间:2024/05/16 11:43
// exec shell script
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
void hello()
{
printf("hello word \n");
}
int main()
{
pid_t pid;
pid=fork();
if(pid<0)
{
printf("fail to fork \n");
exit(3);
}
else if(pid ==0)
{
// child process run testcallexecl
//if(execl("/opt/test/testcallexecl","interp","arg1",NULL)<0)
// exec shell script /usr/bin/hello must be set x privilege to hello
if(execl("/usr/bin/hello","xx","uu",NULL))
{
printf("fail to execl \n");
exit(2);
}
printf("the child is not hello \n");
exit(0);
}
printf("the parent %u\n",getpid());
return 0;
}
cat /usr/bin/hello
#!/bin/sh
echo hello word
---------------------------------------------------------------------------------------------------
// call bin
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
pid_t pid;
pid=fork();
if(pid<0)
{
printf("fail to fork \n");
exit(3);
}
else if(pid ==0)
{
//exec testpid exec bin file
if(execvp("testpid",NULL)<0)
{
//child process exec
printf("fail to exec \n");
exit(2);
}
printf("the child is not exec \n");
exit(0);
}
printf("the parent %u\n",getpid());
return 0;
}
cat pid.c
#include<stdio.h>
#include<unistd.h>
int main()
{
pid_t pid,ppid,uid,euid,gid,egid;
pid=getpid();
ppid=getppid();
uid=getuid();
euid=geteuid();
gid=getgid();
egid = getegid();
printf("id of current process :%u \n",pid);
printf("parent id of current process :%u \n",ppid);
printf("user id of current process :%u \n",uid);
printf("effective user id of current process :%u \n",euid);
printf("gid of current process :%u \n",gid);
printf("effective gid of current process :%u\n",egid);
// setx pid set gid
if(setuid(501)==-1)
{
perror("fail to set uid");
exit(1);
}
uid=getuid();
euid=geteuid();
printf("id of current process :%u \n",pid);
printf("parent id of current process :%u \n",ppid);
return 0;
}
- linux c fork简单调用bin or shell script demo
- C调用shell script脚本的方法
- Linux shell脚本中调用另一个shell(exec、source、fork)
- 【Unix/Linux.Shell Script】Shell & Shell Script
- shell script简单范例
- linux 几个简单shell脚本demo
- linux shell 编程 调用过程 fork execve 组合拳
- ubuntu linux shell fork, source and exec 调用执行
- 关于Lua调用C的简单demo
- LINUX shell script 打包
- linux shell script 入门
- linux shell script 函式
- linux shell script
- Linux shell script
- [linux]shell script 随记
- Linux Shell Script Study
- FTP linux shell script
- linux-shell script
- Mapped Statements collection does not contain value for
- ORACLE临时表总结
- oracle创建表空间
- 测试工程师所需要的基本技能----测试leader/测试经理们你懂你们的下属么?
- 文件管理
- linux c fork简单调用bin or shell script demo
- java代码实现移动文件以及文件夹
- EBS OAF开发中如何在OAF页面调用form并传递参数给form
- ubuntu11.04 默认源不能用,用这个源代替
- 【手机游戏开发优化篇】详解手游[体积]及[运行内存]的优化篇!
- 多级反向代理下,Java获取请求客户端的真实IP地址多中方法整合
- 当一个线程进入一个对象的一个synchronized方法后,其它线程是否可进入此对象的其它方法?
- 我要带徒弟学写JAVA架构,引路架构师之路(Jeecg开源社区)
- cocos2dx 3.0 微信打飞机--004