// Lab 8, Working with structs
// Programmer : Maiar Khattab
// Editor(s) used : Code Blocks 13.12
// Compiler(s) used : Code Blocks 13.12
#include<iostream>
using std:: cout ;
using std:: endl ;
#include<cstdlib>
//struct def
struct tod
{
int hour; // the hr , 0-23
int minute; // the min, 0-59
int second; //the sec, 0-59
char descr [ 32 ] ; //the description of the time of day
} ;
//void printTod(const tod&);
int main ( )
{
cout << "Lab 8, Working With structs\n " ;
cout << "Programmer: Maiar Khattab\n " ;
cout << "Editor(s) used: Code Blocks 13.12\n " ;
cout << "Compiler(s) used: Code Blocks 13.12\n " ;
cout << "File: " << __FILE__ << endl;
cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
tod theTime[ ] = { { 12 ,0 ,0 , "noon" } ,
{ 0 ,0 ,0 ," midnight" } ,
{ 6 ,00 ,00 ," supper " } ,
{ 11 ,30 ,0 ,"bedtime" } } ;
for ( int i; i < 5 ; i++ )
{
char descr [ 32 ] ;
cout << theTime[ i] .descr << " is " << theTime[ i] .hour << ':'
<< theTime[ i] .minute << ":" << theTime[ i] .second << endl;
}
}
IC8vIExhYiA4LCBXb3JraW5nIHdpdGggc3RydWN0cwovLyBQcm9ncmFtbWVyIDogTWFpYXIgS2hhdHRhYgovLyBFZGl0b3IocykgdXNlZCA6IENvZGUgQmxvY2tzIDEzLjEyCi8vIENvbXBpbGVyKHMpIHVzZWQgOiBDb2RlIEJsb2NrcyAxMy4xMgoKI2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIHN0ZDo6Y291dDsKdXNpbmcgc3RkOjplbmRsOwoKI2luY2x1ZGU8Y3N0ZGxpYj4KCi8vc3RydWN0IGRlZgpzdHJ1Y3QgdG9kCnsKaW50IGhvdXI7Ly8gdGhlIGhyICwgMC0yMwppbnQgbWludXRlOy8vIHRoZSBtaW4sIDAtNTkKaW50IHNlY29uZDsvL3RoZSBzZWMsIDAtNTkKY2hhciBkZXNjciBbMzJdOy8vdGhlIGRlc2NyaXB0aW9uIG9mIHRo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A0L7RhtC10YHRgdCwCiAgICAgICAgICAgIHdhaXRwaWQocGlkMiwgJmFtcDtzdGF0dXMyLCAwKTsgIC8vINCe0LbQuNC00LDQtdC8INC30LDQstC10YDRiNC10L3QuNGPINCy0YLQvtGA0L7Qs9C+INC00L7Rh9C10YDQvdC10LPQviDQv9GA0L7RhtC10YHRgdCwCgogICAgICAgICAgICAvLyDQktGL0LLQvtC00LjQvCDRgdGC0LDRgtGD0YEg0LfQsNCy0LXRgNGI0LXQvdC40Y8g0LTQvtGH0LXRgNC90LjRhSDQv9GA0L7RhtC10YHRgdC+0LIKICAgICAgICAgICAgaWYgKFdJRkVYSVRFRChzdGF0dXMxKSkgewogICAgICAgICAgICAgICAgcHJpbnRmKCZxdW90O9CU0L7Rh9C10YDQvdC40Lkg0L/RgNC+0YbQtdGB0YEgMSDQt9Cw0LLQtdGA0YjQuNC70YHRjyDRgSDQutC+0LTQvtC8OiAlZFxuJnF1b3Q7LCBXRVhJVFNUQVRVUyhzdGF0dXMxKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKFdJRkVYSVRFRChzdGF0dXMyKSkgewogICAgICAgICAgICAgICAgcHJpbnRmKCZxdW90O9CU0L7Rh9C10YDQvdC40Lkg0L/RgNC+0YbQtdGB0YEgMiDQt9Cw0LLQtdGA0YjQuNC70YHRjyDRgSDQutC+0LTQvtC8OiAlZFxuJnF1b3Q7LCBXRVhJVFNUQVRVUyhzdGF0dXMyKSk7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIHByaW50ZigmcXVvdDvQoNC+0LTQuNGC0LXQu9GM0YHQutC40Lkg0L/RgNC+0YbQtdGB0YEg0LfQsNCy0LXRgNGI0LXQvS5cbiZxdW90Oyk7CiAgICAgICAgfQogICAgfQoKICAgIHJldHVybiAwOwp9Cg==
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
pid_t pid1, pid2;
// Создаем первый дочерний процесс
pid1 = fork();
if (pid1 < 0) {
// Ошибка при создании процесса
perror("fork failed");
exit(1);
}
if (pid1 == 0) {
// Дочерний процесс 1
printf("Дочерний процесс 1: PID = %d, Родительский PID = %d. Я работаю!\n", getpid(), getppid());
exit(0); // Завершаем процесс
} else {
// Родительский процесс продолжает выполнение
// Создаем второй дочерний процесс
pid2 = fork();
if (pid2 < 0) {
// Ошибка при создании второго процесса
perror("fork failed");
exit(1);
}
if (pid2 == 0) {
// Дочерний процесс 2
printf("Дочерний процесс 2: PID = %d, Родительский PID = %d. Я работаю!\n", getpid(), getppid());
exit(0); // Завершаем процесс
} else {
// Родительский процесс продолжает выполнение и ожидает завершения дочерних процессов
int status1, status2;
waitpid(pid1, &status1, 0); // Ожидаем завершения первого дочернего процесса
waitpid(pid2, &status2, 0); // Ожидаем завершения второго дочернего процесса
// Выводим статус завершения дочерних процессов
if (WIFEXITED(status1)) {
printf("Дочерний процесс 1 завершился с кодом: %d\n", WEXITSTATUS(status1));
}
if (WIFEXITED(status2)) {
printf("Дочерний процесс 2 завершился с кодом: %d\n", WEXITSTATUS(status2));
}
printf("Родительский процесс завершен.\n");
}
}
return 0;
}