├── Homework1 ├── CMakeLists.txt ├── Process.cpp ├── Process.h └── main.cpp ├── Homework2 ├── HomeWork2(Sayed Moeid Heidari).pdf └── main.cpp ├── Homework3 ├── HomeWork2(Sayed Moeid Heidari).pdf └── Saint Petersburg Electrotechnical University LETI.pdf └── README.md /Homework1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(HomwWork1) 3 | 4 | set(CMAKE_CXX_STANDARD 14) 5 | 6 | add_executable(HomwWork1 main.cpp Process.cpp Process.h) -------------------------------------------------------------------------------- /Homework1/Process.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Moeid Heidari on 3/16/20. 3 | // 4 | 5 | #include "Process.h" 6 | 7 | pid_t Process::getMProcessId() const { 8 | return m_Process_Id; 9 | } 10 | 11 | void Process::setMProcessId(pid_t mProcessId) { 12 | m_Process_Id = mProcessId; 13 | } 14 | 15 | uid_t Process::getMUserId() const { 16 | return m_User_Id; 17 | } 18 | 19 | void Process::setMUserId(uid_t mUserId) { 20 | m_User_Id = mUserId; 21 | } 22 | 23 | gid_t Process::getMGroupId() const { 24 | return m_Group_Id; 25 | } 26 | 27 | void Process::setMGroupId(gid_t mGroupId) { 28 | m_Group_Id = mGroupId; 29 | } 30 | 31 | Process::Process(pid_t mProcessId, uid_t mUserId, gid_t mGroupId,pid_t mParentProcessId) : m_Process_Id(mProcessId), m_User_Id(mUserId), 32 | m_Group_Id(mGroupId),m_Parent_Process_Id(mParentProcessId) { 33 | 34 | } 35 | 36 | std::ostream &operator<<(std::ostream &os, const Process &process) { 37 | os << "m_Process_Id: " << process.m_Process_Id << " m_User_Id: " << process.m_User_Id << " m_Group_Id: " 38 | << process.m_Group_Id << "m_Parent_Process_Id"<(const Process &rhs) const { 57 | return rhs < *this; 58 | } 59 | 60 | bool Process::operator<=(const Process &rhs) const { 61 | return !(rhs < *this); 62 | } 63 | 64 | bool Process::operator>=(const Process &rhs) const { 65 | return !(*this < rhs); 66 | } 67 | 68 | Process::Process() 69 | { 70 | m_Process_Id = fork(); 71 | m_User_Id=getuid(); 72 | m_Group_Id=getgid(); 73 | m_Parent_Process_Id=getppid(); 74 | this->printProcess(); 75 | } 76 | 77 | 78 | bool Process::operator==(const Process &rhs) const { 79 | return m_Process_Id == rhs.m_Process_Id && 80 | m_User_Id == rhs.m_User_Id && 81 | m_Group_Id == rhs.m_Group_Id && 82 | m_Parent_Process_Id==rhs.m_Parent_Process_Id; 83 | 84 | } 85 | 86 | bool Process::operator!=(const Process &rhs) const { 87 | return !(rhs == *this); 88 | } 89 | 90 | Process *Process::createNewChild() { 91 | Process *process; 92 | try { 93 | process=new Process(); 94 | 95 | }catch (const char* message) 96 | { 97 | throw "Wrong process Id"; 98 | } 99 | 100 | 101 | return process; 102 | } 103 | 104 | Process::~Process() { 105 | 106 | } 107 | 108 | pid_t Process::getMParentProcessId() const { 109 | return m_Parent_Process_Id; 110 | } 111 | 112 | void Process::setMParentProcessId(pid_t mParentProcessId) { 113 | m_Parent_Process_Id = mParentProcessId; 114 | } 115 | 116 | void Process::printProcess(void) 117 | { 118 | std::cout<<"processId:"<getMProcessId()<getMParentProcessId()<getMUserId()<getMGroupId()< 6 | #include 7 | #include 8 | #include 9 | 10 | #ifndef HOMWWORK1_PROCESS_H 11 | #define HOMWWORK1_PROCESS_H 12 | 13 | 14 | class Process{ 15 | 16 | private: 17 | pid_t m_Process_Id=0; 18 | pid_t m_Parent_Process_Id=0; 19 | uid_t m_User_Id=0; 20 | gid_t m_Group_Id=0; 21 | public: 22 | pid_t getMProcessId() const; 23 | 24 | void setMProcessId(pid_t mProcessId); 25 | 26 | uid_t getMUserId() const; 27 | 28 | void setMUserId(uid_t mUserId); 29 | 30 | gid_t getMGroupId() const; 31 | 32 | void setMGroupId(gid_t mGroupId); 33 | 34 | pid_t getMParentProcessId() const; 35 | 36 | void setMParentProcessId(pid_t mParentProcessId); 37 | 38 | Process(pid_t mProcessId, uid_t mUserId, gid_t mGroupId,pid_t mParentProcessId); 39 | 40 | Process(); 41 | 42 | virtual ~Process(); 43 | 44 | bool operator==(const Process &rhs) const; 45 | 46 | bool operator!=(const Process &rhs) const; 47 | 48 | bool operator<(const Process &rhs) const; 49 | 50 | bool operator>(const Process &rhs) const; 51 | 52 | bool operator<=(const Process &rhs) const; 53 | 54 | bool operator>=(const Process &rhs) const; 55 | 56 | friend std::ostream &operator<<(std::ostream &os, const Process &process); 57 | 58 | Process* createNewChild(); 59 | void printProcess(void); 60 | 61 | 62 | }; 63 | 64 | 65 | #endif //HOMWWORK1_PROCESS_H 66 | -------------------------------------------------------------------------------- /Homework1/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "Process.h" 4 | using namespace std; 5 | int main(void) 6 | { 7 | 8 | //homework 1-1 9 | try { 10 | Process* firstProcess=new Process(); 11 | Process* firstProcessChild=firstProcess->createNewChild(); 12 | Process* leftChild=firstProcessChild->createNewChild(); 13 | Process* righChildt=firstProcessChild->createNewChild(); 14 | } 15 | catch (const char* message) 16 | { 17 | cout<createNewChild()->createNewChild()->createNewChild(); 24 | } 25 | catch (const char* message) 26 | { 27 | cout<createNewChild(); 34 | Process* rightChild=firstProcess->createNewChild(); 35 | Process* secondProssessRightChild=rightChild->createNewChild(); 36 | 37 | } 38 | catch (const char* message) 39 | { 40 | cout< 10 | #include 11 | #include 12 | #include 13 | #include 14 | typedef std::numeric_limits dbl; 15 | int main (int argc, char *argv[]) 16 | { 17 | long num_steps = 100000000; 18 | int PAD=8; 19 | int NUM_THREADS =2; 20 | if(argc==3) 21 | { 22 | num_steps=(long) argv[0]; 23 | NUM_THREADS=atoi(argv[1]); 24 | PAD=atoi(argv[2]); 25 | } 26 | 27 | double step; 28 | double n; 29 | int fd[2]; 30 | pid_t pid; 31 | char line[255]; 32 | int i, nthreads; double pi, sum[NUM_THREADS][PAD]; 33 | step = 1.0/(double) num_steps; 34 | omp_set_num_threads(NUM_THREADS); 35 | std::cout.precision(dbl::max_digits10) 36 | if (pipe(fd) < 0) { 37 | printf("Error while call function pipe\n"); 38 | return 1; 39 | } 40 | 41 | if ((pid = fork()) < 0) { 42 | printf("Error while call function fork\n"); 43 | return 1; 44 | } else if (pid > 0) { 45 | close(fd[0]); 46 | #pragma omp parallel 47 | { int i, id,nthrds; 48 | 49 | 50 | id = omp_get_thread_num(); 51 | nthrds = omp_get_num_threads(); 52 | 53 | if (id == 0) threadNumbers = nthrds; 54 | 55 | #pragma omp parallel for 56 | 57 | for (i=0;i< num_steps; i+=nthrds) 58 | 59 | { 60 | 61 | x = (i+0.5)*step; 62 | #pragma omp critical 63 | sum[id][0] += 4.0/(1.0+x*x); 64 | 65 | } 66 | 67 | } 68 | 69 | for(i=0, pi=0.0;i