Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- zad1 lab2
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main ()
- {
- pid_t potomek;
- potomek = fork ();
- if (potomek != 0) {
- printf ("RODZIC: ID procesu biezacego: %d\n", getpid ());
- printf ("ID dziecka: %d\n", potomek);
- }
- else {
- printf ("DZIECKO: ID procesu biezacego: %d\n", getpid ());
- printf ("ID rodzica: %d\n", getppid ());
- }
- return 0;
- }
- zad2
- #include <stdlib.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main ()
- {
- pid_t potomek;
- //Tworzenie procesu potomnego
- potomek = fork ();
- if (potomek > 0) {
- //To jest proces rodzica, ktory spi przez 60 sec
- sleep (10);
- }
- else {
- //To jest proces dziecka, ktory konczy sie natychmiast
- exit (0);
- }
- return 0;
- }
- zad 3
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- int main ()
- {
- int status;
- int potomek;
- potomek = fork ();
- //proces macierzysty
- if (potomek != 0) {
- wait(&status);
- if (WIFEXITED(status) > 0) {
- printf("status: %d\n", WEXITSTATUS(status));
- }
- else
- printf("Cos jest nie tak");
- }
- //proces potomny
- else {
- printf("proces potomny...\n");
- exit(0);
- }
- return 0;
- }
- zad4
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- void dziecko(int a);
- int main (int argc, char *argv[])
- {
- int status;
- int pid;
- pid_t potomek;
- int i, j;
- for(i = 1; i < atoi(argv[1])+1; i++) {
- potomek = fork ();
- if (potomek == 0) {
- pid = getpid();
- for(j = 0; j < 4; j++)
- printf("Potomek: %d PID: %d PPID: %d\n", i, getpid(), getppid());
- sleep(i);
- exit(0);
- }
- }
- while ((pid = wait(&status)) > 0)
- printf("\nPID: %d, status: %d\n", pid, status);
- return 0;
- }
- void dziecko(int a)
- {
- }
- zad5
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- int main ()
- {
- int status;
- int potomek;
- potomek = fork ();
- if (potomek == 0) {
- execlp("./zad5a", "zad5a", 0);
- }
- wait(&status);
- return 0;
- }
- zad 6
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <signal.h>
- void obsluz(int sygnal)
- {
- printf("------------------------\n");
- printf("Otrzymano sygnal nr: %d\n", sygnal);
- printf("------------------------\n");
- }
- int main(int argc, char **argv)
- {
- signal(SIGALRM, obsluz);
- int pid = getpid();
- kill(pid, SIGALRM);
- printf("Koniec programu.\n");
- return 0;
- }
- zad 7
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <signal.h>
- #include <sys/wait.h>
- void obsluz(int sygnal)
- {
- printf("------------------------\n");
- printf("Otrzymano sygnal nr: %d\n", sygnal);
- printf("------------------------\n");
- }
- int main(int argc, char **argv)
- {
- int potomek;
- int status;
- signal(SIGINT, obsluz);
- potomek = fork();
- if (potomek == 0) {
- kill(getppid(), SIGINT);
- }
- else {
- wait(&status);
- printf("Koniec programu.\n");
- }
- return 0;
- }
- zad 8
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <signal.h>
- #include <sys/wait.h>
- void obsluz(int sygnal)
- {
- printf("Otrzymano sygnal nr: %d\n", sygnal);
- }
- int main(int argc, char **argv)
- {
- int p1, p2, p3, p4;
- int a = 4, b = 4, c = 4, d = 4;
- int status;
- p1 = fork();
- p2 = fork();
- if(p1 == 0) {
- signal(SIGINT, obsluz);
- while(1) {
- printf("proces 1...\n");
- pause();
- sleep(1);
- kill(p2, SIGALRM);
- a--;
- }
- }
- if(p2 == 0) {
- signal(SIGALRM, obsluz);
- while(1) {
- printf("proces 2...\n");
- pause();
- sleep(1);
- kill(p1, SIGINT);
- b--;
- }
- }
- wait(&status);
- return 0;
- }
- zad 9
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- int main(int argc, char **argv)
- {
- int potomek;
- int status;
- int dana = 5;
- potomek = fork();
- if (potomek == 0) {
- printf("Potomek: %d\n", dana);
- printf("Potomek: %d\n", dana += 5);
- }
- else {
- wait(&status);
- printf("Rodzic: %d\n", dana);
- printf("Rodzic: %d\n", dana += 5);
- }
- return 0;
- }
- zad 10
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <signal.h>
- #include <sys/wait.h>
- void obsluz(int sygnal)
- {
- printf("------------------------\n");
- printf("Funkcja obslugujaca sygnal SIGINT\n");
- printf("Otrzymano sygnal nr: %d czyli SIGINT\n", sygnal);
- printf("------------------------\n");
- }
- void skomplikowana_funkcja()
- {
- printf("UWAGA !!! Skomplikowana operacja.\n");
- }
- int main(int argc, char **argv)
- {
- int potomek;
- int status;
- signal(SIGINT, obsluz);
- potomek = fork();
- if (potomek == 0) {
- kill(getppid(), SIGINT);
- }
- else {
- wait(&status);
- skomplikowana_funkcja();
- printf("Koniec programu.\n");
- }
- return 0;
- }
- zad 11
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <signal.h>
- #include <sys/wait.h>
- int main(int argc, char **argv)
- {
- int potomek;
- int status;
- sigblock(SIGINT);
- potomek = fork();
- if (potomek == 0) {
- kill(getppid(), SIGINT);
- }
- else {
- wait(&status);
- printf("Koniec programu.\n");
- }
- return 0;
- }
- zad 5b
- #include <stdio.h>
- int main(int argc, char **argv)
- {
- printf("\nAlbert lubi lowic ryby\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement