niedziela, 19 marca 2017

Environment linux in class (g++)

#include <iostream>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>

using namespace std;
 

class linux_Environment
{
    private:
    size_t my_Size;
    char *text_Filename;
    char *size_linux_Directory;
    pid_t my_Pid;
    char *text_directory;
    int file;
    public:
    linux_Environment(char *directory)
    {
        text_directory="/proc/%d/environ";
        size_linux_Directory=new char[20000];
        text_Filename=new char[96];
        my_Pid=(pid_t) atoi(directory);
        snprintf(text_Filename,sizeof(text_Filename),text_directory,(int)my_Pid);
        file=open(text_Filename,O_RDONLY);
        my_Size=read(file,size_linux_Directory,sizeof(size_linux_Directory));
        close(file);
       
    }
    void write_Environment()
    {
        char *temp;
        size_linux_Directory[my_Size]='\0';
        temp=size_linux_Directory;
        do
        {
            cout<<temp<<endl;
            temp=temp+strlen(temp)+1;
        }while(temp<size_linux_Directory+my_Size);
    }
    ~linux_Environment()
    {
        delete size_linux_Directory;
        delete text_Filename;
    }
};

Brak komentarzy:

Prześlij komentarz