If I use the terminal; I know the method: cd/proc/PID then cat status
The second line of this file shows the state of the processus(running-zombie-...)
but I want write a programm C that contains a function,its argument is PID of processus
I prefer to use the type pid_t
the role of my function is open the file /proc/PID/status and display the state of one processus that exists in the second line. The calling processus should display its state by using this function.
after this; the parent processus should create a child processus, the child processus should display the state of its parent and it ends.
the parent processus should display the state of its child,then it retrieves the return value of its child by using the primitive wait() and display the state of its child ,finally it ends.
How can write a program to do this????? ANY HELP!!!
You described reasonably well what to do. So I don't really understand what's your problem. Don't you know:
- How to open, read and write from/to a file?
- How to fork of a child? (man fork)
- How to terminate a process? (man exit)
- How to get a process pid? (man getpid)
- Surely wait(2) seems not to be your problem.