1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
|
.\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Modified 1996-10-22, Eric S. Raymond <esr@thyrsus.com>
.\" Modified 2002-01-08, Michael Kerrisk <mtk.manpages@gmail.com>
.\" Modified 2003-04-28, Ernie Petrides <petrides@redhat.com>
.\" Modified 2004-05-27, Michael Kerrisk <mtk.manpages@gmail.com>
.\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
.\" Language and formatting clean-ups
.\" Added notes on /proc files
.\" 2005-04-08, mtk, Noted kernel version numbers for semtimedop()
.\" 2007-07-09, mtk, Added an EXAMPLE code segment.
.\"
.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
.\" all rights reserved.
.\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Updated 2003-02-09, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2003-09-12, Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2005-03-01, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" Updated 2005-04-17, Akihiro MOTOKI
.\" Updated 2005-09-06, Akihiro MOTOKI
.\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
.\"
.\"WORD: semaphore ޥե
.\"WORD: member С
.\"WORD: process ץ
.\"WORD: system call ƥॳ
.\"WORD: undo ɥ
.\"WORD: signal ʥ
.\"WORD: catch (catch)
.\"WORD: process-ID ץID
.\"WORD: policy
.\"WORD: implement
.\"WORD: queue 塼
.\"WORD: free (free).
.\"WORD: memory
.\"WORD: anonymous structure ̵̾¤
.\"WORD: time limit »
\"
.TH SEMOP 2 2008-10-04 "Linux" "Linux Programmer's Manual"
.SH ̾
semop, semtimedop \- ޥե
.SH
.nf
.B #include <sys/types.h>
.B #include <sys/ipc.h>
.B #include <sys/sem.h>
.sp
.BI "int semop(int " semid ", struct sembuf *" sops ", unsigned " nsops );
.sp
.BI "int semtimedop(int " semid ", struct sembuf *" sops ", unsigned " nsops ,
.BI " struct timespec *" timeout );
.fi
.sp
.in -4n
glibc εǽޥ
.RB ( feature_test_macros (7)
):
.in
.sp
.BR semtimedop ():
_GNU_SOURCE
.SH
ޥե (semaphore set) ΥСγƥޥե
ʲδϢäƤ:
.sp
.in +4n
.nf
unsigned short semval; /* ޥե */
unsigned short semzcnt; /* Ԥĥץ */
unsigned short semncnt; /* äԤĥץ */
pid_t sempid; /* ǸԤʤäץ */
.sp
.in -4n
.fi
.BR semop ()
.I semid
ǻꤵ줿ޥե줿ޥեФԤ
.I sops
.I nsops
ĤǤؤγǤϸġΥޥե
Фη
.I struct sembuf
ǡΥФ:
.sp
.in +4n
.nf
unsigned short sem_num; /* ޥեֹ */
short sem_op; /* ޥե */
short sem_flg; /* ե饰 */
.sp
.in -4n
.fi
.I sem_flg
ˤ
.B IPC_NOWAIT
.B SEM_UNDO
Ǥ롣
.B SEM_UNDO
ꤵ줿ϡΥץλ˼ưŪ˼ä롣
.PP
.I sops
˴ޤޤνϡ
.I "ν"
ǡ
.I ȥߥå
¹Ԥ롣
ʤƤ˼¹Ԥ뤫¹Ԥʤ
ɤ餫Ȥʤ롣
Ƥľ˼¹ԤǤʤΤΥƥॳο
ġ
.I sem_flg
եɤ
.B IPC_NOWAIT
¸ߤ뤫ˤäƷޤꡢҤΤ褦ˤʤ롣
줾ϥޥե
.IR sem_num
ΥޥեФƼ¹Ԥ롣ޥեκǽΥޥեˤ
ֹ 0 롣
ϻढꡢ
.I sem_op
ͤǶ̤롣
.PP
.I sem_op
ξ硢ȤƤͤޥե
.RI ( semval )
˲ä롣ˤ
.B SEM_UNDO
ꤵƤϡƥϤΥޥե ץɥ
.RI ( semadj )
롣
ɬ¹ԤǤץߤϵʤ
ƤӽФץоݤΥޥեѹĤʤФʤʤ
.PP
.I sem_op
0 ξ硢֥ޤԤġǤ롣ξ硢ץ
ΥޥեФɤ߹ߵĤʤФʤʤ
.I semval
0 ʤСľ˹Ԥ롣
.I semval
0 Ǥʤ硢
.I sem_flg
.B IPC_NOWAIT
ꤵƤС
.BR semop ()
ϼԤ
.B errno
.B EAGAIN
ꤵ (ΤȤ
.I sops
Ф¹Ԥʤ)
.I sem_flg
.B IPC_NOWAIT
ꤵƤʤ硢
.I semzcnt
(ޥեͤ 0 ˤʤΤԤäƤץο) 1 äơ
ʲΤ줫ޤǥץ (sleep) 롣
.IP \(bu 3
.I semval
0 ˤʤä: ΤȤ
.I semval
ͤ 1 롣
.IP \(bu
ޥե礬줿: ΤȤ
.BR semop ()
ϼԤ
.I errno
.B EIDRM
ꤵ롣
.IP \(bu
ƤӽФץʥͤ: ΤȤ
.I semzcnt
ͤ 1 졢
.BR semop ()
ϼԤ
.I errno
.B EINTR
ꤵ롣
.IP \(bu
.\" motoki: semop () semtimedop () δְ㤤
.BR semtimedop ()
.I timeout
ǻꤵ줿»֤вᤷ: ΤȤ
.BR semtimedop ()
ϼԤ
.I errno
.B EAGAIN
ꤵ롣
.PP
.I sem_op
0 ̤ξ硢ץˤϤΥޥեѹĤʤ
ʤʤ
.I semval
.I sem_op
Ͱʾξϡľ˼¹Ԥ:
.I semval
.I sem_op
ͤ롣
ˡ
.B SEM_UNDO
ꤵƤϡΥޥեΥץɥ
.RI ( semadj )
롣
.I semval
.I sem_op
ͤ꾮
.I sem_flg
.B IPC_NOWAIT
ꤵ줿ϡ
.BR semop ()
ϼԤ
.I errno
.B EAGAIN
ꤵ (ΤȤ
.I sops
¹Ԥʤ)
.B IPC_WAIT
ꤵƤʤС
.I semncnt
(ΥޥեͤäΤԤäƤץΥ)
1 äơʲΤ줫ޤǥץ (sleep) 롣
.IP \(bu 3
.I semval
.I sem_op
Ͱʾˤʤä: ΤȤ
.I semncnt
1 졢
.I semval
.I sem_op
ͤ롣
.B SEM_UNDO
ꤵƤˤϤΥޥեΥץɥ
.RI ( semadj )
롣
.IP \(bu
ޥե礬ƥफ줿: ΤȤ
.BR semop ()
ϼԤ
.I errno
.B EIDRM
ꤵ롣
.IP \(bu
ƤӽФץʥͤ: ΤȤ
.I semncnt
1 졢
.BR semop ()
ϼԤ
.I errno
.B EINTR
ꤵ롣
.IP \(bu
.\" motoki: the system call semtimedop () Τȡ
.BR semtimedop ()
.I timeout
ǻꤵ줿»֤вᤷ: ΤȤ
.BR semtimedop ()
ϼԤ
.I errno
.B EAGAIN
ꤵ롣
.PP
硢
.I sops
ؤˤäоݤȤʤäƥޥե
.I sempid
СˤϸƤӽФץΥץ ID ꤵ롣
.I sem_otime
.\"
.\" .I sem_ctime
˸郎ꤵ롣
.PP
.BR semtimedop ()
ؿο
.BR semop ()
Ʊ
ƤӽФץߤ硢ߴ֤ξ¤
.I timeout
λؤ
.I timespec
¤Τǻꤵ줿֤Ȥʤۤʤ롣
ꤷ»֤ãϡ
.BR semtimedop ()
ϼԤ
.I errno
.B EAGAIN
ꤵ
(ΤȤ
.I sops
ϼ¹Ԥʤ)
.I timeout
NULL ξ硢
.BR semtimedop ()
ؿο
.BR semop ()
ؿƱˤʤ롣
.SH ֤
硢
.BR semop ()
.BR semtimedop ()
0 ֤Ǥʤ \-1 ֤
顼
.I errno
ꤹ롣
.SH 顼
Ԥ硢
.I errno
˰ʲΤɤ줫ꤵ:
.TP
.B E2BIG
.I nsops
.B SEMOPM
礭
.B SEMOPM
ϰΥƥॳǵκĿǤ롣
.TP
.B EACCES
ƤӽФץˤϻꤵ줿ޥեԤΤ
ɬפʥĤʤ
.B CAP_IPC_OWNER
ѥӥƥʤ
.TP
.B EAGAIN
ľ˽뤳ȤǤ
.I sem_flg
.B IPC_NOWAIT
ꤵƤ뤫
.I timeout
ǻꤵ줿»֤вᤷ
.TP
.B EFAULT
.I sops
.I timeout
ؤƤ륢ɥ쥹˥Ǥʤ
.TP
.B EFBIG
ǡ
.I sem_num
ͤ 0 ̤ΥޥեοʾǤ롣
.TP
.B EIDRM
ޥե礬줿
.TP
.B EINTR
ΥƥॳߤƤ˥ץʥͤ
.BR single (7)
ȡ
.TP
.B EINVAL
ޥե礬¸ߤʤ
.I semid
0 ̤Ǥ뤫
.I nsops
οǤʤ
.TP
.B ENOMEM
.I sem_flg
.B SEM_UNDO
ꤵ줿ƥ˥ɥ¤Τ˳Ƥ뽽ʬʥ꤬ʤ
.TP
.B ERANGE
.I sem_op+semval
.B SEMVMX
礭
.B SEMVMX
.I semval
κͤǡͤϼ¸Ǥ롣
.SH С
.BR semtimedop ()
Linux 2.5.52 ǽо줷
줫饫ͥ 2.4.22 ˤܿ줿
.BR semtimedop ()
glibc ǤΥݡȤϥС 2.3.3 ǽо줷
.SH
SVr4, POSIX.1-2001.
.\" SVr4 ˤϡɲä EINVAL, EFBIG, ENOSPC Υ顼֤ˤĤƤ
.\" Ҥ롣
.SH
ץ
.I sem_undo
¤Τ
.BR fork (2)
줿ҥץˤϷѾʤ
.BR execve (2)
ƥॳξϷѾ롣
.PP
.BR semop ()
ϥʥϥɥˤäǤ줿ˡ
褷ƼưŪ˺Ƴ뤳ȤϤʤ
Ȥʥϥɥ
.B SA_RESTART
ե饰åȤƤƤƳ뤳ȤϤʤ
.PP
.I semadj
ϥץȤǡ
.B SEM_UNDO
ե饰ꤷƼ¹Ԥ줿ƤΥޥե()Ǥ롣
.BR semctl (2)
.B SETVAL
ޤ
.B SETALL
ꤷޥեͤ
ľꤵ줿ˤϡƤΥץˤб
.I semadj
ͤꥢ롣
.PP
륻ޥե \fIsemval\fP, \fIsempid\fP, \fIsemzcnt\fP, \fIsemnct\fP
ͤϤ⡢Ŭڤꤷ
.BR semctl (2)
ƤӽФȤǼǤ롣
.PP
ޥեΥ˴ؤ¤Τ
.BR semop ()
˱ƶڤܤΤʲ˵:
.TP
.B SEMOPM
.BR semop ()
ǵκ (32)
(Linux Ǥϡͤ
.I /proc/sys/kernel/sem
3եɤбɤ߽ФѹǤ)
.\" /proc ե Linux 2.2 ǤѤǤʤ -- MTK
.TP
.B SEMVMX
.I semval
: ¸ (32767)
.PP
ʲͤ˴ؤƤϼ¸¤Ϥʤ
λĴ (adjust on exit) κ
.RB ( SEMAEM )
ƥΤΥɥ¤Τκ
.RB ( SEMMNU )
ץΥɥ¤Τκ
.SH Х
ץλݡץб
.I semadj
νȤäơ
.B SEM_UNDO
ե饰դǼ¹Ԥ줿ƤΥޥեαƶä
ˤꤢ꤬ȯ: ΥޥեĴԤäƤȡ
ˤϥޥեͤ 0 ̤ͤˤ褦Ȥ礬ФƤ롣
Τ褦ʾ硢ɤΤ褦˼٤?
ҤȤĤιͤˡϡƤΥޥեĴ¹Ԥޤ
ߤ뤳ȤǤ롣ˡǤϥץνλ
Ĺ֤ˤ錄äߤ뤳ȤΤ˾ޤʤ
ɤ줯餤Ĺ֤ˤʤ뤫ʬʤ
̤ȤơΤ褦ʥޥեĴ̵뤷Ƥޤˡ
(ϥޥեȤ
.B IPC_NOWAIT
ꤹΤȾƤ)
Linux 軰μˡѤƤ: ޥեͤ (Ĥޤ
0 ޤ) ơץνλľ³ԤǤ褦ˤƤ롣
ͥ 2.6.x (x <= 10) ˤϡˤƥޥեͤ 0 ˤʤΤ
ԤäƤץޥեͤºݤ 0 ˤʤäȤ˵ (wake up)
ʤȤХ롣ΥХϥͥ 2.6.11 ǽƤ롣
.\" Хݡ:
.\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2
.\" :
.\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
.SH
ʲʬŪʥɤϡ
ޥե 0 ͤ 0 ˤʤΤԤäƤ顢
ޥեͤ 1 û
.BR semop ()
Ȥäƥȥߥå (atomically) ˹Ԥ
.nf
struct sembuf sops[2];
int semid;
/* Code to set \fIsemid\fP omitted */
sops[0].sem_num = 0; /* Operate on semaphore 0 */
sops[0].sem_op = 0; /* Wait for value to equal 0 */
sops[0].sem_flg = 0;
sops[1].sem_num = 0; /* Operate on semaphore 0 */
sops[1].sem_op = 1; /* Increment value by one */
sops[1].sem_flg = 0;
if (semop(semid, sops, 2) == \-1) {
perror("semop");
exit(EXIT_FAILURE);
}
.fi
.SH Ϣ
.BR semctl (2),
.BR semget (2),
.BR sigaction (2),
.BR capabilities (7),
.BR sem_overview (7),
.BR svipc (7),
.BR time (7)
|