Sponsored Content
Full Discussion: Pid file and process check
Top Forums UNIX for Beginners Questions & Answers Pid file and process check Post 303036935 by Don Cragun on Wednesday 17th of July 2019 10:41:44 PM
Old 07-17-2019
I don't know of any OS that randomly picks the next PID to use when creating a new process. But, it is theoretically possible to do it that way.

Most of the systems I have worked on have a maximum PID value that is a configuration parameter. They start out assigning PIDs from 1 and increment the PID they want to assign by one every time a new process is created (e.g., by fork()), but before assigning that value, they check to see if that PID is currently in use. If it is in use, the OS tries again with the next possible PID until it finds one that is not in use. Using this method, you won't run into problems with PID recycling unless there are so many processes running on your system that you don't have many possible PIDs available that aren't in use.

Furthermore, if you have a ps utility that conforms to POSIX requirements, you can ask ps to just print the fields you want to see and not have to worry about some unexpected value in a field you aren't interested in containing what looks like a PID. (Look at your man page for the ps -o format option.)
These 3 Users Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Process PID

Hi Friends :p I have a little problem please help me out. I have a Unix based OS Sun Server having oracle 8i as database on it. The server has one client with windows OS. The client uses developer 2000 (GUI) to run query and run processes. I want to know how can I know the PID of a process run... (3 Replies)
Discussion started by: vanand420
3 Replies

2. Solaris

getting pid of process

hi all, Is there a simple script anyone could through out to me, to find the pid of a process given the name. I actually need to bind this pid to a processor set. I would probably put these comamns in a shell script which would have. a) kick start the executable b) get the pid c) bind it to a... (10 Replies)
Discussion started by: Naanu
10 Replies

3. UNIX for Dummies Questions & Answers

Need to get pid of a process and have to store the pid in a variable

Hi, I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this. Thanks in advance, Amudha (7 Replies)
Discussion started by: samudha
7 Replies

4. Shell Programming and Scripting

Get an PID of particular process

Hi I have written a shell script to find and kill the particular process. Here in shell script i have written the code like cnt = $(ps -ef | grep Shree) echo $cnt I am getting the output root 2326 2317 0 14:39:46 pts/1 0:28 Shree -f fdc.fbconf FDCapp.fbapp Here I want to... (2 Replies)
Discussion started by: Shreedhar Naik
2 Replies

5. Shell Programming and Scripting

getting pid from a process

Hi all, i was able to redirect pid of process to a file in the following way ps aux|awk '$11 == "/Applications/ProjectX/DServer" >> /Applications/ProjectX/DServer.pid it works fine but if one folder name caontains space its not working like below ps aux|awk '$11 == "/Applications/Project\... (1 Reply)
Discussion started by: kirankumars
1 Replies

6. Programming

[C] Process pid by name

Hi I use linux OS. I've already written a function that allow me to get the process name by pid. (searching in /proc). Now I'd like to perform the inverse task.I mean get the process pid by its name. I could write a function that search in every folder in /proc for the process name, but i... (2 Replies)
Discussion started by: Dedalus
2 Replies

7. Shell Programming and Scripting

Check process running Status with PID

Good day I am fairly new to Shell Scripting. I want a script to check if a process is up by checking the process's PID and then return a value for when it's running which would be 0. If it isn't running it should give any other value that 0. Any Help is appreciated Regards (9 Replies)
Discussion started by: 1nsyz1on
9 Replies

8. UNIX for Dummies Questions & Answers

Check who is writing to a file? (pid)

Hello, is there a way to check who is writing to a file? (pid) Like someone starts a ftp transfer, is uploading a file and I'd need to know which pid is actually writing to it. Or is there a way to check which file a process is currently accessing? Greetings and thanks for all your... (4 Replies)
Discussion started by: TehOne
4 Replies

9. AIX

How to get process name from PID?

HI, i used ps -ef | grep 3539052 | grep -v grep and i got a output like ths root 3539052 3407918 0 May 07 - 709:31 /usr/sbin/syslogd but what i need is instead of full path /usr/sbin/syslogd i want only the process name that is 'syslogd' here. (3 Replies)
Discussion started by: sumanthupar
3 Replies

10. Shell Programming and Scripting

Shell script to report file size, pid and also kill the process

Hi All, Looking for a quick LINUX shell script which can continuously monitors the flle size, report the process which is creating a file greater than certain limit and also kill that process. Can someone please help me on this? (4 Replies)
Discussion started by: vasavimacherla
4 Replies
process_id_max(5)						File Formats Manual						 process_id_max(5)

