Sponsored Content
Top Forums UNIX for Advanced & Expert Users Process based code vs. Thread based code Post 302234055 by rkalyankumar on Tuesday 9th of September 2008 03:22:16 AM
Old 09-09-2008
MySQL Process based code vs. Thread based code

I am just wondering on which is the best way to write programs on UNIX. Which one is better from below:

a) Spawning threads per client connection/request?
b) fork-exec new processes per client connection/request?

Assume that I am doing some database system on linux which is supposed to run on unix systems as well.

The basic differences as I know are:

Using processes - have it's own address space, communicate using SysV/POSIX shared memory + semaphores etc & context switching is costly. Also implementing processes instead of threads is that process are more stable and reliable than threads. Just because if one thread malfunctions, the entire process would break.

On the other side, using thread the context switching is less cheaper compared to that of process context switches. No need for shared memory as the memory is shared and accessible by all threads with in the process & hence can avoid costly IPC mechanism's like SysV/POSIX shared memory and semaphores. Instead use simple mutexes and condition variables.

Being said all the above, I am still not in a position to decide up on which way to go i.e. use threads or use processes?

Please help.

Regards
Kalyan
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

server based Including additional code > Lycos way

For a project we need to make sure that all php / html files in a certain directory on the webserver are showing advertisments of us. For example, when you get a website from Lycos, you'll have an advertisement in the right corner. How to? As far as I can see, Lycos includes a javascript... (1 Reply)
Discussion started by: valentijnb
1 Replies

2. Shell Programming and Scripting

Need your HELP:: Shell script to detect paragraph in coordinate-based code.

Hi Friends!! I have obtained following output from a tool called pdftoxml: <xml> <text top="423" left="521" width="333" height="20" font="3">Although the the number of fuzzy rules of a system is </text> <text top="441" left="500" width="355" height="20" font="3">directly dependant on these... (2 Replies)
Discussion started by: parshant_bvcoe
2 Replies

3. Shell Programming and Scripting

restart process based on file

Hi all. I do have a script "startApp.sh" (app result is a file /opt/extract/appextract.txt) I have no problems with stopping app var1=`ps -ef | grep -v grep | grep MyApp | awk '{print $2}'` kill -9 $var1 What I want to achieve is: I start app, app is doing some extraction, after... (11 Replies)
Discussion started by: e-l-diablo
11 Replies

4. Shell Programming and Scripting

How to fetch rows based on line numbers or based on the beginning of a word?

I have a file which will have rows like shown below, ST*820*316054716 RMR*IV*11333331009*PO*40.31 REF*IV*22234441009*xsss471-2762 DTM*003*091016 ENT*000006 RMR*IV*2222234444*PO*239.91 REF*IV*1234445451009*LJhjlkhkj471-2762 </SPAN> DTM*003* 091016 RMR*IV*2223344441009*PO*40.31... (18 Replies)
Discussion started by: Muthuraj K
18 Replies

5. Shell Programming and Scripting

Running a process based on time

Hello All, My script is nearly complete, there is just one last piece that needs to be added in. I need to check for the time, and if it is lets say for example. Sunday at 5:00AM, my script cannot run. I would assume it would be something like this, parden the terrible pseudocode ... (7 Replies)
Discussion started by: jeffs42885
7 Replies

6. Shell Programming and Scripting

Script for running root based C++ code

Hi all, I have to run C++ file using root programming, using following commands: $root -l root .L TwoTrees.C++ root TwoTrees t root t.Loop() root.q I wonder if I can write script to do the following. Thanks Pooja (12 Replies)
Discussion started by: nrjrasaxena
12 Replies

7. Shell Programming and Scripting

Appending code in a directory recursively based on a certain criteria

i am stuck with this strange problem..... maybe you can help. i have one master_file which has two column username and id_number separated by , somewhat like : cat master_file : sample,1234567 javacode,4567891 companion,23456719 adamsandler,1237681 tomcruise,56328910 bradpitt,901236781... (9 Replies)
Discussion started by: mukulverma2408
9 Replies

8. UNIX for Dummies Questions & Answers

Condition based on Timestamp (Date/Time based) from logfile (Epoch seconds)

Below is the sample logfile: Userids Date Time acb Checkout time: 2013-11-20 17:00 axy Checkout time: 2013-11-22 12:00 der Checkout time: 2013-11-17 17:00 xyz Checkout time: 2013-11-19 16:00 ddd Checkout time: 2013-11-21 16:00 aaa Checkout... (9 Replies)
Discussion started by: asjaiswal
9 Replies

