Beruflich Dokumente
Kultur Dokumente
include
"
counter
.
h
"
2
3 oid
v counter
::
process
_
func
()
4 {
5
char
c
;
6
int
shmidct
,
shmid
;
7
key
_
t keyct
,
key
;
8
char
*
ct
,
*
shm
;
9
char
buffer
[
SHMSZ
]
;
10
11
/*
12
*
We need to get the segment named
13
* "
5678
"
,
created by the server
.
14
*/
15
keyct
=
5677
;
16
key
=
5678
;
17
18
/*
19
*
Locate the segment
.
20
*/
21
if
((
shmidct
=
shmget
(
keyct
,
2
,
0666
))
<
0
)
{
22
perror
(
"
shmget ct
"
)
;
23
}
24
if
((
shmid
=
shmget
(
key
,
SHMSZ
,
0666
))
<
0
)
{
25
perror
(
"
shmget
"
)
;
26
}
27
28
/*
29
*
Now we attach the segment to our data space
.
30
*/
31
if
((
ct
= (
char
*)
shmat
(
shmidct
,
NULL
,
0
)) == (
char
*) ‐
1
)
{
32
perror
(
"
shmat ct
"
)
;
33
}
34
if
((
shm
= (
char
*)
shmat
(
shmid
,
NULL
,
0
)) == (
char
*) ‐
1
)
{
35
perror
(
"
shmat
"
)
;
36
}
37
38 val
=
0
;
39
40 while
(
1
)
41 {
42 while
(*
ct
!=
'
s
'
)
;
43 printf
(
"%
s
"
,
shm
)
;
44 val
=
val
+
1
;
45 wait
(
1
)
;
46 *
ct
=
'
r
'
;
47 }
48 }
49