NAME
process_id_max - limit the maximum value for process IDs (PIDs) VALUES
Failsafe Default Minimum Maximum must be greater than or equal to If the difference between and inclusive is less than is effectively limited to this difference. DESCRIPTION
The tunable allows the administrator to select a potential value range for process IDs (PIDs) as generated by (see fork(2)). It allows the administrator to select a balance between compatibility, capacity, and aesthetics. Warning: Some programs cannot tolerate PID values up to the maximum. If such programs exist and are critical, the maximum PID should be appropriately constrained. For more details on these concerns, see below. Who is Expected to Change This Tunable? Anyone. Restrictions on Changing Do not increase the maximum PID if there are critical applications which assume that PIDs fit into a restricted range. (See below). The value of can be increased at any time, and it takes effect immediately. (However, its effect may not be noticed until a sufficient number of new processes have been created to cause the system to utilize the available higher values.) A decrease in the value of also takes effect immediately. However any existing processes with PIDs that are higher than the new value are not affected. The decrease will be in full effect for all processes only after a reboot. When Should the Value of This Tunable Be Raised? Increase the maximum PID if the range of PIDs defined by the and tunables needs to be increased to allow the creation of more simultaneous processes. See nproc(5) for limits on the number of processes. Increase the maximum PID in systems which have many active processes (for example, >25,000). The larger range may increase the efficiency of creating of new processes (because it may take less work to find available PIDs). If it is desired to validate that software programs execute properly in environments where PID values may be large, increase the tunable along with the tunable to force all new process IDs to take on large values. (See process_id_min(5) for more information.) Do not increase the maximum PID if there are critical applications which assume that PIDs fit into a restricted range. (See below.) What are the Side Effects of Raising the Value? If the difference between and tunables is less than the number of processes allowed to exist simultaneously is limited to that difference. When Should the Value of This Tunable Be Lowered? Lower the maximum PID if critical applications make assumptions that the PID range is restricted. What are the Side Effects of Lowering the Value? If the difference between and tunables is less than the number of processes allowed to exist simultaneously is limited to that difference. What Other Tunable Values Should Be Changed at the Same Time? It may be desirable to change For program development and validation, a change in the tunable may also be needed. Potential Application Issues The range of PID values has, in the past, been restricted to 0..30,000. Some programs have built-in assumptions about this range. This section briefly describes some of those assumptions. Some application programs have a built-in assumption that a PID does not exceed 30,000 (which was the old value of the (undocumented) and constants). They could fail if PIDs exceed this maximum. Some application programs store PIDs in 16-bit variables (type in C). Such programs could fail if the maximum PID exceeds 32,767. Some programs provide output formats which can be sensitive to the number of digits in the PID. Such programs may produce aesthetically displeasing output if PIDs exceed 5 digits (exceed 99,999). In some cases automatic expansion of output fields can disturb column align- ment. In some other cases, adjacent fields could run together, making the output incomprehensible. Some programs or scripts parse the outputs of other programs which contain PID values. Some such programs have built-in assumptions that a PID will not exceed five character positions. Such a program could fail if the range exceeds 99,999. Because session IDs (SIDs) and process group IDs (PGIDs) are the same as the process ID of the session or group leader, an increase in the maximum PID also increases the maximum SID and PGID. Though much less likely, the same application issues may exist for SIDs and PGIDs. WARNINGS
All HP-UX kernel tunable parameters are release specific. This parameter may be removed or have its meaning changed in future releases of HP-UX. The HP-UX kernel may silently round the selected values for and/or (e.g., to the nearest power of 2) in order to accommodate the PID gener- ation algorithm. Do not increase the maximum PID if there are critical applications which assume that PIDs fit into a restricted range. See the previous section, for more details on such programmatic assumptions. The default maximum (30,000) has been selected to provide compatibility with all such programs. This value should be used if program sensitivity to larger PID values is unknown. See process_id_min(5) for informa- tion about how large PID values can be selected for software validation purposes. Increasing the PID range does not increase the maximum number of processes in the system. Installation of optional kernel software, from HP or other vendors, may cause changes to tunable parameter values. After installation, some tunable parameters may no longer be at the default or recommended values. For information about the effects of installation on tun- able values, consult the documentation for the kernel software being installed. For information about optional kernel software that was factory installed on your system, see at AUTHOR
was developed by HP. SEE ALSO
fork(2), nproc(5), process_id_min(5). whitepaper, available on Tunable Kernel Parameters process_id_max(5)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy