warning: int format,pid_t arg (arg 2)


 
Thread Tools Search this Thread
Top Forums Programming warning: int format,pid_t arg (arg 2)
# 1  
Old 06-29-2009
Question warning: int format,pid_t arg (arg 2)

I try following code under Solaris10,like follows:

Code:
int glob = 6;
int main(void)
{
  int var;
  pid_t pid;
  var = 88;
  printf("before vfork\n");
  if ((pid = vfork()) < 0) {
    err_sys("vfork error");
  } else if (pid == 0) { 
      glob++;
     var++;
     _exit(0);
  }
  printf("pid = %d, glob = %d, var = %d\n", getpid(), glob, var);
  exit(0);
}

When I compile it,it raise following warning
$gcc -Wall abc.c error.obj
abc.c: In function 'main':
abc.c:16: warning: int format,pid_t arg (arg 2)
ld: warning: symbol 'glob' has differing types:
(file /var/tmp//ccIMPxLe.o type=OBJT; file/usr/lib/libc.so type=FUNC);
/var/tmp//ccIMPxLe.o definition take
ld: warning: symbol 'glob' has differing types:
(file /var/tmp//ccIMPxLe.o type=OBJT; file/usr/lib/libc.so type=FUNC);

Why raise above warning? How to correct it?

Thanks in advance
# 2  
Old 06-29-2009
Because pid's differ widely across systems, the only thing you can really do (aside from changing printf() and adding a new class of object) is to cast intelligently:

Code:
printf ("pid = %lu\n", (unsigned long) getpid());

It's a reasonable assumption that a PID is an unsigned integer type.

HTH. YMMV.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute arg with ssh

Hello, I am trying to execute remote script with ssh : ssh -o ConnectTimeout=10 -o PasswordAuthentication=no -o NumberOfPasswordPrompts=0 -o StrictHostKeyChecking=no root@host '/arbo/script -t' My script is well executed, but my option '-t' is never loaded, how can you explain that ? (2 Replies)
Discussion started by: cterra
2 Replies

2. Shell Programming and Scripting

Bash script too many arg's

I have a simple bash script on RHEL that works fine when there is one file but when it finds multiple files of same condition I get too many args error. for i in * do if ;then echo "no files to move" exit 0 fi if ; then ... (10 Replies)
Discussion started by: jcalisi
10 Replies

3. Shell Programming and Scripting

Copy from/to file, if arg 'ok'

Hello, I've just started with shell scripting, and I need som assistance! Basicly what I want to do is copy names from one file to another, when running the scrip the user should be asked about the status of these names. Let me demonstrate: file: Name: John, Gender: male Name: Jane,... (6 Replies)
Discussion started by: klskl
6 Replies

4. Programming

warning: passing arg 1 of `inet_addr' makes pointer from integer without a cast

I use solaris10,following is tcp client code: #include "cliserv.h" int main(int argc,char argv){ struct sockaddr_in serv; char request,reply; int sockfd,n; if(argc!=2) err_quit("usage: tcpclient <IP address of server>"); if((sockfd=socket(PF_INET,SOCK_STREAM,0))<0) ... (1 Reply)
Discussion started by: konvalo
1 Replies

5. UNIX for Dummies Questions & Answers

Space in a arg

Hi, When i am running a script it considers the below as mulitple arguments. There is any command which can ignore the spaces. I tried by using sed like below to ignore but it doesnt work. sed 's/ /\\ /g'100% Haddock Fillets Battered 500G-small.gif ~vino (3 Replies)
Discussion started by: vino_hymi
3 Replies

6. Shell Programming and Scripting

arg list too long

Hi, Help. I have a file that contains a list of users in a file. I want to cat the content of the file and feed it into sed to a preformated report. The error I got is "ksh: /usr/bin/sed: arg list too long" My method below. A=`cat FILE1.txt` B=`echo $A` sed "s#USERLIST#$B#" FILE2 >... (2 Replies)
Discussion started by: Zenwork
2 Replies

7. UNIX for Dummies Questions & Answers

ls -t arg list too long

echo dirname/filename* | xargs ls -t As a substitute doesn't give the results desired when I exceed the buffer size. I still want the files listed in chronological order, unfortunately xargs releases the names piecemeal...does anyone have any ideas? :( (4 Replies)
Discussion started by: CSU_Ram
4 Replies

8. UNIX for Advanced & Expert Users

arg list too long

Does anyone have a solution for arg list too long error. I have got this from the web but I fail to make any sense out of it Thanks enc (8 Replies)
Discussion started by: encrypted
8 Replies

9. UNIX for Dummies Questions & Answers

arg list too long

I do ls -l ABC*, I get arg list too long message. This will not happen if ABC* has small no of files I believe 4000 files is limit. Any way of avoiding this. I even tried like this for i in `ls -l ABC*` do echo $i done Same problem. Any solution would be great. I am on HP-UX... (5 Replies)
Discussion started by: vingupta
5 Replies
Login or Register to Ask a Question