Exercises

team bbl


12.1

Run the program in Figure 12.17 on a Linux system, but redirect the output into a file. Explain the results.

12.2

Implement putenv_r, a reentrant version of putenv. Make sure that your implementation is async-signal safe as well as thread-safe.

12.3

Can you make the program in Figure 12.13 async-signal safe by blocking signals at the beginning of the function and restoring the previous signal mask before returning? Explain.

12.4

Write a program to exercise the version of getenv from Figure 12.13. Compile and run the program on FreeBSD. What happens? Explain.

12.5

Given that you can create multiple threads to perform different tasks within a program, explain why you might still need to use fork.

12.6

Reimplement the program in Figure 10.29 to make it thread-safe without using nanosleep.

12.7

After calling fork, could we safely reinitialize a condition variable in the child process by first destroying the condition variable with pthread_cond_destroy and then initializing it with pthread_cond_init?

    team bbl



    Advanced Programming in the UNIX Environment
    Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)
    ISBN: 0321525949
    EAN: 2147483647
    Year: 2005
    Pages: 370

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net