Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ALP4-Tutorials
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mariah15
ALP4-Tutorials
Commits
f0d3ef8a
Commit
f0d3ef8a
authored
2 years ago
by
Mactavish
Browse files
Options
Downloads
Patches
Plain Diff
add process exercise
parent
aa2e488d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
exercises/process/makefile
+20
-0
20 additions, 0 deletions
exercises/process/makefile
exercises/process/mysystem.c
+61
-0
61 additions, 0 deletions
exercises/process/mysystem.c
with
81 additions
and
0 deletions
exercises/process/makefile
0 → 100644
+
20
−
0
View file @
f0d3ef8a
# Define required macros here
PROG
=
mysystem
OBJS
=
mysystem.o
CFLAG
=
-Wall
-g
CC
=
gcc
INCLUDE
=
-I
.
# binary target
$(PROG)
:
$(OBJS)
$(
CC
)
$(
CFLAGS
)
$(
INCLUDES
)
-o
$@
$(
OBJS
)
# implicit rule for building .o from .c
%.o
:
%.c
$(
CC
)
-c
-o
$@
$<
$(
CFLAGS
)
$(
INCLUDES
)
.PHONY
:
clean
# clean all the .o and executable files
clean
:
rm
-rf
*
.o
$(
PROG
)
This diff is collapsed.
Click to expand it.
exercises/process/mysystem.c
0 → 100644
+
61
−
0
View file @
f0d3ef8a
/**
* File: mysystem.c
* ----------------
* A program containing an implementation of a working shell that can
* execute entered text commands. It relies on our own implementation
* of system(), called mysystem(), that creates a process to execute
* a given shell command.
*/
#include
<stdbool.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<sys/wait.h>
#include
<unistd.h>
#include
<errno.h>
// The max-length shell command the user can enter
static
const
size_t
COMMAND_MAX_LEN
=
2048
;
/* Function: mysystem
* ------------------
* Parameters:
* command - the shell command to execute in another process
* Returns: the exit status of the command execution
*
* This function executes the given shell command using /bin/sh.
* It executes it in another process, and waits for that process
* to complete before returning. This function returns its exit status.
*
* Hint: use fork(), exec() family of functions, and waitpid()
* use "/bin/sh" and "-c" als the first two arguments to exec() family of
* Further information: https://www.baeldung.com/linux/exec-functions
*/
// Uncomment when implemented
static
int
mysystem
(
char
*
command
)
{
// TODO: implement this function
}
int
main
(
int
argc
,
char
*
argv
[])
{
char
command
[
COMMAND_MAX_LEN
];
while
(
true
)
{
printf
(
"> "
);
fgets
(
command
,
sizeof
(
command
),
stdin
);
// If the user entered Ctl-d, stop
if
(
feof
(
stdin
))
{
break
;
}
// Remove the \n that fgets puts at the end
command
[
strlen
(
command
)
-
1
]
=
'\0'
;
// TODO: use mysystem instead of system
int
commandReturnCode
=
system
(
command
);
printf
(
"return code = %d
\n
"
,
commandReturnCode
);
}
printf
(
"
\n
"
);
return
0
;
}
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