Skip to content

Commit

Permalink
Implemented x-platform getpid, started a process.h module for stuff l… (
Browse files Browse the repository at this point in the history
#546)

* Implemented x-platform getpid, started a process.h module for stuff like fork and process invoke etc...
  • Loading branch information
JonathanHenson authored Nov 15, 2019
1 parent b93006b commit 40296d9
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
26 changes: 26 additions & 0 deletions include/aws/common/process.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef AWS_COMMON_PROCESS_H
#define AWS_COMMON_PROCESS_H
/*
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.
*/

#include <aws/common/common.h>

AWS_EXTERN_C_BEGIN

AWS_COMMON_API int aws_get_pid(void);

AWS_EXTERN_C_END

#endif /* AWS_COMMON_PROCESS_H */
23 changes: 23 additions & 0 deletions source/posix/process.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.
*/

#include <aws/common/process.h>

#include <sys/types.h>
#include <unistd.h>

int aws_get_pid(void) {
return (int)getpid();
}
21 changes: 21 additions & 0 deletions source/windows/process.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.
*/
#include <aws/common/process.h>

#include <process.h>

int aws_get_pid(void) {
return _getpid();
}
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ add_test_case(test_background_log_channel_all)
add_test_case(test_pipeline_logger_unformatted_test)
add_test_case(test_pipeline_logger_formatted_test)

add_test_case(get_pid_sanity_check_test)

generate_test_driver(${CMAKE_PROJECT_NAME}-tests)

if (NOT MSVC AND NOT LEGACY_COMPILER_SUPPORT)
Expand Down
30 changes: 30 additions & 0 deletions tests/process_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.
*/

#include <aws/testing/aws_test_harness.h>

#include <aws/common/process.h>

static int s_get_pid_sanity_check_test_fn(struct aws_allocator *allocator, void *ctx) {
(void)allocator;
(void)ctx;

int pid = aws_get_pid();
ASSERT_TRUE(pid > 0);

return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(get_pid_sanity_check_test, s_get_pid_sanity_check_test_fn)

0 comments on commit 40296d9

Please sign in to comment.