Working with processes

Return to homepage

Handling signals

  1. Create a simple program that prints status message and waits for several seconds in a loop.
  2. Run the program for several seconds and then send it SIGINT signal using the kill command.
  3. Chage action taken by the process on receipt of SIGINT signal. Make proccess to print a message and end the process. Use either signal or sigaction system calls.
  4. Make copy of the program from the step "Creating a sub-process and running a program", but change the execve call to execute the program created in the previous steps.

Communication between processes using pipes

  1. Make copy of the program created in the previous section "Handling signals"
  2. Modify the program to sleep for 5 seconds and write a message to output file on receipt of a signal. File descriptor is provided in first command line argument of the program.
  3. Consider the following program (you have already seen it in the previous seminar). Change it so the child process immediately swaps its program with the program created in the previous step.
  4. 
    #include <stdio.h>
    int main(void)
    {
        printf("Hello world\n");
        pid_t p = fork();
        switch(p)
        {
        case 0:
            printf("Child is running\n");
            break;
        case -1: 
            perror("fork");
            break;
        default: 
            printf("Parent is running, fork returned %d\n", p);
        }
    }
  5. Modify the parent process program to create unnamed pipe. File descriptor associated to the input end of the pipe is the argument value provided to the program executed in the subprocess.
  6. Change parent to dispatch a signal to the child process using the kill() system call and immediately read the output end of the pipe after.

Homework 5

First part of either variant of homework 6.