Sponsored Content
Top Forums Programming Count Number Of Threads in a Process Post 33183 by S.P.Prasad on Wednesday 18th of December 2002 11:59:42 PM
Old 12-19-2002
We are working on SunOS Rel 5.8.Infact I have worked on the method - counting the number of subdirectories in the /proc/[pid]/lwp by using the following algorithm :

.......
/* After I have found the pid of the required process */
sprintf ( Dir , "/proc/%d/lwp" , pid ) ;
if ( ! chdir ( Dir ) ) {
Counter = 0 ;
if ((dp = opendir ( Dir ))!= NULL) {
while((dirp=readdir(dp))!=NULL)
if(dirp->d_name[0]!='.') Counter ++ ;
}
}
.......
I get the right count of subdirectories in the variable Counter. But the threads created in the program does not matches in number to subdirectories in /proc/[pid]/lwp. For example in an application I have created two thread by using pthread_create but number of subdirectories created in lwp directory for that process is five.I am not able to figure it as to why this difference exists.
 

10 More Discussions You Might Find Interesting

1. HP-UX

how to see the threads count of a process in hp unix?

hi,all: how to see the threads count of a process in hp unix? thanks (2 Replies)
Discussion started by: bugbugbug
2 Replies

2. Linux

Maximum number of threads handled by a process????

Hi Anybody knows max. no. of threads handled by a process in linux. Please reply Thanks in advnce :confused: (0 Replies)
Discussion started by: Agnello
0 Replies

3. UNIX for Advanced & Expert Users

Threads and Threads Count ?

Hi all, How can I get the list of all Threads and the Total count of threads under a particular process ? Do suggest !! Awaiting for the replies !! Thanks Varun:b: (2 Replies)
Discussion started by: varungupta
2 Replies

4. HP-UX

Need help. Unable to create threads after a certain number

Hi, I have a process which creates pthreads to generate some reports. After creating the reports these threads return null. But after 1024 threads, the process is not able to create any threads further.,and at max 5 threads are existing simultaneously and are returning the control back after... (2 Replies)
Discussion started by: Krsh
2 Replies

5. UNIX for Advanced & Expert Users

threads per process

What are the maximum number of threads possible per Process? Is it OS dependent? (1 Reply)
Discussion started by: digdarshan
1 Replies

6. Solaris

Number of threads running

Is there any command to find 1) the number of threads running 2) kernel boot mode in solaris box (2 Replies)
Discussion started by: vickylife
2 Replies

7. Shell Programming and Scripting

how to add the number of row and count number of rows

Hi experts a have a very large file and I need to add two columns: the first one numbering the incidence of records and the another with the total count The input file: 21 2341 A 21 2341 A 21 2341 A 21 2341 C 21 2341 C 21 2341 C 21 2341 C 21 4567 A 21 4567 A 21 4567 C ... (6 Replies)
Discussion started by: juelillo
6 Replies

8. AIX

How to list all threads in a running process

Hello, On Linux, I can use 'ps -efL | grep process_name' to list all threads that belong to a running process. -L has a different meaning on AIX and I could not find an equivalent flag in the man pages. Does anyone know of a way to dump the threads under a running process? Thanks,... (2 Replies)
Discussion started by: makodarear
2 Replies

9. SuSE

Configuring Number Threads

I have this error message from the logs of Zimbra email running on SUSE 11.2 Is the thread maximum of 20 an operating system parameter, or is it part of the application code, or part of the java run time? Part two, how would I increase that number? (3 Replies)
Discussion started by: jgt
3 Replies

10. HP-UX

How to get number of threads for single java process on HP-UX OS?

Hi All, When i was trying to get total number of threads per java process using this command ps -o NLWP PID, I'm not getting any output. Could someone help me in this issue. Thanks, GMar (1 Reply)
Discussion started by: mgangumolu
1 Replies
DIRECTORY(3)						     Library Functions Manual						      DIRECTORY(3)

NAME
opendir, readdir, telldir, seekdir, rewinddir, closedir - directory operations SYNOPSIS
#include <sys/types.h> #include <sys/dir.h> DIR *opendir(filename) char *filename; struct direct *readdir(dirp) DIR *dirp; long telldir(dirp) DIR *dirp; seekdir(dirp, loc) DIR *dirp; long loc; rewinddir(dirp) DIR *dirp; closedir(dirp) DIR *dirp; DESCRIPTION
Opendir opens the directory named by filename and associates a directory stream with it. Opendir returns a pointer to be used to identify the directory stream in subsequent operations. The pointer NULL is returned if filename cannot be accessed, or if it cannot malloc(3) enough memory to hold the whole thing. Readdir returns a pointer to the next directory entry. It returns NULL upon reaching the end of the directory or detecting an invalid seekdir operation. Telldir returns the current location associated with the named directory stream. Seekdir sets the position of the next readdir operation on the directory stream. The new position reverts to the one associated with the directory stream when the telldir operation was performed. Values returned by telldir are good only for the lifetime of the DIR pointer from which they are derived. If the directory is closed and then reopened, the telldir value may be invalidated due to undetected direc- tory compaction. It is safe to use a previous telldir value immediately after a call to opendir and before any calls to readdir. Rewinddir resets the position of the named directory stream to the beginning of the directory. Closedir closes the named directory stream and frees the structure associated with the DIR pointer. Sample code which searchs a directory for entry ``name'' is: len = strlen(name); dirp = opendir("."); for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) if (dp->d_namlen == len && !strcmp(dp->d_name, name)) { closedir(dirp); return FOUND; } closedir(dirp); return NOT_FOUND; SEE ALSO
open(2), close(2), read(2), lseek(2), dir(5) 4.2 Berkeley Distribution September 24, 1985 DIRECTORY(3)
All times are GMT -4. The time now is 02:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy