Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
exercises
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
os
exercises
Commits
2c9170a4
Commit
2c9170a4
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
finished ex5, i think?
parent
21547fd2
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
serie1/ex5/.gitignore
+2
-0
2 additions, 0 deletions
serie1/ex5/.gitignore
serie1/ex5/Makefile
+23
-0
23 additions, 0 deletions
serie1/ex5/Makefile
serie1/ex5/multi_process.c
+42
-0
42 additions, 0 deletions
serie1/ex5/multi_process.c
with
67 additions
and
0 deletions
serie1/ex5/.gitignore
0 → 100644
+
2
−
0
View file @
2c9170a4
*.o
multi_process
This diff is collapsed.
Click to expand it.
serie1/ex5/Makefile
0 → 100644
+
23
−
0
View file @
2c9170a4
CC
:=
clang
CFLAGS
:=
-g
-pedantic
-Wall
-Wextra
-std
=
c2x
LDFLAGS
:=
-fsanitize
=
address
-fsanitize
=
leak
-fsanitize
=
undefined
-lm
TARGET
:=
multi_process
all
:
$(TARGET)
$(TARGET)
:
multi_process.o
@
printf
"=================== Building executable ===================
\n
"
$(
CC
)
$(
CFLAGS
)
$^
-o
$@
$(
LDFLAGS
)
@
printf
"
\n
"
%.o
:
%.c
@
printf
"================== Building object files ==================
\n
"
$(
CC
)
$(
CFLAGS
)
-c
$<
@
printf
"
\n
"
.PHONY
:
clean
clean
:
rm
-f
*
.o
$(
TARGET
)
This diff is collapsed.
Click to expand it.
serie1/ex5/multi_process.c
0 → 100644
+
42
−
0
View file @
2c9170a4
#include
<stdio.h>
#include
<stdlib.h>
#include
<sys/types.h>
#include
<sys/wait.h>
#include
<unistd.h>
#define HOUR_IN_SEC 3600
int
main
(
void
)
{
pid_t
pid
=
-
1
;
pid
=
fork
();
if
(
pid
>
0
)
{
wait
(
NULL
);
fprintf
(
stdout
,
"parent(%d)
\n
"
,
getpid
());
fprintf
(
stdout
,
"return value of fork: %d
\n
"
,
pid
);
fprintf
(
stdout
,
"============= Counter =============
\n
"
);
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
fprintf
(
stdout
,
"%d
\n
"
,
i
);
}
fprintf
(
stdout
,
"===================================
\n
"
);
sleep
(
HOUR_IN_SEC
);
}
else
if
(
pid
==
0
)
{
fprintf
(
stdout
,
"child(%d)
\n
"
,
getpid
());
fprintf
(
stdout
,
"return value of fork: %d
\n
"
,
pid
);
fprintf
(
stdout
,
"============= Counter =============
\n
"
);
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
fprintf
(
stdout
,
"%d
\n
"
,
i
);
}
fprintf
(
stdout
,
"===================================
\n
"
);
exit
(
0
);
// sleep(HOUR_IN_SEC);
}
else
{
perror
(
"fork"
);
}
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment