Hi,
The open group specification says that write() is atomic as long
as the number of bytes is not larger than PIPE_BUF. In the following
program, sometimes only one process successfully writes to the file.
I thought that fprintf also uses write() underneath, so the file
should contains strings from both processes. Any insight?
#include <stdio.h>
#include <limits.h>
#include <assert.h>
int main() {
int i;
FILE *f;
printf("bufsiz=%d pipe_buf=%d\n", BUFSIZ, PIPE_BUF);
f = fopen( "test.txt" , "w" );
/* f = stdout; */
fprintf( f, "Parent is process %d\n", getpid() );
assert(fork() >= 0);
for (i=1; i<4; i++)
fprintf( f, " %8d: %d\n", getpid(), i );
fclose( f );
return 0;
}
Here are some results, the first correctly contains strings from
both processes, but the second only contains strings from one
process:
cincai@verdimar:/tmp> ./a.out; cat haha.txt
bufsiz=8192 pipe_buf=4096
Parent is process 25831
25832: 1
25832: 2
25832: 3
bufsiz=8192 pipe_buf=4096
Parent is process 25831
25831: 1
25831: 2
25831: 3
cincai@verdimar:/tmp> ./a.out ;cat haha.txt
bufsiz=8192 pipe_buf=4096
Parent is process 25836
25837: 1
25837: 2
25837: 3
--
Bis zu 70% Ihrer Onlinekosten sparen: GMX SmartSurfer!
Kostenlos downloaden: http://www.gmx.net/de/go/smartsurfer
Dear friends,
I am writing a program for uploading a file onto my webserver with JSP. I use JSP, Tomcat, Apache2, MySQL.
I use this program : http://jakarta.apache.org/commons/fileupload/ . I choose the version 1.1.
But it does not run properly as I expect (HTTP Status 500).
Please tell me where the mistake.
Thank you very much in advance.
-----
// This is my 'ps.jsp' :
<body>
<table cellpadding="0" cellspacing="0" border="1" align="center">
<form enctype="multipart/form-data" action="http://localhost:8080/penguin-teknologi/penguin-teaches/cgiupload.jsp" method="post" name="myform">
<tr><td align="justify"><font style="Comic Sans MS, Arial">Silahkan pilih file yg akan diupload.</font></td></tr>
<tr><td><input type="text" name="nama"></td></tr>
<tr><td align="justify"><input type="file" name="soalnya"></td></tr>
<tr><td align="justify"><input type="submit" value="Kirim"><input type="reset"></td></tr>
</form>
</table>
</body>
-----
// This is my 'cgiupload.jsp'
<%@ page import="org.apache.commons.fileupload.*, java.util.List, java.io.File, java.util.Iterator" %>
<%
boolean isMultipart = FileUpload.isMultipartContent(request);
if(!isMultipart){
request.setAttribute("msg", "Request was not multipart!");
request.getRequestDispatcher("msg.jsp").forward(request, response);
return;
}
DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(request);
Iterator itr = items.iterator();
while(itr.hasNext()){
FileItem item = (FileItem) itr.next();
if(item.isFormField()) {
String fieldName = item.getFieldName();
if(fieldName.equals("name"))
request.setAttribute("msg", "Thank You: " + item.getString());
} else {
File fullFile = new File(item.getName());
File savedFile = new File(getServletContext().getRealPath("/"), fullFile.getName());
item.write(savedFile);
}
}
request.getRequestDispatcher("msg.jsp").forward(request, response);
%>
-----
// This is my 'msg.jsp' :
<body>
<%
String msg = (String)request.getAttribute("msg");
if(msg != null)
out.println("<font size=+1>Buseettt<br>" + msg + "</font><br/>");
%>
Click <a href="../../../../../Apache%20Group/Apache2/htdocs/p-tek/penguin-teaches/ps.jsp">here</a> to go to the upload page.
</body>
-----
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: org/apache/commons/io/output/DeferredFileOutputStream
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
javax.servlet.ServletException: org/apache/commons/io/output/DeferredFileOutputStream
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.penguin_002dteaches.cgiupload_jsp._jspService(cgiupload_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
org.apache.commons.fileupload.DefaultFileItemFactory.createItem(DefaultFileItemFactory.java:102)
org.apache.commons.fileupload.FileUploadBase.createItem(FileUploadBase.java:500)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:367)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:268)
org.apache.jsp.penguin_002dteaches.cgiupload_jsp._jspService(cgiupload_jsp.java:57)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.16 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.16
Hi,
I'm trying to compile a program on x86_64, but when it gets to the final
linking stage, I get the error
relocation R_X86_64_PC32 against `prefetch_C_withmask' can not be used
when making a shared object; recompile with -fPIC
I've tried putting -fPIC every place I can find where it is legal to do
so, but I still always get the same error
Does anyone know what this relocation is, and why I keep getting the
error?
Hi,
is there a standard rule on widening conversion between signed
and unsigned type? I found a reference from this URL:
http://developers.sun.com/prodtech/cc/articles/ILP32toLP64Issues.html
which also seems to be implemented by gcc. Can anybody confirm
on this? TIA.
int main() {
unsigned int ui = 0xcabcdef2;
long long ll_ui = ui;
unsigned long long ull_ui = ui;
int i = 0xcabcdef2;
long long ll_i = i;
unsigned long long ull_i = i;
printf("ui=%x ll_ui=%llx ull_ui=%llx\n", ui, ll_ui, ull_ui);
printf("i=%x ll_i=%llx ull_i=%llx%\n", i, ll_i, ull_i);
return 0;
}
Execution result:
ui=cabcdef2 ll_ui=cabcdef2 ull_ui=cabcdef2
i=cabcdef2 ll_i=ffffffffcabcdef2 ull_i=ffffffffcabcdef2
--
Regards,
Verdi
--
Echte DSL-Flatrate dauerhaft f�r 0,- Euro*!
"Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl
> --- Ursprüngliche Nachricht ---
> Von: Ken Jennings <ken_jennings(a)bellsouth.net>
> An: "Verdi March" <cincaipatron(a)gmx.net>
> Betreff: Re: [suse-programming-e] The meaning of atomic in write()
> Datum: Tue, 28 Mar 2006 01:00:49 -0500
> Are you sure haha.txt is the file? The code says it opens test.txt
for
> write.
Sorry typo :), should be test.txt. And I rerun it to confirm the
result is as what I've described.
cincai@verdimar:/tmp> ./a.out; cat test.txt
bufsiz=8192 pipe_buf=4096
Parent is process 29077
29077: 1
29077: 2
29077: 3
cincai@verdimar:/tmp> ./a.out; cat test.txt
bufsiz=8192 pipe_buf=4096
Parent is process 29082
29083: 1
29083: 2
29083: 3
Parent is process 29082
29082: 1
29082: 2
29082: 3
--
Regards,
Verdi
--
"Feel free" mit GMX FreeMail!
Monat für Monat 10 FreeSMS inklusive! http://www.gmx.net
I am running SuSE Linux 10.0 which ships with g++ 4.0.2. However, several of
my programs that were working fine under 3.3.5 will not build under 4.0.2. I
consistently get the following errors:
/usr/include/c++/4.0.2/bits/sstream.tcc:112: error: expected unqualified-id
before '(' token
/usr/include/c++/4.0.2/bits/sstream.tcc:114: error: expected unqualified-id
before '(' token
I would like to downgrade my c++ environment to 3.3.x so I can get back to
where I was (working!). What is the most direct/quickest way to get back
where I was? I noticed that 3.3.x is not on the DVD.
Thanks,
Darrell
Greeting
I've got a kernel module that contains something like this:
while(loop) {
take semaphore A
do some I/O on the PCI bus
give semaphore A
}
This loop is launched by a worker thread
Meanwhile, I've got write() mapped into a module function like this:
my_write() {
take semaphore A
write to the PCI pus
give semaphore A
}
The problem is that my_write() can never get the A semaphore. The loop
is too tight perhaps. Or maybe the system call has a lower priority than
the kernel's worker thread. Other than using flags, is there some easy
way to fix this?
TIA&Cheers
I'm starting a new job in a few days. One of my first tasks will be to
modify th 2-D GUI of a package. In the following I'll have to evolve the
2-D GUI into a 3-D GUI allowing for 3-D rotations of 3-D structures.
I've never used Tcl/Tk in my life so I would greatly appreciate some
advice about an easy tutorial with plenty of worked out examples ... if
available.
I'm running SuSE 9.3 on my laptop and have zero time to replace it with
SuSe 10
for the time being.
Thank you in advance for your help.
Maura
Anything in particular I need to be aware of in an application that is
multi-threaded, but also does regular forks?
I've studied some of the stuff talked about in the man-page for
pthread_atfork(), and none of it applies to my situation. I don't
think I have a specific problem with fork(), I'm just trying to
eliminate that option.
/Per Jessen, Zürich
On the Xerces C++ mailing list I was told the following:
"XMLCh is specifically UTF-16. But wchar_t is not UTF-16 everywhere. It's
non-portable, and Solaris and Linux each use different (including from each
other) encodings for wchar_t.
There's actually a gcc option to make wchar_t the same as on Windows, it was
created for Wine. I'm not brave enough to rely on it."
The Qt documentation tells me:
<quote url=http://doc.trolltech.com/4.1/qstring.html>
The QString class provides a Unicode character string.
QString stores a string of 16-bit QChars, where each QChar stores one Unicode
4.0 character. Unicode is an international standard that supports most of the
writing systems in use today. It is a superset of ASCII and Latin-1 (ISO
8859-1), and all the ASCII/Latin-1 characters are available at the same code
positions.
Behind the scenes, QString uses implicit sharing (copy-on-write) to reduce
memory usage and to avoid the needless copying of data. This also helps
reduce the inherent overhead of storing 16-bit characters instead of 8-bit
characters.
</quote>
So, can I do this with confidence?
const XMLCh* QtoX(const QString& s) {
return reinterpret_cast<const XMLCh*>(s.constData());
}
Q:Is this thing loaded?
A:I don't know; pull the trigger and find out.
Q:Where should I point it?
Steven