2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2014-08-09 00:57:47 +02:00
|
|
|
* sched/task/task_getpid.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2024-09-11 13:45:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sched.h>
|
2018-12-30 18:58:19 +01:00
|
|
|
#include <errno.h>
|
2012-07-14 21:30:31 +02:00
|
|
|
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2014-08-09 00:57:47 +02:00
|
|
|
#include "task/task.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-10-03 01:43:18 +02:00
|
|
|
/****************************************************************************
|
2023-02-01 09:36:45 +01:00
|
|
|
* Name: nxsched_getpid
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2022-11-15 07:37:20 +01:00
|
|
|
* Get the Process ID of the currently executing task.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-12-30 15:41:06 +01:00
|
|
|
* Input parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2023-02-01 09:36:45 +01:00
|
|
|
* Normally when called from user applications, nxsched_getpid() will
|
|
|
|
* return the Process ID of the currently executing task. that is,
|
|
|
|
* the main task for the task groups. There is no specification for
|
|
|
|
* any errors returned from nxsched_getpid().
|
2018-12-30 15:41:06 +01:00
|
|
|
*
|
2015-10-03 01:43:18 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2023-02-01 09:36:45 +01:00
|
|
|
pid_t nxsched_getpid(void)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2014-04-10 18:20:44 +02:00
|
|
|
FAR struct tcb_s *rtcb;
|
|
|
|
|
2017-05-11 21:35:56 +02:00
|
|
|
/* Get the TCB at the head of the ready-to-run task list. That
|
2018-12-30 15:41:06 +01:00
|
|
|
* will usually be the currently executing task. There is are two
|
|
|
|
* exceptions to this:
|
|
|
|
*
|
2022-11-15 07:37:20 +01:00
|
|
|
* Early in the start-up sequence, the ready-to-run list may be
|
|
|
|
* empty! In this case, of course, the CPU0 start-up/IDLE thread with
|
|
|
|
* pid == 0 must be running, and
|
2014-04-10 18:20:44 +02:00
|
|
|
*/
|
|
|
|
|
2016-02-07 00:44:41 +01:00
|
|
|
rtcb = this_task();
|
2018-12-30 15:41:06 +01:00
|
|
|
if (rtcb != NULL)
|
2014-04-10 18:20:44 +02:00
|
|
|
{
|
2022-11-15 07:37:20 +01:00
|
|
|
/* Yes.. Return the Process ID */
|
2014-04-10 18:20:44 +02:00
|
|
|
|
2022-11-15 07:37:20 +01:00
|
|
|
return rtcb->group->tg_pid;
|
2014-04-10 18:20:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We must have been called earlier in the start up sequence from the
|
2016-02-10 23:53:34 +01:00
|
|
|
* start-up/IDLE thread before the ready-to-run list has been initialized.
|
2012-07-14 21:30:31 +02:00
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2022-03-21 23:47:09 +01:00
|
|
|
return IDLE_PROCESS_ID;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2023-02-01 09:36:45 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: getpid
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the Process ID of the currently executing task.
|
|
|
|
*
|
|
|
|
* Input parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Normally when called from user applications, getpid() will return the
|
|
|
|
* Process ID of the currently executing task. that is, the main task
|
|
|
|
* for the task groups. There is no specification for any errors
|
|
|
|
* returned from getpid().
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
pid_t getpid(void)
|
|
|
|
{
|
|
|
|
return nxsched_getpid();
|
|
|
|
}
|