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
7bd597f5
Commit
7bd597f5
authored
5 months ago
by
Mertens De Andrade Guilherme
Browse files
Options
Downloads
Patches
Plain Diff
continuation of code 3
parent
12bc11e7
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_3.c
+95
-0
95 additions, 0 deletions
server_3.c
with
95 additions
and
0 deletions
server_3.c
+
95
−
0
View file @
7bd597f5
...
...
@@ -4,6 +4,9 @@
#include
<unistd.h>
#include
<cstring>
#include
<unistd.h>
#include
<ctime>
#include
<sys/wait.h>
volatile
bool
running
=
true
;
...
...
@@ -57,6 +60,12 @@ int main(){
while
(
running
)
{
print_process_info
(
"Parent"
);
sleep
(
1
);
int
status
;
pid_t
result
=
waitpid
(
pid
,
&
status
,
WNOHANG
);
if
(
result
==
pid
)
{
std
::
cout
<<
"child dead, father stopping"
<<
std
::
endl
;
running
=
false
;
}
}
}
...
...
@@ -120,5 +129,91 @@ They have the same group id, and they both stop cin CTR+C because they belong to
and this singal is sent to all the process in the group
==============================================================================================================
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
2344 16628 16628 16628 pts/1 28184 Ss 911 0:02 /bin/zsh -i
2344 21290 21290 21290 pts/2 28302 Ss 911 0:00 /bin/zsh -i
16628 28184 28184 16628 pts/1 28184 S+ 911 0:00 ./a.out
28184 28185 28184 16628 pts/1 28184 S+ 911 0:00 ./a.out
21290 28302 28302 21290 pts/2 28302 R+ 911 0:00 ps aj
output:
58
Parent | id: 28184
Parent | father id: 16628
Parent | groupd id: 28184
58
Child | id: 28185
Child | father id: 28184
Child | groupd id: 28184
after killing the son:
36
Child | id: 28185
Parent | id: 28184
Child | father id: 28184
Child | groupd id: 28184
Parent | father id: 16628
5
Parent | groupd id: 28184
5
Child | id: 28185
Parent | id: 28184
Child | father id: 28184
Parent | father id: 16628
Child | groupd id: 28184
Parent | groupd id: 28184
46
46
Received signal: 15
Stopping the program
finished
Message during exit
Parent | id: 28184
Parent | father id: 16628
Parent | groupd id: 28184
29
AND
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
2344 16628 16628 16628 pts/1 28184 Ss 911 0:02 /bin/zsh -i
2344 21290 21290 21290 pts/2 28984 Ss 911 0:00 /bin/zsh -i
16628 28184 28184 16628 pts/1 28184 S+ 911 0:00 ./a.out
28184 28185 28184 16628 pts/1 28184 Z+ 911 0:00 [a.out] <defunct>
21290 28984 28984 21290 pts/2 28984 R+ 911 0:00 ps aj
the child continous there, but has a <defunct>
after killing first the parent:
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
2344 16628 16628 16628 pts/1 16628 Ss+ 911 0:02 /bin/zsh -i
2344 21290 21290 21290 pts/2 30012 Ss 911 0:01 /bin/zsh -i
1 29861 29860 16628 pts/1 16628 S 911 0:00 ./a.out
21290 30012 30012 21290 pts/2 30012 R+ 911 0:00 ps aj
the child continous to be running
If first I kill the child and then the father, both of them will desapear
After killing first the child:
Child | groupd id: 31529
29
Received signal: 15
Stopping the program
finished
Message during exit
child dead, father stopping
finished
Message during exit
*/
\ 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