欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

myprocess_linux.c

sourceforge历史版本完整下载: http://sourceforge.net/project/showfiles.php?group_id=202044 提供了基于b树索引算法的文件数据数据
C
字号:
/**
* @file myprocess_linux.c 描述如何起进程 2008-03-25 23:25
*
* @author lin shao chuan (email:lsccsl@tom.com, msn:lsccsl@163.net)
*
* @brief if it works, it was written by lin shao chuan, if not, i don't know who wrote it.        
** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee,* provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation.  lin shao chuan makes no* representations about the suitability of this software for any* purpose.  It is provided "as is" without express or implied warranty.* see the GNU General Public License  for more detail.*/#include "myprocess.h"
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>#include "mylog.h"static pid_t create_process(const char * path, const char * appname, char * param[]){	pid_t pid = 0;

	LOG_DEBUG(("create_process"));

	pid = vfork();	

	LOG_DEBUG(("vfork over"));

	if(pid < 0)
	{
		LOG_WARN(("fork err"));
		return -1;
	}

	if(pid == 0)
	{
		LOG_DEBUG(("execvp"));
		if(execvp(appname, param) == -1)
		{
			LOG_WARN(("execvp err"));
			return -1;
		}
		else
		{
			LOG_DEBUG(("execvp ok"));
			return 0;
		}
	}
	else
	{
		return pid;	}}/** * @brief 创建进程 */int UOS_CreateProcess(const char * path, const char * appname, char * param[]){	LOG_DEBUG(("UOS_CreateProcess"));

	if(create_process(path, appname, param) < 0)		return  -1;	return 0;}/** * @brief 创建进程并等待 */int UOS_CreateProcessAndWait(const char * path, const char * appname, char * param[]){
	pid_t pid = 0;

	LOG_DEBUG(("UOS_CreateProcessAndWait"));

	pid = create_process(path, appname, param);

	if(pid < 0)
		return -1;

	waitpid(pid, NULL, 0);

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -