Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <signal.h>
- using namespace std;
- // Вариант №17, Verenuk A. A.
- int main()
- {
- int pid, k;
- char str[100];
- fstream file;
- file.open("pid.txt",ios::in);
- if(!file) {
- cout << "Невозможно открыть ФАЙЛ.\n";
- exit(0);
- }
- file.getline(str,100);
- k = atoi(str);
- file.close();
- // cout << "k: " << k << endl;
- // cout << "ppid: " << getppid() << endl;
- // cout << "pid: " << getpid() << endl;
- file.open("pid.txt",ios::out|ios::trunc);
- if(!file)
- {
- cout << "Невозможно создать ФАЙЛ.\n";
- exit(0);
- }
- if(k!=0)
- {
- kill(k,15);
- file << "0";
- }else{
- if ((pid=fork())!=0)
- {
- // cout << "forkpid: " << pid << endl;
- file << pid;
- }else{
- for(int i=1;i>0;i++)
- {
- sleep(100);
- }
- }
- }
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement