자신의 PID 넘버를 알수 있는 방법이 있나여?
글쓴이: jeeterm / 작성시간: 금, 2006/03/31 - 6:17오후
현재 프로그램을 짜서 돌리는게 있는데
메모리가 계속..세구 있어서..
그 사용량을 체크하려는데여..
Process ID 를 알면( 즉 345 라구 하면 ) /proc/345 디렉토리에
해당 프로세스 정보가 있다하네여..
혹시 C 프로그램에서.. ( Linux Redhat 9 ) 자신의 PID 를 구하려면
어떤 함수가 있나여?
예제가 있으면 더욱 좋구여..
그럼..숙5하시구여..
안양에서 맹가이버가..
Forums:


getpid
getpid
#include pid_t
#include
pid_t getpid(void);
pid_t getppid(void);
^^
#include pid_t
#include
pid_t getpid(void);
pid_t getppid(void);
^^
#include pid_t
#include < unistd.h >
pid_t getpid(void);
pid_t getppid(void);
^^
#include ( unistd.h ) pid_t
#include ( unistd.h )
pid_t getpid(void);
pid_t getppid(void);
* 꺽쇠를 입력하면 화면에 안나와서.. ( ) 가로로 대신함..
^^
<> 문제... 언젠간
<> 문제... 언젠간 고쳐지겠지만 당분간은 "<"를 써주시면 됩니다. 혹은 <code> 태그를 사용해 주셔도 됩니다. cinsk님의 "KLDP(drupal)에 글 쓸 때, 프로그램 소스 붙이기."글에 코드 입력에 대한 좋은 내용들이 있습니다.
----
$PWD `date`
$PWD `date`
Numeric Directories
Numeric Directories (Processes' PID Directories):
Each process subdirectory has the entries listed below in the form /proc/PID/:
Files:
cmdline: Command line arguments
environ: Values of environment variables
mem: Memory held by this process
stat: Process Status
status: Process status in human readable form
maps: Memory maps
statm: Process memory status information
mounts: Mounted filesystems
Links:
cwd: Link to the current working directory
exe: Link to the executable of this process
root: Link to the root directory of this process
Directories:
fd: Contains all file descriptors
If you check the file "status" by issuing the command "cat /proc/[PID]/status" you should see something like:
Example:
$ cat /proc/self/status
This will show you nearly the same information you would get if you viewed it with the ps command. In fact, ps uses the proc file system to obtain its information.
Example:
$ cat /proc/self/statm
91 91 76 4 0 87 15
$
The "statm" file contains more detailed information about the process memory usage. Its seven fields are explained below:
size total program size.
resident size of memory portions.
shared number of pages that are shared.
trs number of pages that are 'code'.
drs number of pages of data/stack.
lrs number of pages of library.
dt number of dirty pages.
* 출처: http://www.linux-me.org/index.php?option=articles&task=viewarticle&artid=21&Itemid=3
^^