2015-10-03 07:43:18 +08:00
|
|
|
/****************************************************************************
|
2014-08-09 06:57:47 +08:00
|
|
|
* sched/task/task_getpid.c
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2024-09-11 19:45:11 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 23:33:58 +08: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 07:21:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08: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 07:21:28 +08:00
|
|
|
*
|
2015-10-03 07:43:18 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2015-10-03 07:43:18 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Included Files
|
2015-10-03 07:43:18 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sched.h>
|
2018-12-31 01:58:19 +08:00
|
|
|
#include <errno.h>
|
2012-07-15 03:30:31 +08:00
|
|
|
|
2014-08-09 07:53:55 +08:00
|
|
|
#include "sched/sched.h"
|
2014-08-09 06:57:47 +08:00
|
|
|
#include "task/task.h"
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2015-10-03 07:43:18 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Public Functions
|
2015-10-03 07:43:18 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2015-10-03 07:43:18 +08:00
|
|
|
/****************************************************************************
|
2023-02-01 16:36:45 +08:00
|
|
|
* Name: nxsched_getpid
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
|
|
|
* Description:
|
2022-11-15 14:37:20 +08:00
|
|
|
* Get the Process ID of the currently executing task.
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2018-12-30 22:41:06 +08:00
|
|
|
* Input parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2023-02-01 16:36:45 +08: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 22:41:06 +08:00
|
|
|
*
|
2015-10-03 07:43:18 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2023-02-01 16:36:45 +08:00
|
|
|
pid_t nxsched_getpid(void)
|
2007-02-18 07:21:28 +08:00
|
|
|
{
|
2014-04-11 00:20:44 +08:00
|
|
|
FAR struct tcb_s *rtcb;
|
|
|
|
|
2017-05-12 03:35:56 +08:00
|
|
|
/* Get the TCB at the head of the ready-to-run task list. That
|
2018-12-30 22:41:06 +08:00
|
|
|
* will usually be the currently executing task. There is are two
|
|
|
|
* exceptions to this:
|
|
|
|
*
|
2022-11-15 14:37:20 +08: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-11 00:20:44 +08:00
|
|
|
*/
|
|
|
|
|
2016-02-07 07:44:41 +08:00
|
|
|
rtcb = this_task();
|
2018-12-30 22:41:06 +08:00
|
|
|
if (rtcb != NULL)
|
2014-04-11 00:20:44 +08:00
|
|
|
{
|
2022-11-15 14:37:20 +08:00
|
|
|
/* Yes.. Return the Process ID */
|
2014-04-11 00:20:44 +08:00
|
|
|
|
2022-11-15 14:37:20 +08:00
|
|
|
return rtcb->group->tg_pid;
|
2014-04-11 00:20:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We must have been called earlier in the start up sequence from the
|
2016-02-11 06:53:34 +08:00
|
|
|
* start-up/IDLE thread before the ready-to-run list has been initialized.
|
2012-07-15 03:30:31 +08:00
|
|
|
*/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2022-03-22 06:47:09 +08:00
|
|
|
return IDLE_PROCESS_ID;
|
2007-02-18 07:21:28 +08:00
|
|
|
}
|
2023-02-01 16:36:45 +08: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();
|
|
|
|
}
|