MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / sys_kill

Function sys_kill

components/lwp/lwp_syscall.c:1375–1479  ·  view source on GitHub ↗

* @brief Sends a signal to a process or a group of processes. * * This system call sends the signal specified by `signo` to the process or process group * identified by `pid`. If `pid` is positive, the signal is sent to the process with the * specified process ID. If `pid` is `0`, the signal is sent to all processes in the * same process group as the caller. If `pid` is `-1`, the signal is se

Source from the content-addressed store, hash-verified

1373 * @see signal(), killpg(), raise()
1374 */
1375sysret_t sys_kill(int pid, int signo)
1376{
1377 rt_err_t kret = 0;
1378 sysret_t sysret;
1379 struct rt_lwp *lwp = RT_NULL;
1380
1381 /* handling the semantics of sys_kill */
1382 if (pid > 0)
1383 {
1384 /**
1385 * Brief: Match the pid and send signal to the lwp if found
1386 * Note: Critical Section
1387 * - pid tree (READ. since the lwp is fetch from the pid tree, it must stay there)
1388 */
1389 lwp_pid_lock_take();
1390 lwp = lwp_from_pid_raw_locked(pid);
1391 if (lwp)
1392 {
1393 lwp_ref_inc(lwp);
1394 lwp_pid_lock_release();
1395 }
1396 else
1397 {
1398 lwp_pid_lock_release();
1399 kret = -RT_ENOENT;
1400 }
1401
1402 if (lwp)
1403 {
1404 kret = lwp_signal_kill(lwp, signo, SI_USER, 0);
1405 lwp_ref_dec(lwp);
1406 }
1407 }
1408 else if (pid < -1 || pid == 0)
1409 {
1410 pid_t pgid = 0;
1411 rt_processgroup_t group;
1412
1413 if (pid == 0)
1414 {
1415 /**
1416 * sig shall be sent to all processes (excluding an unspecified set
1417 * of system processes) whose process group ID is equal to the process
1418 * group ID of the sender, and for which the process has permission to
1419 * send a signal.
1420 */
1421 pgid = lwp_pgid_get_byprocess(lwp_self());
1422 }
1423 else
1424 {
1425 /**
1426 * sig shall be sent to all processes (excluding an unspecified set
1427 * of system processes) whose process group ID is equal to the absolute
1428 * value of pid, and for which the process has permission to send a signal.
1429 */
1430 pgid = -pid;
1431 }
1432

Callers

nothing calls this directly

Calls 11

lwp_pid_lock_takeFunction · 0.85
lwp_from_pid_raw_lockedFunction · 0.85
lwp_ref_incFunction · 0.85
lwp_pid_lock_releaseFunction · 0.85
lwp_signal_killFunction · 0.85
lwp_ref_decFunction · 0.85
lwp_pgid_get_byprocessFunction · 0.85
lwp_selfFunction · 0.85
lwp_pgrp_findFunction · 0.85
lwp_pgrp_signal_killFunction · 0.85
lwp_signal_kill_allFunction · 0.85

Tested by

no test coverage detected