Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tp1-ProgDev-mertens-guilherme
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
Container 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mertens De Andrade Guilherme
tp1-ProgDev-mertens-guilherme
Commits
ce3bbe8b
Commit
ce3bbe8b
authored
5 months ago
by
Mertens De Andrade Guilherme
Browse files
Options
Downloads
Patches
Plain Diff
Server
parent
bf7622a5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server_5.c
+93
-0
93 additions, 0 deletions
server_5.c
with
93 additions
and
0 deletions
server_5.c
0 → 100644
+
93
−
0
View file @
ce3bbe8b
#include
<iostream>
#include
<csignal>
#include
<cstdlib>
#include
<fcntl.h>
#include
<unistd.h>
#include
<sys/stat.h>
volatile
bool
running
=
true
;
void
handle_signal
(
int
signal_number
)
{
std
::
cout
<<
"Server received signal: "
<<
signal_number
<<
std
::
endl
;
running
=
false
;
}
int
main
(){
// Signal handling
struct
sigaction
sa
;
sa
.
sa_handler
=
handle_signal
;
sa
.
sa_flags
=
0
;
sigemptyset
(
&
sa
.
sa_mask
);
if
(
sigaction
(
SIGINT
,
&
sa
,
nullptr
)
==
-
1
||
sigaction
(
SIGTERM
,
&
sa
,
nullptr
)
==
-
1
)
{
perror
(
"Failed to set signal handler"
);
exit
(
EXIT_FAILURE
);
}
const
char
*
fifo_path
=
"my_fifo"
;
// Open FIFO for writing
int
fd
=
open
(
fifo_path
,
O_WRONLY
);
if
(
fd
==
-
1
)
{
perror
(
"Server failed to open FIFO for writing"
);
exit
(
EXIT_FAILURE
);
}
int
number
=
0
;
while
(
running
)
{
// Write numbers to FIFO
if
(
write
(
fd
,
&
number
,
sizeof
(
number
))
==
-
1
)
{
perror
(
"Failed to write to FIFO"
);
running
=
false
;
}
std
::
cout
<<
"Server sent: "
<<
number
<<
std
::
endl
;
number
++
;
sleep
(
1
);
}
close
(
fd
);
std
::
cout
<<
"Server exiting..."
<<
std
::
endl
;
return
0
;
}
/*
erver sent: 53
Server sent: 54
Server sent: 55
Server sent: 56
Server sent: 57
Server sent: 58
Server sent: 59
Server sent: 60
Server sent: 61
killing the server:
Server sent: 99
Server sent: 100
Server received signal: 15
Server exiting...
output of client:
Client received: 97
Client received: 98
Client received: 99
Client received: 100
Failed to read from FIFO: Success
Client exiting...
with kill -9 client
Client received: 13
Client received: 14
Client received: 15
Client received: 16
[1] 11097 killed ./client_5
Server sent: 12
Server sent: 13
Server sent: 14
Server sent: 15
Server sent: 16
~/workspace:
*/
\ No newline at end of file
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