ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

Ò»ÖÖ¼òµ¥Ò×ÓõÄC++½ø³ÌÀà
2015-07-20 17:17:29 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:3´Î
Tags£º¼òµ¥ Ò×Óà ½ø³Ì

Ò» ´úÂë½á¹¹

\

¶þ ´úÂë

1. posix_process.h

/*************************************************************************
    > File Name: posix_process.h
    > Author: wangzhicheng
    > Mail: 2363702560@163.com 
    > Created Time: Thu 12 Feb 2015 07:35:34 PM WST
 ************************************************************************/
#ifndef POSIX_PROCESS_H
#define POSIX_PROCESS_H
#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           using namespace std; /* * posix process class * */ class POSIX_PROCESS { protected: pid_t mPid; posix_spawnattr_t mSpawnattr; posix_spawn_file_actions_t mFileactions; char **mArgv; char **mEnvp; string mProgram_path; public: POSIX_PROCESS(const string &program_path, char **argv, char **envp); POSIX_PROCESS(const string &program_path, char **argv, char **envp, posix_spawnattr_t &X, \ posix_spawn_file_actions_t &Y); void run(void); void join(int &value); }; #endif
         
        
       
      
     
    
   
  

2. posix_process.cpp

/*************************************************************************
    > File Name: posix_process.cpp
    > Author: wangzhicheng
    > Mail: 2363702560@163.com 
    > Created Time: Thu 12 Feb 2015 07:50:36 PM WST
 ************************************************************************/

#include "posix_process.h"
POSIX_PROCESS::POSIX_PROCESS(const string &program_path, char **argv, char **envp) {
	this->mArgv = argv;
	this->mEnvp = envp;
	this->mProgram_path = program_path;
	posix_spawnattr_init(&this->mSpawnattr);
	posix_spawn_file_actions_init(&this->mFileactions);
}
POSIX_PROCESS::POSIX_PROCESS(const string &program_path, char **argv, char **envp, posix_spawnattr_t &X, posix_spawn_file_actions_t &Y) {
	this->mArgv = argv;
	this->mEnvp = envp;
	this->mProgram_path = program_path;
	this->mSpawnattr = X;
	this->mFileactions = Y;
	posix_spawnattr_init(&this->mSpawnattr);
	posix_spawn_file_actions_init(&this->mFileactions);
}
void POSIX_PROCESS::run(void) {
	posix_spawn(&this->mPid, this->mProgram_path.c_str(), &this->mFileactions, &this->mSpawnattr, \
			this->mArgv, this->mEnvp);
}
void POSIX_PROCESS::join(int &value) {
	wait(&value);
}

3. schedule.cpp

/*************************************************************************
    > File Name: schedule.cpp
    > Author: wangzhicheng
    > Mail: 2363702560@qq.com 
    > Created Time: Thu 12 Feb 2015 08:01:44 PM WST
 ************************************************************************/
#include "posix_process.h"
int main(int argc, char **argv, char **envp) {
	string program_path;
	cin >> program_path;
	POSIX_PROCESS process(program_path, argv, envp);
	int value;
	process.run();
	process.join(value);

	return 0;
}

4. makefile

CC=g++
all:
	$(CC) -g -o main schedule.cpp posix_process.cpp posix_process.h

Èý ³ÌÐòÔËÐнØÍ¼


¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºPOJ1459Power Network£¨µçÍø£©¨D¨.. ÏÂһƪ£ºCodeForces 171F£¨Ç§¹ÅÉñÌâ¡£¡££©

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤ÔõÑùÓà Python дһ (2025-12-27 02:49:19)
¡¤ÈçºÎѧϰpythonÊý¾Ý (2025-12-27 02:49:16)
¡¤ÏëÒª×ÔѧÊý¾Ý·ÖÎö£¬ (2025-12-27 02:49:14)
¡¤Java ¼¯ºÏ¿ò¼Ü - ²Ë (2025-12-27 02:19:36)
¡¤Java¼¯ºÏ¿ò¼Ü×îÈ«Ïê (2025-12-27 02:19:33)