File tree Expand file tree Collapse file tree 3 files changed +3
-61
lines changed Expand file tree Collapse file tree 3 files changed +3
-61
lines changed Original file line number Diff line number Diff line change 2
2
#include <stdio.h>
3
3
#include <stdlib.h>
4
4
#include <unistd.h>
5
- #include <sys/wait.h>
6
5
7
- #define EXIT_FAILURE 1
6
+ #include "Common.h"
8
7
9
8
// To compile:
10
9
// gcc -std=gnu99 "01 - Signals_SIGCHLD.c" -o signals_sigchld
11
10
12
11
// Task:
13
12
// Create a program which creates a child process and handles SIGCHLD signal from its childs.
14
13
15
- void kill_child_handler (int sig )
16
- {
17
- int status ;
18
- pid_t done = waitpid (
19
- -1 , // Any child
20
- & status ,
21
- 0 ); // Blocked mode.
22
- if (done == -1 )
23
- {
24
- printf ("No more child processes.\n" );
25
- }
26
- else
27
- {
28
- short isNormalTermination = WIFEXITED (status );
29
- if (!isNormalTermination ||
30
- // WEXITSTATUS should be used only if normal termination = true.
31
- (isNormalTermination && WEXITSTATUS (status ) != 0 ))
32
- {
33
- printf ("Zombie for PID -- %d failed.\n" , done );
34
- exit (EXIT_FAILURE );
35
- }
36
- else
37
- {
38
- printf ("Zombie for PID -- %d successfully removed.\n" , done );
39
- }
40
- }
41
- }
42
-
43
14
int main ()
44
15
{
45
16
pid_t main_pid = getpid ();
Original file line number Diff line number Diff line change 2
2
#include <stdio.h>
3
3
#include <stdlib.h>
4
4
#include <unistd.h>
5
- #include <sys/wait.h>
6
5
7
- #define EXIT_FAILURE 1
6
+ #include "Common.h"
8
7
9
8
pid_t child_pid ;
10
9
Original file line number Diff line number Diff line change 5
5
#include <string.h>
6
6
#include <unistd.h>
7
7
#include <sys/file.h>
8
- #include <sys/wait.h>
9
8
#include <sys/types.h>
10
9
#include <sys/stat.h>
11
10
12
- #define EXIT_FAILURE 1
11
+ #include "Common.h"
13
12
14
13
// Compilation:
15
14
// gcc "02 - Flock.c" -o flockc
16
15
17
16
// This program imitates work of 3 processes (parent and 2 childs) with some file with flock-blocking, which means
18
17
// that 2 processes cannot both write into file, but can both read file in the same time. However it cannot write and read in the same time.
19
18
20
- void kill_child_handler (int sig )
21
- {
22
- int status ;
23
- pid_t done = waitpid (-1 , // Any child
24
- & status ,
25
- 0 ); // Blocked mode.
26
- if (done == -1 )
27
- {
28
- printf ("No more child processes.\n" );
29
- }
30
- else
31
- {
32
- short isNormalTermination = WIFEXITED (status );
33
- if (!isNormalTermination ||
34
- // WEXITSTATUS should be used only if normal termination = true.
35
- (isNormalTermination && WEXITSTATUS (status ) != 0 ))
36
- {
37
- printf ("Zombie for PID -- %d failed.\n" , done );
38
- exit (EXIT_FAILURE );
39
- }
40
- else
41
- {
42
- printf ("Zombie for PID -- %d successfully removed.\n" , done );
43
- }
44
- }
45
- }
46
-
47
19
int lock_write ()
48
20
{
49
21
int fd ;
You can’t perform that action at this time.
0 commit comments