9. Shell Programming and Scripting

Code snippet to cut XML files based on record length

I want to do FTP an Huge XML file to mainframe server using AIX server Since my file size is huge, i want to split the XML file based on a delimiter , the record delimiter should be set after every 27000 bytes of data and then do the ftp This is done becos the data send to the mainframe must... (1 Reply)
Discussion started by: vishwanath001
1 Replies

10. Programming

C++ separate code based on the few changes

Hi, I am working in Visual studio 2008 in which i have written the code in c++,qml,qt.Its a simulator application. I would like to create a simulator with certain changes. In order to do that i have modified the code with few changes based on the preprocessor condition. #define... (4 Replies)
Discussion started by: SA_Palani
4 Replies
SEM_OVERVIEW(7) 					     Linux Programmer's Manual						   SEM_OVERVIEW(7)

NAME
sem_overview - Overview of POSIX semaphores DESCRIPTION
POSIX semaphores allow processes and threads to synchronize their actions. A semaphore is an integer whose value is never allowed to fall below zero. Two operations can be performed on semaphores: increment the semaphore value by one (sem_post(3)); and decrement the semaphore value by one (sem_wait(3)). If the value of a semaphore is currently zero, then a sem_wait(3) operation will block until the value becomes greater than zero. POSIX semaphores come in two forms: named semaphores and unnamed semaphores. Named semaphores A named semaphore is identified by a name of the form /somename; that is, a null-terminated string of up to NAME_MAX-4 (i.e., 251) characters consisting of an initial slash, followed by one or more characters, none of which are slashes. Two processes can operate on the same named semaphore by passing the same name to sem_open(3). The sem_open(3) function creates a new named semaphore or opens an existing named semaphore. After the semaphore has been opened, it can be operated on using sem_post(3) and sem_wait(3). When a process has finished using the semaphore, it can use sem_close(3) to close the semaphore. When all processes have finished using the semaphore, it can be removed from the system using sem_unlink(3). Unnamed semaphores (memory-based semaphores) An unnamed semaphore does not have a name. Instead the semaphore is placed in a region of memory that is shared between multiple threads (a thread-shared semaphore) or processes (a process-shared semaphore). A thread-shared semaphore is placed in an area of memory shared between by the threads of a process, for example, a global variable. A process-shared semaphore must be placed in a shared memory region (e.g., a System V shared memory segment created using shmget(2), or a POSIX shared memory object built created using shm_open(3)). Before being used, an unnamed semaphore must be initialized using sem_init(3). It can then be operated on using sem_post(3) and sem_wait(3). When the semaphore is no longer required, and before the memory in which it is located is deallocated, the semaphore should be destroyed using sem_destroy(3). The remainder of this section describes some specific details of the Linux implementation of POSIX semaphores. Versions Prior to kernel 2.6, Linux only supported unnamed, thread-shared semaphores. On a system with Linux 2.6 and a glibc that provides the NPTL threading implementation, a complete implementation of POSIX semaphores is provided. Persistence POSIX named semaphores have kernel persistence: if not removed by sem_unlink(3), a semaphore will exist until the system is shut down. Linking Programs using the POSIX semaphores API must be compiled with cc -lrt to link against the real-time library, librt. Accessing named semaphores via the file system On Linux, named semaphores are created in a virtual file system, normally mounted under /dev/shm, with names of the form sem.somename. (This is the reason that semaphore names are limited to NAME_MAX-4 rather than NAME_MAX characters.) Since Linux 2.6.19, ACLs can be placed on files under this directory, to control object permissions on a per-user and per-group basis. CONFORMING TO
POSIX.1-2001. NOTES
System V semaphores (semget(2), semop(2), etc.) are an older semaphore API. POSIX semaphores provide a simpler, and better designed inter- face than System V semaphores; on the other hand POSIX semaphores are less widely available (especially on older systems) than System V semaphores. EXAMPLE
An example of the use of various POSIX semaphore functions is shown in sem_wait(3). SEE ALSO
sem_close(3), sem_destroy(3), sem_getvalue(3), sem_init(3), sem_open(3), sem_post(3), sem_unlink(3), sem_wait(3), pthreads(7) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2010-05-22 SEM_OVERVIEW(7)
All times are GMT -4. The time now is 06:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy