Sponsored Content
Full Discussion: Implementing thread in UNIX
Top Forums UNIX for Advanced & Expert Users Implementing thread in UNIX Post 302608519 by admin_xor on Saturday 17th of March 2012 05:55:08 PM
Old 03-17-2012
Please note that while posting, you might want to post your environment like the U*IX variant you are using and also the shell you are using.

Assuming, you are using POSIX compliant shell like Bash or KSH, you can implement threads by forking processes using & operator:

Code:
thread () {
           # your thread code goes here
}

for i in {1..5}; do
          thread &
done

This forks 5 processes (or threads) with the same code.
This User Gave Thanks to admin_xor For This Post:
 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cliched unix help thread

Windows blows. I'm poor so unix is looking like a great alterative (expecially after my former roommate showed me most of the things it can do). Right now I'm looking at Debian or some other Unix kernel that would run nicley on my computer. But the problem we had with installing it while he was... (3 Replies)
Discussion started by: beardsman
3 Replies

2. Forum Support Area for Unregistered Users & Account Problems

How to post a new thread (Regarding Unix related doubts) in Unix Forums

How to post a new thread (Regarding Unix related doubts) in Unix Forums. I registered my id but I am unable to post my Questions to Forum. Thanks & Regards, indusri (1 Reply)
Discussion started by: indusri
1 Replies

3. UNIX Benchmarks

unix benchmark thread?

Type: UltraSPARC IIIi 1,593 Mhz x2 Ram: 16G Disk: 2*70G fw scsi drives Load: db application kernel: Sunos5.10 pgms: compiled Sun cc -O2 ============================================================== BYTE UNIX Benchmarks (Version 3.11) System -- SunOS sun.spmbox.com 5.10... (2 Replies)
Discussion started by: mr_manny
2 Replies

4. Shell Programming and Scripting

Measure thread execution (in C, unix)

Hi, I have a simulation program which creates two threads and I would like to know if I can measure the time of each individual thread. Threads communicate (I use pthread to manage them) and I want to measure communication time. I found a solution with clock_gettime and CLOCK_THREAD_CPUTIME_ID... (32 Replies)
Discussion started by: Tinkh
32 Replies

5. Shell Programming and Scripting

Read from a file in unix(Continue from previous thread)

Hi This is continuation of previos thread status=running username=abc password=123456 server=linux The script was made which is used to capture the data from file ./scr test status It will give result running I have a case like status = running username=abc password=123456... (14 Replies)
Discussion started by: parthmittal2007
14 Replies

6. Shell Programming and Scripting

What's UNIX Expert's suggestion for this thread ?

Assume that 100 file's of type .txt are saved in directory in which, 40 .txt files having ID 225 in column x 10 .txt files having ID 220 in column x 30 .txt files having ID 115 in column x and remaining 20 .txt file's having UNIQUE ID say 226,227,228,229,230....first I want to read only files... (8 Replies)
Discussion started by: Akshay Hegde
8 Replies

7. Forum Support Area for Unregistered Users & Account Problems

UNIX.com links from Google yield invalid thread error

If one enters a Google search query like site:unix.com mysql php and clicks on the resulting link, one gets the message below: vBulletin Message No Thread specified. If you followed a valid link, please notify the administrator (2 Replies)
Discussion started by: Unregistered
2 Replies
pthread_detach(3T)														pthread_detach(3T)

NAME
pthread_detach() - mark a thread as detached to reclaim its resources when it terminates SYNOPSIS
PARAMETERS
thread Thread whose resources are to be reclaimed immediately when it terminates. DESCRIPTION
is used to detach the thread thread. When thread terminates, its resources will automatically be reclaimed by the system. If thread has already terminated, causes the resources of thread to be reclaimed by the system. does not cause thread to terminate. Once a detached thread has terminated, its resources, including the thread ID, may be reused by the system. The return status of a detached thread is lost when the thread terminates. Calling this function multiple times for the same thread results in undefined behavior. RETURN VALUE
Upon successful completion, returns zero. Otherwise, an error number is returned to indicate the error (the variable is not set). ERRORS
If any of the following occur, the function returns the corresponding error number: [EINVAL] thread does not refer to a joinable thread. [ESRCH] No thread could be found corresponding to thread. AUTHOR
was derived from the IEEE POSIX P1003.1c standard. SEE ALSO
pthread_create(3T), pthread_join(3T), wait(2). STANDARDS CONFORMANCE
Pthread Library pthread_detach(3T)
All times are GMT -4. The time now is 01:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy